I'm trying to pass search results to text bxes in a form, which I can then change and then update the database. I cannot see where my error is! It is when I try to update that it goes wrong
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 '1' at line 1
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 '1' at line 1
Code:
<?PHP
include 'config.php';
include 'opendb.php';
//create search form,
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
Enter First Name:-<INPUT NAME="FirstName" TYPE="TEXT" id="FirstName" size="50" maxlength="50"><br>
Enter Surname:-<INPUT NAME="SurName" TYPE="TEXT" id="SurName" size="50" maxlength="50"><br>
<INPUT TYPE="SUBMIT" NAME="Search" id="SUBMIT" VALUE="Search">
</FORM>
<?PHP
$queryItem = array();
if(isset($_POST['Search']))
{
if ($_POST['FirstName'])
{
$queryItem[] = "FirstName='".mysql_escape_string($_POST['FirstName'])."'";
}
if ($_POST['SurName'])
{
$queryItem[] = "SurName='".mysql_escape_string($_POST['SurName'])."'";
}
if ($_POST['Postcode'])
{
$queryItem[] = "Postcode='".mysql_escape_string($_POST['Postcode'])."'";
}
//now you create your query statement (I assume AND)
$query1 = "SELECT * FROM Addressbook WHERE ".implode(" AND ", $queryItem) or die(mysql_error());
$result1 = mysql_query($query1) or die(mysql_error());
// get the entry from the result
while($row = mysql_fetch_array($result1)) // Print out the contents
{
$ud_ID = $row['ID'];
$ud_FirstName = $row['FirstName'];
$ud_SurName = $row['SurName'];
echo $row['ID']." "."<br>";
echo $row['FirstName']." ".$row['SurName'];
echo"<br>";
echo $row['Address1']." ".$row['Address2']." ".$row['Address3'];
echo"<br>";
echo $row['Town']." ".$row['Postcode'];
echo"<br>";
echo "<em><strong>E-Mail:-</em></strong>"." ".$row['email'];
echo"<br>";
echo "<em><strong>Phone:-</em></strong>"." ".$row['Phone'];
echo"<p></P>";
}
echo "<br>";
}
/*The variable is passed from the array found by result and placed in the text box,
the value to be changed and then the update passed to the database
*/
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
ID Number :-<input name="ID" value="<?PHP echo "$ud_ID";?>"><br>
First Name:-<input name="ud_FirstName" value="<?PHP echo "$ud_FirstName";?>"><br>
Surname:-<input name="ud_SurName" value="<?PHP echo "$ud_SurName";?>">
<INPUT TYPE="SUBMIT" NAME="Update" id="SUBMIT" VALUE="Update">
<?PHP
if(isset($_POST['Update']))
{
$ud_ID = $_POST['ud_ID'];
$ud_FirstName = $_POST['ud_FirstName'];
$ud_SurName = $_POST['ud_SurName'];
$query2 = "UPDATE Addressbook SET FirstName ='$ud_FirstName' Where ID = '$ud_ID' ";
$result2 = mysql_query($query2) or die(mysql_error());
if(mysql_query($result2))
{
echo("<P> The address and all Information has been added<?P>");
}
else
{
echo("<P>Error adding Address information:<br>". mysql_error() ."</P>");
}
}
?>
<?PHP
include 'close.php';
?>