Jump to content

mysql insert into table values


lostlee
 Share

Recommended Posts

What gets put in for the values is my problem.  I have tried every way I can think of but I get errors in the code or I don't get the row inserted.

 

Can anyone give me a code sample using $ variables, preferably a multi-line list?  I would have to fix up my code to show you what I am trying as it is in between tries now.

 

I have to be doing something wrong and may have to put together a simple test script but a working example would be better.  Everything I look at on the web shows "xxxxx xxxx" examples not $variables.

 

Thanks in advance.

Link to comment
Share on other sites

I have looked at this very site especially since it is the mysql manual, and many others similar to this one.  There is no example in any that I have seen that show an example of $variables as the values.  All that I need is for someone to give me an example with $variable VALUES.  I assure you and others that I have likely looked at many different sites looking for an example and have found none to date.

Link to comment
Share on other sites

mysql_query("INSERT INTO table (col1, col2, col3) VALUES ('" . $col1 . "', '" . $col2 . "', '" . $col3 . "')");

 

why do people still concatenate variables in queries wrapped in double quotes? I'm still trying to figure this out. It's not needed, more work and can lead to more error(s).

Link to comment
Share on other sites

mysql_query("INSERT INTO table (col1, col2, col3) VALUES ('" . $col1 . "', '" . $col2 . "', '" . $col3 . "')");

 

why do people still concatenate variables in queries wrapped in double quotes? I'm still trying to figure this out. It's not needed, more work and can lead to more error(s).

 

Because there are times when you still need to concatenate things even when using double quotes. Or at the very least use {}. It is just habit and personal preference. I don't see how it could lead to more errors.

Link to comment
Share on other sites

mysql_query("INSERT INTO table (col1, col2, col3) VALUES ('" . $col1 . "', '" . $col2 . "', '" . $col3 . "')");

 

why do people still concatenate variables in queries wrapped in double quotes? I'm still trying to figure this out. It's not needed, more work and can lead to more error(s).

 

Because there are times when you still need to concatenate things even when using double quotes. Or at the very least use {}. It is just habit and personal preference. I don't see how it could lead to more errors.

 

okay, wasn't attacking you or anything, was honestly just curious. It can lead to more errors if the coder does not know how to properly concatenate.

Link to comment
Share on other sites

mysql_query("INSERT INTO table (col1, col2, col3) VALUES ('" . $col1 . "', '" . $col2 . "', '" . $col3 . "')");

 

why do people still concatenate variables in queries wrapped in double quotes? I'm still trying to figure this out. It's not needed, more work and can lead to more error(s).

 

Because there are times when you still need to concatenate things even when using double quotes. Or at the very least use {}. It is just habit and personal preference. I don't see how it could lead to more errors.

 

It can lead to more errors if the coder does not know how to properly concatenate.

 

Haha, well that could be said about anything. "It could lead to errors if the coder doesn't know how to use a semi-colon".

Link to comment
Share on other sites

This thread is more than a year old.

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.

 Share

×
×
  • 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.