yandoo Posted January 29, 2008 Share Posted January 29, 2008 Hi, I keep getting an error using a select query. Theres only a tiny amount of code on my test page: <?php require_once('Connections/woodside.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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php mysql_select_db($database_woodside, $woodside); $query_Recordset1 = "SELECT * FROM breed WHERE AnimalTypeID=$_POST[AnimalTypeID]"; $Recordset1 = mysql_query($query_Recordset1, $woodside) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); mysql_select_db($database_woodside, $woodside); $query_Recordset2 = "SELECT * FROM animal"; $Recordset2 = mysql_query($query_Recordset2, $woodside) or die(mysql_error()); $row_Recordset2 = mysql_fetch_assoc($Recordset2); $totalRows_Recordset2 = mysql_num_rows($Recordset2); ?> <form id="form1" name="form1" method="get" action=""> <input name="hiddenField" type="hidden" value="<?php echo $row_Recordset2['AnimalTypeID']; ?>" /> </form> </body> </html> <?php mysql_free_result($Recordset2); ?> The error message i keep getting is: 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 Im pretty sure it is to do with this line of code: $query_Recordset1 = "SELECT * FROM breed WHERE AnimalTypeID=$_POST[AnimalTypeID]"; When trying to test the query i get this error 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 '[AnimalTypeID]' at line 1 How do i fix this please? Any help greatly appreciated Thank you Quote Link to comment https://forums.phpfreaks.com/topic/88366-solved-querycode-error/ Share on other sites More sharing options...
trq Posted January 29, 2008 Share Posted January 29, 2008 $query_Recordset1 = "SELECT * FROM breed WHERE AnimalTypeID='{$_POST['AnimalTypeID']}'"; Quote Link to comment https://forums.phpfreaks.com/topic/88366-solved-querycode-error/#findComment-452243 Share on other sites More sharing options...
yandoo Posted January 29, 2008 Author Share Posted January 29, 2008 Brilliant, thank you Quote Link to comment https://forums.phpfreaks.com/topic/88366-solved-querycode-error/#findComment-452244 Share on other sites More sharing options...
yandoo Posted January 29, 2008 Author Share Posted January 29, 2008 Hi, Thanks for your help, ive just done some testing and it has fixed the 1st error message on opening the page, which is brilliant. There is a slightly different error that applies to the same query saying: mysql 1064: 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 'AnimalTypeID]'}" at line 1 Any ideas? Thank You Quote Link to comment https://forums.phpfreaks.com/topic/88366-solved-querycode-error/#findComment-452252 Share on other sites More sharing options...
duclet Posted January 29, 2008 Share Posted January 29, 2008 Becareful of your single quote: '{$_POST['AnimalTypeID']}' not '{$_POST['AnimalTypeID]'}' or whatever it was. Quote Link to comment https://forums.phpfreaks.com/topic/88366-solved-querycode-error/#findComment-452255 Share on other sites More sharing options...
yandoo Posted January 29, 2008 Author Share Posted January 29, 2008 Hi, that is what my code is though???? WHERE AnimalTypeID='{$_POST['AnimalTypeID']}' the error message just adds " to it: 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 'AnimalTypeID']}" at line 1 Think previous message had typo as it is above Thank You Quote Link to comment https://forums.phpfreaks.com/topic/88366-solved-querycode-error/#findComment-452258 Share on other sites More sharing options...
trq Posted January 29, 2008 Share Posted January 29, 2008 Post your current code. Quote Link to comment https://forums.phpfreaks.com/topic/88366-solved-querycode-error/#findComment-452270 Share on other sites More sharing options...
yandoo Posted January 29, 2008 Author Share Posted January 29, 2008 Thaks for reply, heres my test code is using: <?php require_once('Connections/woodside.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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php mysql_select_db($database_woodside, $woodside); $query_Recordset1 = "SELECT * FROM breed WHERE AnimalTypeID='{$_POST['AnimalTypeID']}'"; $Recordset1 = mysql_query($query_Recordset1, $woodside) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <form id="form1" name="form1" method="post" action=""> <input name="hiddenField" type="hidden" value="<?php echo $row_Recordset2['AnimalTypeID']; ?>" /> <?php $_POST['AnimalTypeID']; ?></form> </body> </html> <?php echo $Recordset1; mysql_free_result($Recordset2); ?> Thank You Quote Link to comment https://forums.phpfreaks.com/topic/88366-solved-querycode-error/#findComment-452274 Share on other sites More sharing options...
yandoo Posted January 29, 2008 Author Share Posted January 29, 2008 Hi there, Im getting the follwoing error message when looking at the query, the page however opens fine it it just the syntax of this query i think: $query_Recordset1 = "SELECT * FROM breed WHERE AnimalTypeID='{$_POST['AnimalTypeID']}'"; Error: mysql 1064: check the manual that corresponds to your MySQL server version for the right syntax to use near 'AnimalTypeID']}" Any suggestions??? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/88366-solved-querycode-error/#findComment-452388 Share on other sites More sharing options...
yandoo Posted January 29, 2008 Author Share Posted January 29, 2008 Anybody who wanted to know, i changed ' ' quotes for `` around AnimalTypeID. thanks Quote Link to comment https://forums.phpfreaks.com/topic/88366-solved-querycode-error/#findComment-452407 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.