Jump to content

double entry


witham

Recommended Posts

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
https://forums.phpfreaks.com/topic/16951-double-entry/#findComment-71399
Share on other sites

Archived

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

×
×
  • 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.