Jump to content


Photo

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


  • Please log in to reply
5 replies to this topic

#1 11Tami

11Tami
  • Members
  • PipPipPip
  • Advanced Member
  • 329 posts

Posted 01 October 2006 - 07:15 AM

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.c...m/dropdown.php" method="post">
first name<input type="text" name="firstname" />
<input type="submit"/>
</form>


#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 01 October 2006 - 07:33 AM

Hi Tami,

Are you getting any errors displayed? Can you give a description of what's "wrong?"
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 JasonLewis

JasonLewis
  • Members
  • PipPipPip
  • Advanced Member
  • 3,351 posts
  • LocationVictoria, Australia

Posted 01 October 2006 - 08:51 AM

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:

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

Good luck with your coding.
Jason / ProjectFear / Jaysonic

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 01 October 2006 - 11:01 AM

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

mysql_connect() arguments are
hostname
username
password
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 otuatail

otuatail
  • Members
  • PipPipPip
  • Advanced Member
  • 960 posts

Posted 01 October 2006 - 12:56 PM

If the field name is firstname then it should be
$sql="INSERT INTO buttons (firstname ) VALUES ($_POST[firstname])";

Des.

#6 11Tami

11Tami
  • Members
  • PipPipPip
  • Advanced Member
  • 329 posts

Posted 01 October 2006 - 05:06 PM

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!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users