Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/88366-solved-querycode-error/
Share on other sites

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

 

 

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 :)

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 :)

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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