witham Posted August 8, 2006 Share Posted August 8, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/16951-double-entry/ Share on other sites More sharing options...
tomfmason Posted August 8, 2006 Share Posted August 8, 2006 Just post the relivant portion of your code. Quote Link to comment https://forums.phpfreaks.com/topic/16951-double-entry/#findComment-71390 Share on other sites More sharing options...
brown2005 Posted August 8, 2006 Share Posted August 8, 2006 please post the code u use to enter the items in with Quote Link to comment https://forums.phpfreaks.com/topic/16951-double-entry/#findComment-71391 Share on other sites More sharing options...
witham Posted August 8, 2006 Author Share Posted August 8, 2006 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 outputif (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");?> Quote Link to comment https://forums.phpfreaks.com/topic/16951-double-entry/#findComment-71399 Share on other sites More sharing options...
corbin Posted August 8, 2006 Share Posted August 8, 2006 $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 Quote Link to comment https://forums.phpfreaks.com/topic/16951-double-entry/#findComment-71408 Share on other sites More sharing options...
sasa Posted August 8, 2006 Share Posted August 8, 2006 change line[code]if ( mysql_num_rows($result) < 0 ){ [/code]to[code]if ( mysql_num_rows($result) > 0 ){ [/code] Quote Link to comment https://forums.phpfreaks.com/topic/16951-double-entry/#findComment-71467 Share on other sites More sharing options...
witham Posted August 9, 2006 Author Share Posted August 9, 2006 Sorted thank you very much sometimes a fresh set of eyes see far clearer. thanks again Quote Link to comment https://forums.phpfreaks.com/topic/16951-double-entry/#findComment-71932 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.