Jump to content

PHP error....


s_ainley87

Recommended Posts

Can anybody see the reason as to why my file is not being moved across to the uploads folder and the filename is not going to the table?

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Product added redirecting....</title>
</head>

<body>
<?php
require_once ('include/mysql_connect.php'); // Connect to the database.
if ($_POST[op] != "yes"){ // Check if the form has been submitted.

if (!empty($_POST['Prodname'])) {
	$pn = escape_data($_POST['Prodname']);
} else {
	$pn = FALSE;
	echo '<p><font color="red">Please enter the product\'s name!</font></p>';
}

if (!empty($_POST['Catname'])) {
	$cn = escape_data($_POST['Catname']);
} else {
	$cn = FALSE;
	echo '<p><font color="red">Please enter the product\'s category name!</font></p>';
}
// Check for an image.
if (is_uploaded_file ($_FILES['image']['tmp_name'])) {
	if (move_uploaded_file($_FILES['image']['tmp_name'], "uploads/{$_FILES['image']['name']}")) { // Move the file over.

		echo "<sript>window.alert('The file has been uploaded!')</script>";

	} 
	else 
	{ // Couldn't move the file over.
		echo '<p><font color="red">The file could not be moved.</font></p>';
		$i = FALSE;
	}
	$i = $_FILES['image']['name'];
} 
else
{
$i=FALSE;
}
// Check for a price.
if (is_numeric($_POST['Prodprice'])) {
	$p = $_POST['Prodprice'];
} else {
	$p = FALSE;
	echo '<p><font color="red">Please enter the products\'s price!</font></p>';
}

// Check for a description (not required).
if (!empty($_POST['Proddesc'])) 
{
$d = escape_data($_POST['Proddesc']);
} 
	else 
	{
	$d = '<i>No description available.</i>';	
	} 

if(!isset($pn) || !isset($cn) || !isset($d) || !isset($p) ||!isset($i))
{
    echo "Somthing is not working";
}
elseif (isset($pn) || isset($cn) || isset($p) || isset($d) ||isset($i))
{

	// Add the product to the database.

	$query = "INSERT INTO product (product_name, category_name, product_price, product_desc, image_name) VALUES ('$pn','$cn', '$p','$d','$i')";
	if (mysql_query ($query,$dbc)) 
	{ // Worked.
		echo "<script> window.alert('Product added you will now be sent back to the hub')</script>";
	echo "<script type=\"text/javascript\">
	window.location = \"adminhub.php\"
	</script>";
	} 
		else 
		{ // If the query did not run OK.
		echo '<p><font color="red">Your submission could not be processed due to a system error.</font></p>'; 
		}

} 
			else 
			{ // Failed a test.
			echo '<p><font color="red">Please click <a href =\"products.php\">back</a> and try again.</font></p>';
			}

				} 
?>
</body>
</html>[\code]

Link to comment
Share on other sites

this is what the form looks like, i am also getting an undefined index on line 29 that is the is_uploaded_file line.

 

echo " please add the category to the database <br/><form method=\"POST\" action=\"addproddatabase.php\">
<div align=\"left\">
<strong>Product Name:</strong><input type=\"text\" name=\"Prodname\"/><br/><br/>
<strong>Category Name:</strong><input type=\"text\" name=\"Catname\"/><br/><br/>
<strong>Product Price:</strong><input type=\"text\" name=\"Prodprice\" /><br/><br/>
<strong>Product Description</strong><textarea name=\"Proddesc\"/></textarea><br/><br/>
<strong>Product Image:</strong><input type=\"file\" name=\"image\" /><br/><br/>
<input type=\"submit\" name=\"submit\" value=\"Add To Database\" />
</div>
</form>";

Link to comment
Share on other sites

BlueSkyIS, the undefined index error means the code is accessing a variable that does not exist and the code will never work. Changing the error reporting to hide the message just means that the code is still accessing a variable that does not exist and will never work, but now you don't even know what the code is doing that is not working.  ::)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.