Jump to content

Archived

This topic is now archived and is closed to further replies.

11Tami

Man I really need help! insert into sql table big problem.

Recommended Posts

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! Tami

<?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>

Share this post


Link to post
Share on other sites
from just looking at the php code. try replaceing it with this. but i am not sure because you didn't give any errors. but just try this:

[code]
<?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)
?>
[/code]

Share this post


Link to post
Share on other sites
[code]
$con = mysql_connect("","dropdown","");
[/code]

mysql_connect() arguments are
hostname
username
password

Share this post


Link to post
Share on other sites
If the field name is firstname then it should be
$sql="INSERT INTO buttons (firstname ) VALUES ($_POST[firstname])";

Des.

Share this post


Link to post
Share on other sites
Thank you, thank you, thank you, lord project fear! Weird thing is It worked once with what I had but then it would never work again. That made no sense to me. Project fear yours works just fine! Thank you very much!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.