Jump to content


Photo

double entry


  • Please log in to reply
6 replies to this topic

#1 witham

witham
  • Members
  • PipPipPip
  • Advanced Member
  • 86 posts

Posted 08 August 2006 - 08:45 PM

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

#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 08 August 2006 - 08:49 PM

Just post the relivant portion of your code.

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 08 August 2006 - 08:50 PM

please post the code u use to enter the items in with

#4 witham

witham
  • Members
  • PipPipPip
  • Advanced Member
  • 86 posts

Posted 08 August 2006 - 08:59 PM

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");

?>

#5 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 08 August 2006 - 09:05 PM

$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
Why doesn't anyone ever say hi, hey, or whad up world?

#6 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 08 August 2006 - 10:45 PM

change line
if (  mysql_num_rows($result) < 0  ){
to
if (  mysql_num_rows($result) > 0  ){


#7 witham

witham
  • Members
  • PipPipPip
  • Advanced Member
  • 86 posts

Posted 09 August 2006 - 05:49 PM

Sorted thank you very much sometimes a fresh set of eyes see far clearer. thanks again




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users