lostlee Posted January 28, 2012 Share Posted January 28, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/255955-mysql-insert-into-table-values/ Share on other sites More sharing options...
joel24 Posted January 29, 2012 Share Posted January 29, 2012 post your code Quote Link to comment https://forums.phpfreaks.com/topic/255955-mysql-insert-into-table-values/#findComment-1312107 Share on other sites More sharing options...
AyKay47 Posted January 29, 2012 Share Posted January 29, 2012 http://dev.mysql.com/doc/refman/5.1/en/insert.html Quote Link to comment https://forums.phpfreaks.com/topic/255955-mysql-insert-into-table-values/#findComment-1312109 Share on other sites More sharing options...
lostlee Posted January 29, 2012 Author Share Posted January 29, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/255955-mysql-insert-into-table-values/#findComment-1312160 Share on other sites More sharing options...
litebearer Posted January 29, 2012 Share Posted January 29, 2012 We really do need to see some of the code you have tried Quote Link to comment https://forums.phpfreaks.com/topic/255955-mysql-insert-into-table-values/#findComment-1312162 Share on other sites More sharing options...
Pikachu2000 Posted January 29, 2012 Share Posted January 29, 2012 The query syntax is no different whether you're using variables or actual values. Post the code your having problems with, along with any error messages. Quote Link to comment https://forums.phpfreaks.com/topic/255955-mysql-insert-into-table-values/#findComment-1312176 Share on other sites More sharing options...
scootstah Posted January 29, 2012 Share Posted January 29, 2012 mysql_query("INSERT INTO table (col1, col2, col3) VALUES ('" . $col1 . "', '" . $col2 . "', '" . $col3 . "')"); Quote Link to comment https://forums.phpfreaks.com/topic/255955-mysql-insert-into-table-values/#findComment-1312178 Share on other sites More sharing options...
AyKay47 Posted January 29, 2012 Share Posted January 29, 2012 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). Quote Link to comment https://forums.phpfreaks.com/topic/255955-mysql-insert-into-table-values/#findComment-1312184 Share on other sites More sharing options...
scootstah Posted January 29, 2012 Share Posted January 29, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/255955-mysql-insert-into-table-values/#findComment-1312188 Share on other sites More sharing options...
AyKay47 Posted January 29, 2012 Share Posted January 29, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/255955-mysql-insert-into-table-values/#findComment-1312189 Share on other sites More sharing options...
scootstah Posted January 29, 2012 Share Posted January 29, 2012 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". Quote Link to comment https://forums.phpfreaks.com/topic/255955-mysql-insert-into-table-values/#findComment-1312192 Share on other sites More sharing options...
Pikachu2000 Posted January 29, 2012 Share Posted January 29, 2012 I find this easier to read, by a long shot: $query = "INSERT INTO table (col1, col2, col3) VALUES ('$col1', '$col2', '{$col3['index']}', '$col4'); Quote Link to comment https://forums.phpfreaks.com/topic/255955-mysql-insert-into-table-values/#findComment-1312194 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.