Started work early this morning and im still having issues with this. Although the error message is different. Here is my code:
<?php
session_start();
require_once('common_functions.php');
$_SESSION['form1_data']='';
?>
<?php
// list box to choose quality standard or approach to update
if (!isset ($_POST['submit'])) ;
{
echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="POST">'
. 'Choose a quality standard/approach to update: <select name="quality_id">' . "\n";
$sql = "SELECT quality_id FROM quality_info";
$result = mysql_query($sql, $connection)
OR die(mysql_error());
while ($row = mysql_fetch_assoc($result))
{
echo '<option value="' . $row['quality_id'] . '">'
. $row['quality_id'] . "</option>\n";
}
echo '</select><input type="submit" name="submit" value="find" /></form>';
}
?>
</form>
<?php
//prepopulate the form
if (isset ($_POST['submit']) && $_POST['submit'] == 'find');
{
$result = mysql_query ("SELECT * FROM quality_info WHERE quality_id = '" . $_POST['quality_id'] . "'");
if (mysql_num_rows ($result)) {$row = mysql_fetch_assoc ($result);}
else {echo 'no records found matching ' . $_POST['quality_id'];}
echo '
<form action="' . $_SERVER['PHP_SELF'] . '" method="POST">
<td width="6%"></td>
<table width="100%" border="0">
<tr>
<td width="3%"> </td>
<td width="1%"> </td>
</tr>
<tr>
<td><strong>Quality name </strong></td>
<td width="39%"><input type="text" name="quality_name" value="' . $row['quality_name'] . '"></td>
<td> </td>
</tr>
<tr>
<td><strong>Authoritative/associative/governing body </strong></td>
<td width="39%"><input name="authority_body" type="text" size="50" value="' . $row['authority_body'] . '"></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><strong>Address1</strong></td>
<td width="39%"><input name="address1" type="text" size="50" value="' . $row['address1'] . '"></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><strong>Address2</strong></td>
<td width="39%"><input name="address2" type="text" size="50" value="' . $row['address2'] . '"></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><strong>Town</strong></td>
<td width="39%"><input name="town" type="text" size="50" value="' . $row['town'] . '"></td>
<td> </td>
</tr>
<tr>
<td><strong>Postcode</strong></td>
<td width="39%"><input name="postcode" type="text" size="50" value="' . $row['postcode'] . '"></td>
<td> </td>
</tr>
<tr>
<td><strong>Telephone</strong></td>
<td width="39%"><input name="telephone" type="text" size="50" value="' . $row['telephone'] . '"></td>
<td> </td>
</tr>
<tr>
<td><strong>Email</strong></td>
<td width="39%"><input name="email" type="text" size="50" value="' . $row['email'] . '"></td>
<td> </td>
</tr>
<tr>
<td><strong>Website</strong></td>
<td width="39%"><input name="website" type="text" size="50" value="' . $row['website'] . '"></td>
<td> </td>
</tr>
<tr>
<td><strong>Local agency</strong></td>
<td width="39%"><textarea name="local_agency" rows = "5" cols="20">' . $row['local_agency'] . '</textarea></td>
<td> </td>
</tr>
<tr>
<td><strong>Contact</strong></td>
<td width="39%"><textarea name="contact" rows = "5" cols="40">' . $row['contact'] . '</textarea></td>
<td> </td>
</tr>
<tr>
<td><strong>What is it?</strong></td>
<td width="39%"><textarea name="what_is_it" rows = "5" cols="40">' . $row['what_is_it'] . '</textarea></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><strong>Who and what does it apply to?</strong></td>
<td width="39%"><textarea name="who_what_apply" rows = "5" cols="40">' . $row['who_what_apply'] . '</textarea></td>
<td> </td>
</tr>
<tr>
<td><strong>How does it work?</strong></td>
<td width="39%"><textarea name="how_work" rows = "5" cols="40">' . $row['how_work'] . '</textarea></td>
<td> </td>
</tr>
<tr>
<td><strong>What are the resource implications</strong></td>
<td width="39%"><textarea name="resource_implications" rows = "5" cols="40">' . $row['resource_implications'] . '</textarea></td>
<td> </td>
</tr>
<td>Click the submit button when you have completed your update
<input name="submit" type="submit" id="submit" value="update"></td>
<td> </td>
</tr>
</table>
</form>
</div>
</body>
</html>
';
}
?>
<?php
if (isset($_POST['submit']) && $_POST['submit'] == 'update')
{
//this is the update part
$sql = "UPDATE quality_info SET
quality_name= '".$_POST['quality_name']."',
authority_body= '".$_POST['authority_body']."',
address'= '".$_POST['address1']."',
address2= '".$_POST['address2']."',
town= '".$_POST['town']."',
postcode= '".$_POST['postcode']."',
telephone= '".$_POST['telephone']."',
email= '".$_POST['email']."',
website= '".$_POST['website']."',
local_agency= '".$_POST['local_agency']."',
contact= '".$_POST['contact']."',
what_is_it= '".$_POST['what_is_it']."',
who_what_apply= '".$_POST['who_what_apply']."',
how_work= '".$_POST['how_work']."',
resource_implications= '".$_POST['resource_implications']."',
WHERE quality_id = '".$row['quality_id']."'
";
}
$result = mysql_query($sql) or die(mysql_error());
echo $row['quality_id'];
?>
</form>
the error message is vague:
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 ''= 'bbbbbb', address2= 'cccc', town= 'ddddd', postcode= '
I have echoed my quality_id which outputs the correct number (depending on the choice made in the quality_id list box) so I still cannot see where im going wrong aaaahhrrrghhhh!