<HTML>
<?php
if (empty($CSP_Name) || empty($Supervisor) || empty($Rep_Number) || empty($Department) || empty($Account_No) || empty($First_Name) || empty($Last_Name) || empty($Phone) || empty($ShipTo_Address) || empty($ShipTo_City) || empty($ShipTo_State) || empty($ShipTo_ZIP) || empty($Accept))
{echo "<h2>Please make sure you have filled in all required fields. Please use your browsers Back button</h2>\n";
echo "<h2>******REQUEST WAS NOT SUBMITTED******</h2>\n";}
if (isset ($_POST['chk8'])) {
$req1 = "Pre Band Mailer\n";
} else {
$req1 = "None\n";
}
if (isset ($_POST['chk9'])) {
$req2 = "At Brand Mailer\n";
} else {
$req2 = "None\n";
}
if (isset ($_POST['chk10'])) {
$req3 = "Welcome Kit\n";
} else {
$req3 = "None\n";
}
if (isset ($_POST['chk11'])) {
$req4 = "Three Product Welcome Kit -1\n";
} else {
$req4 = "None\n";
}
if (isset ($_POST['chk12'])) {
$req5 = "Three Product Welcome Kit -2\n";
} else {
$req5 = "None\n";
}
if (isset ($_POST['chk13'])) {
$req6 = "...\n";
} else {
$req6 = "None\n";
}
if (isset ($_POST['chk14'])) {
$req7 = "...\n";
} else {
$req7 = "None\n";
}
$ShipTo_Address = stripcslashes($ShipTo_Address);
$Additional_Info = stripcslashes($Additional_Info);
?>
<?php
$usr = "national_twc";
$pwd = "timewarnercable";
$db = "national_test";
$host = "localhost";
$cid = mysql_connect($host,$usr,$pwd);
if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); }
if ($REQUEST_METHOD=="POST") {
if mysql_query("SELECT * FROM test WHERE Account_No = '$Account_No'"){
echo ("<center><h1>Sorry. Your account is already added.</h1></center>\n");
} else {
$SQL = " INSERT INTO twc ";
$SQL = $SQL . " (DATE, CSP_Name, Supervisor, Rep_Number, Department, Email, req1, req2, req3, req4, req5, req6, req7, Account_No, First_Name, Last_Name, Phone, ShipTo_Address, ShipTo_City, ShipTo_State, ShipTo_ZIP, Additional_Info, Accept) VALUES ";
$SQL = $SQL . " (now(), '$CSP_Name', '$Supervisor', '$Rep_Number', '$Department', '$Email', '$req1', '$req2', '$req3', '$req4', '$req5', '$req6', '$req7', '$Account_No', '$First_Name', '$Last_Name', '$Phone', '$ShipTo_Address', '$ShipTo_City', '$ShipTo_State', '$ShipTo_ZIP', '$Additional_Info', '$Accept') ";
$result = mysql_db_query($db,"$SQL",$cid);
}
if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); }
echo ("<center><h1>Thank You.</h1></center>\n");
echo ("<center>Please use back button to go back.</center>\n");
}
mysql_close($cid);
?>
</HTML>
Our company does fullfillment requests for a client, and this is the script that places the data into the mysql table from the form they fill out.
What I'm trying to add is a way to check the db before adding the record to prevent duplicate records being submitted to the db.
I've got the code in there, but it seems to fail at:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Accounts\national\wwwRoot\test\new_datain.php on line 52
I'm not sure what is wrong. Perhaps a syntax error. I'm new to php and mysql.
Thanks for any help you can provide me.
- jason