Forum Moderators: coopster

Message Too Old, No Replies

Please help! Trying to insert one entry into a table for mysql.

         

Simone100

7:17 am on Oct 1, 2006 (gmt 0)

10+ Year Member



I've been working on this for several days. I don't know why its so hard! Trying to add a simple entry to a my sql table. server version
4.0.27 database name "dropdown" table name "buttons" column name "one" I sure hope someone can help, thanks!

<?php
$con = mysql_connect("","dropdown","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}mysql_select_db("dropdown", $con);

$firstname = $_POST['firstname'] ;
$sql="INSERT INTO buttons (one)
VALUES
('$_POST[firstname]')";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";mysql_close($con)
?>

input field name is "firstname"
<form action="http://www.website.com/dropdown.php" method="post">
first name<input type="text" name="firstname" />
<input type="submit"/>
</form>

barns101

11:08 am on Oct 1, 2006 (gmt 0)

10+ Year Member



What error message do you get? I noticed that the very first line doesn't include your database host or password:

$con = mysql_connect("","dropdown","");

Simone100

4:53 pm on Oct 1, 2006 (gmt 0)

10+ Year Member



Thats just so I don't include those here.

This is the error message.

Error, you are using incorrect syntax for ' ) VALUES ('','')'

Simone100

5:03 pm on Oct 1, 2006 (gmt 0)

10+ Year Member



I think someone helped me, if not, I'll let you know. Thanks.

henry0

5:06 pm on Oct 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Since $firstname has a value

('$_POST[firstname]')";

Instead try
('$firstname')";

lmo4103

5:21 pm on Oct 1, 2006 (gmt 0)

10+ Year Member



change this:
('$_POST[firstname]')";

to this:
('" . $_POST['firstname'] . "')";