olivierp -
Joined: 23 Apr 2004 Posts: 54 Location: Montreal, Qc
|
Posted: Mon May 02, 2005 8:08 pm Post subject: PHP form insert into MySQL |
|
|
Hi all, Thanks in adcance for your help !
PHP 5 [prepackaged by Aprelium]
MySQL 4.1.11 [with Administrator]
Abyss WebServer X1
I'm trying to use a form to insert a new row in MySQL DB.
When testing the script, I do not get any errors and the proper echo is displayed but no rows were added to the table.
I tested the PHP installation with a simple php script which works fine :
Quote: | <?php
echo "Hello Dave!";
?> |
I created a DB with cmd called mailing and a table called girls
The table has 2 columns in this order :
Quote: | name [also a primary key, not-null, no auto inc, and no default value]
email [not-null, no auto inc, and no default value] |
Here is the php script :
Quote: | <?
mysql_connect("localhost","root","xxxxxxxx");
mysql_select_db("mailing");
$name = $_POST['name'];
$email = $_POST['email'];
$result = mysql_query("INSERT INTO girls (name,email) VALUES ('".$name."', '".$email."')");
if($result == 1){
echo "Query Finished";
}
?> |
Here is the form :
Quote: | <form method="post" action="mailing.php">
<TABLE>
<TR>
<TD>Name:</TD>
<TD><INPUT TYPE='TEXT' NAME='name' size=60></TD>
</TR>
<TR>
<TD>Email:</TD>
<TD><INPUT TYPE='TEXT' NAME='email' size=60></TD>
</TR><br>
<TR>
<TD></TD><br>
<TD><INPUT TYPE="submit" name="submit" value="submit"></TD>
</TR>
</TABLE>
</form> |
|
|