Can't insert into a MySQL database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eaglewingmd
Forum Newbie
Posts: 1
Joined: Sat Apr 10, 2010 5:02 pm

Can't insert into a MySQL database

Post by eaglewingmd »

I have created a database on Hostmonster using the MySQL wizard and PHPadmin. The database is fine. I can add to it using PHPadmin. But this code does not add to the database when processing my form. The rest of the script works, sends out email, moves to a new page but this.... I even had PHPadmin create code, used it and it would not add. Yet I am not getting anymore errors. I would appreciate your help.

/* put it in the database

$username="steve";
$password="password";
$database="contacts";

mysql_connect("localhost", $username, $password ) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());

mysql_query("INSERT INTO 'data' VALUES('$first','$last','$email','$likeit')");

mysql_close();

/*mail($sendtome,$mesubject,$datamessage);*/
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Can't insert into a MySQL database

Post by requinix »

In MySQL, apostrophes and quotation marks are only for strings. If you want quotes around names, like tables or fields, you need backticks.

It's the button by the 1 key.
Post Reply