Jump to content

Problem with SQL insert


lubber123

Recommended Posts

I am pretty new to PHP and am feeling my way around.  I am having trouble doing a simple insert into my DB and am not sure what I am doing wrong.

 

Here is my code:

 

$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
if (!$connection) {
die("Database connection failed: " . mysql_error());
}

$db_select = mysql_select_db(DB_NAME,$connection);
if (!$db_select) {
die("Database selection failed: " . mysql_error());
}


$event_query = "INSERT INTO `test` (`id` ,'personal_info', 'event_creator')
VALUES ( '', $personal_info , $event_creator)";

 

I get the errors that personal_info and event_creator are not set even though they are set further up in the code.

 

Can anyone help?

Link to comment
Share on other sites

You are putting single quotes around your column names. You should use double quotes for table/column names and singles around the inserted data. If your query is already wrapped in double quotes, you'll need a backslash in front of each double quote inside the query.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.