0

I am trying to create a products page in a admin panel, where the administrator can input their products. I am trying to add the product to the database and use a or die output if anything goes wrong. But it seems like every time I type in or die, I receive a error code before evening running the code (last part of code).

What is the reason for this? Please help.

<?php
// parse from data
if (isset($_POST['product_name'])) {

    $pid = mysql_real_escape_string($_POST['thisID']);
    $Product_Name = mysql_real_escape_string($_POST['Product_Name']);
    $desc = mysql_real_escape_string($_POST['Product_Desc']);

    // See if that product name is an identical match to another product in the system
    $sql = mysql_query("UPDATE products SET product_name='$Product_Name'LIMIT 1");
    $productMatch= mysql_mum_rows($sql);
    if ($productMatch>0){
        echo "Sorry you tried to place a duplicate product name";
        exit();
    }   

    //add products to database
    $sql = mysql_query("INSERT INTO Product(Product_Name,Product_Desc,date_added)
    VALUES('$Product_Name','$desc',now())") or die(mysql_error())

<?php
//blocks gravs
?>
fusion3k
  • 11,568
  • 4
  • 25
  • 47
jerneva
  • 473
  • 1
  • 8
  • 25
  • 1
    Add semicolon in the end and where are you closing your first IF? – Hail Hydra Feb 05 '16 at 01:56
  • first thing to do is turn on error reporting, and why are you using update and checking for number of rows? just use `COUNT` if you want to check whether that particular name exists – Kevin Feb 05 '16 at 01:56
  • 2
    `$productMatch= mysql_mum_rows($sql);` is wrong - from [`mysql_num_rows()`](http://php.net/manual/en/function.mysql-num-rows.php) - `...This command is only valid for statements like SELECT or SHOW that return an actual result set. To retrieve the number of rows affected by a INSERT, UPDATE, REPLACE or DELETE query, use mysql_affected_rows().` – Sean Feb 05 '16 at 01:56

1 Answers1

0

You forgot to terminate(;) your code in die part and you open again a php code but you forgot to close the part last php code.so to correct it might be like this.

<?php
//..Some of your code here
    $sql = mysql_query("INSERT INTO Product(Product_Name,Product_Desc,date_added)
            VALUES('$Product_Name','$desc',now())") or die(mysql_error());

    //blocks gravs
    ?>
jameshwart lopez
  • 2,993
  • 6
  • 35
  • 65