Jump to content

re error in coding


blui

Recommended Posts

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>

 

 

Link to comment
https://forums.phpfreaks.com/topic/43628-re-error-in-coding/
Share on other sites

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());

 

 

Link to comment
https://forums.phpfreaks.com/topic/43628-re-error-in-coding/#findComment-211835
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/43628-re-error-in-coding/#findComment-212263
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/43628-re-error-in-coding/#findComment-212277
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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