why can't insert data into the database table?
Posted: Thu Jun 24, 2010 1:11 am
the html file
the add.php file
Code: Select all
<form method="post" action="add.php">
<input type="hidden" name="id" value="NULL" />
<table><tr height="20"><td colspan="2"><font size="+0" face="verdana">Below is a sample form for our php</td></tr><tr height="50"><td></td></tr><tr><td align="left"><font size="+0" face="verdana"><b>Your name<br />Your Email Address</b></td><td><input type="text" name="name"><br /><input type="text" name="email" /></td> </tr><tr><td colspan="2"><center><select name="opinion"><option value="is greate">I like your site</option><option value="is OK">you site is ok</option><option value="is horrible">your site is horrible</option></select><input type="submit" value="tell us"!/></td></tr></table></form>
Code: Select all
$DBhost ="localhost"; //mysql-server
$DBuser = "root"; //mysqluser
$DBpass = "123";
$DBName = "learnphp";
$table = "information";
mysql_connect($DBhost,$DBuser,$DBpass) or die("error");
mysql_select_db("$DBName") or die("error");
$sqlquery = "INSERT INTO $table (id,name,email,opinion)VALUES ('$_POST[id]','$_POST[name]','$_POST[email]','$_POST[opinion]')";
$results=mysql_query($sqlquery);mysql_close();
echo "<html><titile>PHP and mysql</title><body><p><center>you just enter this information into the database<p><blockquote>";
print "Name:$_POST[name]<p>E-mail:$_POST[email]<p>opinion:$_POST[opinion]</blockquote></center>";