Jump to content

Archived

This topic is now archived and is closed to further replies.

witham

double entry

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

Share this post


Link to post
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");

?>

Share this post


Link to post
Share on other sites
$sqlCOMPARE  = "SELECT * from prodname where `ProdName` = '$ProdName'";

Wrong sentax on that line...  And I'm not sure bout the rest of the script... Just woke up :D

Share this post


Link to post
Share on other sites
change line[code]if (  mysql_num_rows($result) < 0  ){ [/code]to[code]if (  mysql_num_rows($result) > 0  ){ [/code]

Share this post


Link to post
Share on other sites
Sorted thank you very much sometimes a fresh set of eyes see far clearer. thanks again

Share this post


Link to post
Share on other sites

×

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.