Jump to content


Photo

need help sorting this error


  • Please log in to reply
7 replies to this topic

#1 roama1

roama1
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 08 October 2005 - 04:53 PM

trying to create an page to edit the data base file
But i keep getting this message
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 '' at line 1
Cant see the error. would appreciate some help..
Thanks

<?php require_once('../Connections/yelan.php');?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "editBooks")) {
$updateSQL = sprintf("UPDATE books SET title=%s, author=%s, price=%s, description=%s WHERE bookID=%s",
GetSQLValueString($_POST['title'], "text"),
GetSQLValueString($_POST['author'], "text"),
GetSQLValueString($_POST['price'], "double"),
GetSQLValueString($_POST['description'], "text"),
GetSQLValueString($_POST['editbooksKey'], "int"));

mysql_select_db($database_yelan, $yelan);
$Result1 = mysql_query($updateSQL, $yelan) or die(mysql_error());

$updateGoTo = "control.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}

mysql_select_db($database_yelan, $yelan);
$query_editbooks = "SELECT * FROM books WHERE bookID = $editkey";
$editbooks = mysql_query($query_editbooks, $yelan) or die(mysql_error());
$row_editbooks = mysql_fetch_assoc($editbooks);
$totalRows_editbooks = mysql_num_rows($editbooks);?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR...ml4/loose.dtd">
<html>
<head>
<title>admin edit books</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<p>edit books </p>
<form name="editBooks" method="POST" action="<?php echo $editFormAction; ?>">
<table width="106%" border="1" id="edit">
<tr>
<td width="15%">bookID</td>
<td width="15%">title</td>
<td width="18%">author</td>
<td width="17%">price</td>
<td width="20%">description</td>
</tr>
<tr>
<td><input name="edit" type="submit" id="edit" value="edit">
<input name="editbooksKey" type="hidden" id="editbooksKey" value="<?php echo $editkey?>"></td>
<td>
<input name="title" type="text" id="title" value="<?php echo $row_editbooks['title']; ?>"> </td>
<td><input name="author" type="text" id="author" value="<?php echo $row_editbooks['author']; ?>"></td>
<td><input name="price" type="text" id="price" value="<?php echo $row_editbooks['price']; ?>"></td>
<td><input name="description" type="text" id="description" value="<?php echo $row_editbooks['description']; ?>"></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="editBooks">
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($editbooks);
?>

#2 marker5a

marker5a
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 08 October 2005 - 05:08 PM

Its kind of hard to tell what is going on without knowing what file you are calling with require_once in the first line. My guess is that there is some faulty MySQL code in the '../Connections/yelan.php' file, but not to sure. Hope this helps

Chris

#3 roama1

roama1
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 08 October 2005 - 05:32 PM

Its kind of hard to tell what is going on without knowing what file you are calling with  require_once in the first line.  My guess is that there is some faulty MySQL code in the '../Connections/yelan.php'  file, but not to sure.  Hope this helps

Chris

View Post


Thanks for responding..
The require once is the connection to the database.. It works fine

What i want to have happen is.. when i want to edit a book in my database the list is generated by another page.. i hit the edit link and that particular book entry is brought up from the data base for editing.. what is happening is if i use the recordset to change the code to ...

$query_editbooks = sprintf("SELECT * FROM books WHERE bookID = %s", $colname_editbooks);



... i always get the same data base entry not he one i selected.. thats why
so i changed the code to this line of code

$query_editbooks = "SELECT * FROM books WHERE bookID = $editkey";


Its in this line of code that i think the error is.. but i cant see it.....

#4 marker5a

marker5a
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 08 October 2005 - 06:32 PM

Try this

$query_editbooks = mysql_query("SELECT * FROM books WHERE bookID = $editkey");

Let us know

Chris

#5 roama1

roama1
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 09 October 2005 - 01:59 AM

Try this

$query_editbooks = mysql_query("SELECT * FROM books WHERE bookID = $editkey");

Let us know

Chris

View Post

Thanks for looking at this problem.. I tried the code you gave, now the error reads.. Query was empty...

#6 marker5a

marker5a
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 09 October 2005 - 02:03 AM

One other idea for you

$query_editbooks = mysql_query("SELECT * FROM `books` WHERE bookID = '$editkey'");

Not much changed with the code, but thats how I do my queries. Give it a shot, and let me know

Chris

#7 roama1

roama1
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 09 October 2005 - 02:08 AM

One other idea for you

$query_editbooks = mysql_query("SELECT * FROM `books` WHERE bookID = '$editkey'");

Not much changed with the code, but thats how I do my queries.  Give it a shot, and let me know

Chris

View Post


Thanks again.. tried the new code now i have this error

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 'Resource id #4' at line 1



#8 roama1

roama1
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 10 October 2005 - 11:56 PM

Thanks again.. tried the new code now i have this error

View Post


Found a solution... what i did was went to my control.php page and edited the link to editbooks.php. by removing the buttons and using an image and adding the value to be carried over it worked.. weired but it solved the problem


<a href="editbooks.php?editkey=<?php echo $row_control['bookID']; ?>" name="editkey"><img src="quill.png" width="20" height="22"></a>






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users