I am getting the following error when I try to use my edit.php script:

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

I can't seem to find anything wrong with my syntax below.

Has anyone ever had this issue?

I have been googling it for a couple hours now.

Thank you in advance!


ini_set('display_errors', '1');
 Allows user to edit specific entry in database

 // creates the edit record form
 // since this form is used multiple times in this file, I have made
it a function that is easily reusable
 function renderForm($id, $Cricket_Region, $Market, $error)
 <title>Edit Record</title>
 // if there are any errors, display them
 if ($error != '')
 echo '<div style="padding:4px; border:1px solid red;

 <form action="" method="post">
 <input type="hidden" name="id" value="<?php echo $id; ?>"/>
 <p><strong>ID:</strong> <?php echo $id; ?></p>
 <strong>Cricket Region: *</strong> <input type="text" name="Cricket
Region" value="<?php echo $Cricket_Region; ?>"/><br/>
 <strong>Market: *</strong> <input type="text" name="Market"
value="<?php echo $Market; ?>"/><br/>
 <p>* Required</p>
 <input type="submit" name="submit" value="Submit">

 // connect to the database

 // check if the form has been submitted. If it has, process the form
and save it to the database
 if (isset($_POST['submit']))
 // confirm that the 'id' value is a valid integer before getting the form data
 if (is_numeric($_POST['id']))
 // get form data, making sure it is valid
 $id = $_POST['id'];
 $Cricket_Region =
 $Market = mysql_real_escape_string(htmlspecialchars($_POST['Market']));

 // check that firstname/lastname fields are both filled in
 if ($Cricket_Region == '' || $Market == '')
 // generate error message
 $error = 'ERROR: Please fill in all required fields!';

 //error, display form
 renderForm($id, $Cricket_Region, $Market, $error);
 // save the data to the database
 mysql_query("UPDATE expiringleases SET
Cricket_Region='$Cricket_Region', Market='$Market' WHERE id='$id'")
 or die(mysql_error());

 // once saved, redirect back to the view page
 header("Location: view.php");
 // if the 'id' isn't valid, display an error
 echo 'Error!';
 // if the form hasn't been submitted, get the data from the db and
display the form

 // get the 'id' value from the URL (if it exists), making sure that
it is valid (checking that it is numeric/larger than 0)
 if (isset($_GET['id']))
 // query db
 $id = $_GET['id'];
 $result = mysql_query("SELECT * FROM expiringleases WHERE id=$id")
 or die(mysql_error());
 $row = mysql_fetch_array($result);

 // check that the 'id' matches up with a row in the databse

 // get data from db
 $Cricket_Region = $row['Cricket_Region'];
 $Market = $row['Market'];

 // show form
 renderForm($id, $Cricket_Region, $Market, '');
 // if no match, display result
 echo "No results!";
 // if the 'id' in the URL isn't valid, or if there is no 'id' value,
display an error
 echo 'Error!';

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to