roama1 Posted October 8, 2005 Share Posted October 8, 2005 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/html4/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> </p> </body> </html> <?php mysql_free_result($editbooks); ?> Quote Link to comment https://forums.phpfreaks.com/topic/2635-need-help-sorting-this-error/ Share on other sites More sharing options...
marker5a Posted October 8, 2005 Share Posted October 8, 2005 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 Quote Link to comment https://forums.phpfreaks.com/topic/2635-need-help-sorting-this-error/#findComment-8730 Share on other sites More sharing options...
roama1 Posted October 8, 2005 Author Share Posted October 8, 2005 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 304238[/snapback] 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..... Quote Link to comment https://forums.phpfreaks.com/topic/2635-need-help-sorting-this-error/#findComment-8731 Share on other sites More sharing options...
marker5a Posted October 8, 2005 Share Posted October 8, 2005 Try this $query_editbooks = mysql_query("SELECT * FROM books WHERE bookID = $editkey"); Let us know Chris Quote Link to comment https://forums.phpfreaks.com/topic/2635-need-help-sorting-this-error/#findComment-8732 Share on other sites More sharing options...
roama1 Posted October 9, 2005 Author Share Posted October 9, 2005 Try this $query_editbooks = mysql_query("SELECT * FROM books WHERE bookID = $editkey"); Let us know Chris 304251[/snapback] Thanks for looking at this problem.. I tried the code you gave, now the error reads.. Query was empty... Quote Link to comment https://forums.phpfreaks.com/topic/2635-need-help-sorting-this-error/#findComment-8738 Share on other sites More sharing options...
marker5a Posted October 9, 2005 Share Posted October 9, 2005 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 Quote Link to comment https://forums.phpfreaks.com/topic/2635-need-help-sorting-this-error/#findComment-8739 Share on other sites More sharing options...
roama1 Posted October 9, 2005 Author Share Posted October 9, 2005 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 304338[/snapback] 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 Quote Link to comment https://forums.phpfreaks.com/topic/2635-need-help-sorting-this-error/#findComment-8740 Share on other sites More sharing options...
roama1 Posted October 10, 2005 Author Share Posted October 10, 2005 Thanks again.. tried the new code now i have this error 304340[/snapback] 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> Quote Link to comment https://forums.phpfreaks.com/topic/2635-need-help-sorting-this-error/#findComment-8769 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.