Hi guys, I've searched these forums and everywhere else... and I can't understand why this won't work when it works for other people... Here are my two error messages:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Assignment\inc\ManageStock.php on line 24

Notice: Undefined index: fileField in C:\xampp\htdocs\Assignment\inc\ManageStock.php on line 39

<?php
//parse form and add inventory to system
if(isset($_POST['productName'])){
$productName = mysql_real_escape_string($_POST['productName']);
$price = mysql_real_escape_string($_POST['price']);
$category = mysql_real_escape_string($_POST['category']);
$description = mysql_real_escape_string($_POST['description']);
//check if product name ios already in use
$sql = mysql_query("SELECT id FROM products WHERE productName = '$productName' LIMIT 1");
$productMatch = (mysql_num_rows($sql));//count the output amount   <<-----LINE 24
if( $productMatch > 0) // if there is a match
{
echo "Sorry there is already a product with this name in our system!";
exit();
}
else
{
//if no match add into database
$sql = mysql_query("INSERT INTO products (productid, title, description, keywords, link, price, section)
VALUES ('', '$productName', '$description', '', '', '$price' '')");
$pid = mysql_insert_id();//sets the AI product ID to this variable
//placing image in folder
$newname = "$pid.jpg";
//should save image as the <products id>.jpg
move_uploaded_file($_FILES['fileField']['tmp_name'],'../Images/newproducts/$newname'); <<-----LINE 39
}
}

?>

any ideas? Cheers in advance

<?php
//parse form and add inventory to system
if(isset($_POST['productName'])){
$productName = mysql_real_escape_string($_POST['productName']);
$price = mysql_real_escape_string($_POST['price']);
$category = mysql_real_escape_string($_POST['category']);
$description = mysql_real_escape_string($_POST['description']);
//check if product name ios already in use
echo 'Name:'.$productName."<br/>\r\n";
$query = "SELECT id FROM products WHERE productName = '$productName' LIMIT 1";
echo 'Query:'.$query."<br/>\r\n";
$sql = mysql_query($query) or die(mysql_error());
$productMatch = (mysql_num_rows($sql));//count the output amount   <<-----LINE 24
if( $productMatch > 0) // if there is a match
{
echo "Sorry there is already a product with this name in our system!";
exit();
}
else
{
//if no match add into database
$sql = mysql_query("INSERT INTO products (productid, title, description, keywords, link, price, section)
VALUES ('', '$productName', '$description', '', '', '$price' '')");
$pid = mysql_insert_id();//sets the AI product ID to this variable
//placing image in folder
$newname = "$pid.jpg";
//should save image as the <products id>.jpg
move_uploaded_file($_FILES['fileField']['tmp_name'],"../Images/newproducts/$newname"); <<-----LINE 39 (double quotes not single)
}
}
?>

try printing out the actual query for the first one, the uploaded file was using single quotes around a variable( single quotes prints text literally '\r\n' would print \r\n where as "\r\n" would output a return and newline - same with $var)

I'm still getting the same two error messages,
the printing of the query returns: (with "black adidas gloves as the input)
Name:black adidas gloves
Query:SELECT id FROM products WHERE productName = 'black adidas gloves' LIMIT 1
so i think that part is working fine...

<?php
require("connect.php");
?>

this is just above the php block which I have already posted, inside connect.php is the code to connect to the db, and I know that it works already, other functions are working with the database using the same implementation

it's productid, I've changed that in my query now. and when i echo the query out, it's returning the name but not the query...

echo 'Name:'.$productName."<br/>\r\n";
$query = mysql_query("SELECT productid FROM products WHERE productName = '$productName' LIMIT 1");
echo 'Query:'.$query."<br/>\r\n";

--output--
Name:Adidas Response Boxing Gloves
Query:

still getting:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Assignment\inc\ManageStock.php on line 24

Notice: Undefined index: fileField in C:\xampp\htdocs\Assignment\inc\ManageStock.php on line 39

echo 'Name:'.$productName."<br/>\r\n";
$query = "SELECT productid FROM products WHERE productName = '$productName' LIMIT 1";
echo 'Query:'.$query."<br/>\r\n";
$sql = mysql_query($query) or die(mysql_error());
$productMatch = mysql_num_rows($sql);

thanks for the help so far Pritaeas. I changed productid to "id" for a function i use later on, and simplicity's sake... also in my table, the product's name is "title" so i changed your code a little and I'm getting:
Name:Hatton Blue Boxing Gloves
Query:SELECT id FROM products WHERE title = 'Hatton Blue Boxing Gloves' LIMIT 1

so that should be fine... the next part is adding the image to my directory,
still getting:
Notice: Undefined index: fileField in C:\xampp\htdocs\Assignment\inc\ManageStock.php on line 40

which is this:

move_uploaded_file($_FILES['fileField']['tmp_name'],"../Images/newproducts/$newname");

any ideas?

Says fileField is not in the POST array. Are you sure it's not a typo, or you forgot to select a file?

Undefined index means there is a variable that is being accessed that hasn't been set, in the line it looks like its this $_FILES['fileField']['tmp_name']

maybe try this instead $_FILES["file"]["tmp_name"] thats how it is in my upload script

Didn't work, still thanks for all the rapid responses; I didn't expect such a friendly and resourceful community :)
I tried instead to pass it as a variable from the form eg:

$file = mysql_real_escape_string($_POST['fileField']);

then later on:

move_uploaded_file($_FILES["$file"]["tmp_name"],"../Images/newproducts/$newname");

but still no joy:

Notice: Undefined index: Hatton_Boxing_Blue.jpg in C:\xampp\htdocs\Assignment\inc\ManageStock.php on line 41

</div>

<div id ="addNewProduct">
<a href ="ManageStock.php#inventoryForm"> + Add New Product + </a>

</div>

<div id = "inventory_Form">
<a name ="inventoryForm" id="inventoryForm"></a>
<h3> Add New Item </h3>
<form action ="ManageStock.php" name="newInventoryForm" id="myInventoryForm" method = "post">
<table>
        <tr>
            <td>Product Name:</td>
            <td><input type ='text' name ='productName' id ="prodName" size ="64" /></td>
            </tr>
        <tr>
            <td>Price:</td>
            <td><label>£
            <input type ='text' name ='price' id ="price" size ="12" />
            </label></td>
            </tr>
                    <tr>
            <td>Category:</td>
            <td><label>
            <select name ='category' id ="category" ></select>
            <option value =""></option>
            <option value ="Gloves">Gloves</option>
            <option value ="Weights">Weights</option>
            <option value ="Clothing">Clothing</option>
            <option value ="Bags">Bags</option>
            </label>

            </td>
            </tr>
                    <tr>
            <td>Description:</td>
            <td><input type ='text' name ='description' id ="description" size ="250" /></td>
            </tr>
                                <tr>
            <td>Key Words (help users search):</td>
            <td><input type ='text' name ='keywords' id ="keywords" size ="250" /></td>
            </tr>
                    <tr>
            <td>Image:</td>
            <td><input type ='file' name ='fileField' id ="fileField" /></td>
            </tr>
        <tr>
            <td></td>
            <td><input type ='submit' name ='SubmitProduct' value ='Add Product!' /></td>
            </tr>

        </table>

</form>
</div>

That is correct, maybe theres an error on the upload see what this says at the top of the ManageStock.php page

if($_FILES["file"]["error"] > 0){
    die('Return Code: '.$_FILES["file"]["error"]);
}

i notice this in my upload function, maybe it'll help

ini_set('upload_max_filesize', '20M');

still won't work :/

Notice: Undefined index: file in C:\xampp\htdocs\Assignment\inc\ManageStock.php on line 41

Notice: Undefined index: file in C:\xampp\htdocs\Assignment\inc\ManageStock.php on line 43

move_uploaded_file($_FILES["file"]["tmp_name"],"../Images/newproducts/$newname"); //41

if($_FILES["file"]["error"] > 0){                                                 //43
    die('Return Code: '.$_FILES[""]["error"]);
    }
    else
    {
//header("location: ManageStock.php");
exit();
}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.