Jump to content

double entry


witham

Recommended Posts

I would really appreciate some help with a problem I have with a script I have written. the problem I have is that when you add a product it enters the data twice?

I would include the code but I am usnsure how to present it properly?

Could anyone please give me some pointers?

Thanks
Link to comment
Share on other sites

Thanks for your reply (how do you present the code properly?)

This is the business part that does the "insert" but I cannot see why it is doubling it up


<?

//check the $ProdName variable to see if it has data if not send the user back to the entry page
// this has to be done before any output


if (empty($ProdName)){ 
header("Location: addprod.php");
die ("opps"); 
}

if (empty($ProdEquiv)){ 
header("Location: addprod.php");
die ("opps"); 
}


$dbuser  = ''; // your database server user name
$dbhost  = 'localhost'; // name of the sql server
$dbpass  = ''; // your database server password
$dbname  = 'weld'; // the name of the database to connect to

// use a compare statement to check for duplicates

$sqlCOMPARE = "SELECT * from prodname where '$ProdName' = proddesc;";


// the sql query to insert data into the prodname table


$sqlINSERT = "INSERT into prodname values
  (null, '$Manufacturer', '$ProdType', '$ProdName', '$ProdNar', '$ProdEquiv');";

$sqlINSERT = strtoupper($sqlINSERT);

//use to display the desired data $sqlSELECT


$sqlSELECT = "SELECT MANNAME, prodtype, proddesc, prodnar, prodequiv
FROM man, produse, prodname where manno = manid  
and prodid = useid
                and manno = MANID
and proddesc = '$ProdName'
order by MANNAME;";




// mysql_connect connects to the database server and returns a link to the the resource
$dblink = @mysql_connect("$dbhost","$dbuser","$dbpass")
or die("<p><b>Could not connect to database server: ($dbhost)</b></p>\n");

// mysql_select_db selects a database to use on the database server pointers to by $dblink
// the @ sign before the command supresses any error messages
@mysql_select_db ($dbname , $dblink)
or die ("<p><b>Could not connect to database ($dbname)</b></p>\n");


// now execute the next query to determine if a duplicate has been entered and use
// an if statement to return the user to the entry page if this is true


$result  = mysql_query($sqlCOMPARE, $dblink)
or die("<p>Error Processing Query</p><hr /><p>".mysql_error()."</p>\n");


if (  mysql_num_rows($result) < 0  ){ 
header("Location: addprod.php"); 
die ("opps"); 

}

// now execute the next query to update the database table


$result  = mysql_query($sqlINSERT, $dblink)
or die("<p>Error Processing Query mickey</p><hr /><p>".mysql_error()."</p>\n");

// now execute the next query to display these results

$result  = mysql_query($sqlSELECT, $dblink)
or die("<p>Error Processing Query</p><hr /><p>".mysql_error()."</p>\n");

?>
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.