Hello. I have a set of pages that work in another module. I copied the code over to a new module, and made changes to the user variables, and, the code works in the other module, but it gives me the following error message when I try it in the new module:
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 'WHERE bid='3'' at line 1
This error comes in the second script, after the submit button is pressed in the first script, and the processing begins in the second script.
Here are the two code pages:
bio_update.php
<?php
echo 'Hello and welcome <b>' . $_SESSION['YourName'] . '</b> !!';
$whois = $_SESSION['YourName'];
$result = mysql_query("SELECT bid , uname , ubio , pic FROM biography WHERE uname LIKE '$whois'") or exit(mysql_error());
$bioarray = mysql_fetch_assoc($result);
foreach ($bioarray as $key => $value)
{
$$key = htmlspecialchars($value);
}
echo 'Make your <B>CHANGES</b> in the form below:<br><br>
<form enctype="multipart/form-data" method="post" action="bio_change_update.php">
<table width="100%">
<tr><td><b>Upload a picture?</b></td></tr>
<tr><td><input type="file" name="biospic"><input type="submit" name="submit" value="UPDATE!"></td></tr>
<tr><td><input type="hidden" name="biosid" value="' . $bid . '"</td></tr>
<tr><td><b>About You:</b></td></tr>
<tr><td><textarea name="biodesc" rows="20" cols="80"> ' . $ubio . '</textarea></td></tr>
</table>
</form>
';
?>
bio_change_update.php
<?php
session_start();
include 'config.php';
$picture = basename( $_FILES['biospic']['name']);
//Correctly escape out all info in fields from POST operation
foreach ($_POST as $key => $value)
{
$value = trim($value);
if ($value != '') {$value = "'" . mysql_real_escape_string($value) . "'";}
else {$value = 'NULL';}
$$key = $value;
}
$sql = "UPDATE biography SET ubio=$biodesc, pic=$biospic WHERE bid=$biosid";
$result = mysql_query($sql) or exit(mysql_error());
//Now we need to upload the file
if ($picture <> NULL) {
$target_path = "biography/";
$target_path = $target_path . basename( $_FILES['biospic']['name']);
if(move_uploaded_file($_FILES['biospic']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['biospic']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
}
}
mysql_close;
$_SESSION['admin'] = NULL;
$_SESSION['nametest'] = basename( $_FILES['biospic']['name']);
include 'index.php';
?>
I dont see what is causing the error. I am not sure exactly what the error message is pointing at. Any one see what is wrong?
Thanks;
Ice