i have written this code which is inserting some values into database , first i have created 2 files one for from.html and the other for form.php, in form.php file i written the php code which inserts values into database and then i called this form.php file in action attribute of html form.
how can i write write this php code in html form and call it in same file , and what should be the action attribute if php code is present in html file.
here is my code
<Head>
<title>Contact form</title>
<style type="text/css">
table{
border:1;
border-collapse:collapse;
font: normal 12px 'Lucida Grande',Verdana,sans-serif;
}
td{
color:#663333;font-family:verdana;
border-bottom: 1px solid #666;
padding-left:10px;
background-color:#F0F8FF;
}
#sub{ text-align:center;}
</style>
</Head>
<body>
<?php
include("connection.php");
//Get data in local variable
$v_username=$_POST['username'];
$v_email=$_POST['email'];
$v_package=$_POST['mydropdown'];
$v_msg=$_POST['msg'];
// check for null values
if ($v_username=="" or $v_msg=="")
echo "All fields must be entered, hit back button and re-enter information";
else{
$query="insert into contact(username,email,package,msg) values('$v_username','$v_email','$v_package','$v_msg')";
mysql_query($query) or die(mysql_error());
echo "Your message has been received";
}
?>
<h2> FeedBack/Contact Form</h2>
<form action="#" method="POST">
<table>
<tr>
<td >Name*</td>
<td ><input type="text" size=40 name="username"></td>
</tr>
<tr>
<td >Email</td>
<td ><input type="text" size=40 name="email"></td>
</tr>
<tr>
<td >Package</td>
<td ><select name="mydropdown">
<option value="Fresh Milk">Fresh Milk</option>
<option value="Old Cheese Cheese">Old Cheese</option>
<option value="Hot Bread">Hot Bread</option>
</select></td>
</tr>
<tr>
<td >Comments/Suggestions*</td>
<td ><textarea name="msg" cols=40 rows=7></textarea> </td>
</tr>
<tr>
<td colspan=2 id="sub"><input type="submit" name="submit" value="submit" ></td>
</tr>
</Table>
</form>
</BODY>
</Html>
This post has been edited by Dormilich: 19 April 2012 - 01:22 AM
Reason for edit:: please use [code] [/code] tags when posting code

New Topic/Question
Reply



MultiQuote





|