-1

I am trying to insert some fields into a db by running a .php file, with no success.

It may be probably bad syntax, but since i am amateur in PHP, not really sure.

Could you guys help me correct my wrongs with this?

mysql_query("DELETE FROM deleteme"); seems to be working fine,

but mysql_query("INSERT INTO 'addme' is not!

<?php  
$con = mysql_connect("localhost", "localdb", "pass") or  
    die("Could not connect: " . mysql_error());  
mysql_select_db("localdb");  

mysql_query("DELETE FROM deleteme");
mysql_query("INSERT INTO 'addme' ('id', 'roleid', 'username', 'password', 'authmodule', 'authdata', 'firstname', 'lastname', 'email', 'signature', 'notes', 'template', 'language', 'loginattempts', 'supportdepts', 'ticketnotifications', 'homewidgets') VALUES
(3, 1, 'admin', 'af3c9', '', '', 'Admin', 'Administration', 'admin@email.com', '', '', 'typical', 'english', 0, '1,2,4', '', '')");

mysql_close($con);  
?>

Also Tried this, with no luck:

<?php  
$con = mysql_connect("localhost", "localdb", "pass") or  
    die("Could not connect: " . mysql_error());  
mysql_select_db("localdb");  

mysql_query("DELETE FROM deleteme");
mysql_query("INSERT INTO `addme` (`id`, `roleid`, `username`, `password`, `authmodule`, `authdata`, `firstname`, `lastname`, `email`, `signature`, `notes`, `template`, `language`, `loginattempts`, `supportdepts`, `ticketnotifications`, `homewidgets`) VALUES
(3, 1, 'admin', 'af3c9', '', '', 'Admin', 'Administration', 'admin@email.com', '', '', 'typical', 'english', 0, '1,2,4', '', '')");

mysql_close($con);  
?>

2 Answers2

2

Table and column names should be surrounded with backticks, not quotes.

mysql_query("INSERT INTO `addme` (`id`, `roleid`, `username`, `password`, `authmodule`, `authdata`, `firstname`, `lastname`, `email`, `signature`, `notes`, `template`, `language`, `loginattempts`, `supportdepts`, `ticketnotifications`, `homewidgets`) VALUES
(3, 1, 'admin', 'af3c9', '', '', 'Admin', 'Administration', 'admin@email.com', '', '', 'typical', 'english', 0, '1,2,4', '', '')");
Barmar
  • 741,623
  • 53
  • 500
  • 612
2

Use backticks ` intsead of quotes '

INSERT INTO `addme` (`id`,....

Back ticks ` are to be used for table and column identifiers, but are only necessary when the identifier is a MySQL reserved keyword

For more information see when-to-use-single-quotes-double-quotes-and-backticks

And if you want to know where is Backticks is located on keyboard then see here how-do-i-type-the-tick-and-backtick-characters-on-windows

On the side note don't use mysql_* function. WHY?

Community
  • 1
  • 1
Rakesh Shetty
  • 4,548
  • 7
  • 40
  • 79