PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
The id number from the url is not added to the database. I know that the id number is in the url. It displays nothing when I echo the id which is strange. When I echo the id before the submit button code it displays. So the submit button is the problem. Can someone please have a look at my code below and tell me why this is happening? Thanks in advance.
require "config.php";
// define variables
$findphoto = $_FILES['findphoto'];
$photo = mysql_real_escape_string($_POST['photo']);
$filename = mysql_real_escape_string($_POST['filename']);
//$id = $_GET['id']; // get the id number from the url
$arrErrors = array();
// on submit
if (isset($_POST['btnsubmit'])) {
if($_FILES['findphoto']['name'] == '') {
$arrErrors['findphoto'] = 'You did not select a photo to upload';
}
if ($photo == '') {
$arrErrors['photo'] = 'Please enter a photo name and file extension that you wish to upload for this clearing sale.';
}
if ($filename == '') {
$arrErrors['filename'] = 'Please enter a file name for the photo.';
}
if (count($arrErrors) == 0) {
$parent_id = $_GET['id'];
// insert the id into the table
$insert = "INSERT INTO `clearingsales_photos` (`parent_id`, `photos`, `filename`) VALUES ('$parent_id', '$photo', '$filename')";
if (mysql_query ($insert)) {
print "<strong>Photo and filename have been added to the database. Please don't forget to upload the files via ftp.</strong><br /><br />";
} else {
print "<p>Could not add the entry because: <b>" . mysql_error() . "</b>. The query was $insert.</p>";
}
} else {
// The error array had something in it. There was an error.
// Start adding error text to an error string.
$strError = '<div class="formerror"><p>Please check the following and try again:</p><ul>';
// Get each error and add it to the error string
// as a list item.
foreach ($arrErrors as $error) {
$strError .= "<li>$error</li>";
}
$strError .= '</ul></div>';
}
}
else {
print "<p>Could not add the entry because: <b>" . mysql_error() . "</b>. The query was $insert.</p>";
}
Are you recieving this error? If so, it's a problem in your database connection.
Beyond that, I don't really see anything particularly wrong in the php. If you're problem is beyond that, try making your form's action="" include the id.
Refresh the page and if I see it, move it to another if statement and try again. It's actually a fairly quick process. Find out where your script isn't going. If it's going everywhere, then the error isn't in the conditions. Just a good way to make sure.
Or more importantly, is anything going in? Or is it JUST not the id not being inserted? I'm thinking maybe the problem is your table. Is your id field auto_increment or enum by any chance?