blui Posted March 21, 2007 Share Posted March 21, 2007 Hi all, I am still new to this php and MySQL and am trying to create a dynamic dropdown menu that is created from all the files in a directory. I am trying to insert the data - which would look like this 'images/index.jpg' into the field 'links' where the PRIMARY ID equals 1. But I recieve the following error message:- Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in....phpinfo2.php I know I am close but I have tried so many different alterations and none seem to work, can someone please help? All 3 scripts involved are listed below phpinfo.php:- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <? require_once('connectionlocal.php'); ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form action="../php/postinfo2.php" method="post"> <label>Choose your image <select name="imagelist"> <? require_once('directorylistinginc.php'); ?> </select> </label> <input type="submit" name="submit" value="submit"> </form> </body> </html> ------------------------------------------------------------------------ directorylistinginc.php:- <? $file_dir="images"; $dir=opendir($file_dir); while ($file=readdir($dir)) { if ($file != "." && $file != "..") { echo "<option value=".$file_dir."/".$file." >".$file.""; echo "</option>"; } } ?> -------------------------------------------------------------------- phpinfo2.php:- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <? require_once('connectionlocal.php'); ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?PHP $sql = "INSERT INTO cmscontent where PRIMARY ID = 1(links) VALUES ($_POST['imagelist'])"; $queryResult = mysql_query($sql) or die("An error has happened: " . mysql_error() ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
btherl Posted March 21, 2007 Share Posted March 21, 2007 Try this instead.. I added {} around the variable and added a missing closing bracket on die() $sql = "INSERT INTO cmscontent where PRIMARY ID = 1(links) VALUES ({$_POST['imagelist']})"; $queryResult = mysql_query($sql) or die("An error has happened: " . mysql_error()); Quote Link to comment Share on other sites More sharing options...
blui Posted March 21, 2007 Author Share Posted March 21, 2007 Hi there, I tried the alterations to the code as you suggested but recieved the following error instead:- An error has happened: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'where PRIMARY ID = 1(links) VALUES (images/stuff.jpg)' at line Any further suggestions Quote Link to comment Share on other sites More sharing options...
paul2463 Posted March 21, 2007 Share Posted March 21, 2007 shouldnt the syntax of a query be like this //$sql = "INSERT INTO table (columns) VALUES (values) WHERE column_id = variable" $sql = "INSERT INTO cmscontent (links) VALUES ({$_POST['imagelist']}) WHERE PRIMARYID = 1"; Quote Link to comment Share on other sites More sharing options...
blui Posted March 21, 2007 Author Share Posted March 21, 2007 Hi Paul tried your version and the error has now changed (would the fact that I am currently working on MySQL version 3.23 have an impact?) An error has happened: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE PRIMARYID = 1' at line 1 Quote Link to comment Share on other sites More sharing options...
paul2463 Posted March 21, 2007 Share Posted March 21, 2007 what it doesnt understand is the where clause do you have a column name called PRIMARYID and if so do you have a PRIMARYID of 1 in that table?? Quote Link to comment Share on other sites More sharing options...
blui Posted March 21, 2007 Author Share Posted March 21, 2007 I thought I would have included a PRIMARYID column, but I will double check thats the case, before continuing with anything else thanks for the pointer though Quote Link to comment 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.