•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,588 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,574 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 929 | Replies: 11
![]() |
•
•
Join Date: Nov 2007
Posts: 13
Reputation:
Rep Power: 2
Solved Threads: 0
php Syntax (Toggle Plain Text)
<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
•
•
Join Date: Nov 2007
Posts: 13
Reputation:
Rep Power: 2
Solved Threads: 0
php Syntax (Toggle Plain Text)
<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 = "Voice Welcome Kit\n"; } else { $req3 = "None\n"; } if (isset ($_POST['chk11'])) { $req4 = "Welcome Kit (Scientific Atlanta)\n"; } else { $req4 = "None\n"; } if (isset ($_POST['chk12'])) { $req5 = "Three Product Welcome Kit (Motorola)\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 twc 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>
Thanks for your help. I've believe I've changed what you told me to correctly. I'm posting my code again for you to double check me and point me in the right direction.
It seems its passing the check and the error message, and just adding the record to the db. Am I missing something? Please help me.
Thanks again
Jason
Starting from line 52:
First you need to query the db and see if you get a result from the query. I'm not sure but the best I can remember the way it was would be true as the query would return true even if no rows matched your terms. You may also want to check to make sure that the Account_No variable is being processed correctly and passed correctly, this most likely where your problem lies as without this var being correct you will never get a correct query and all data would be added like your talking about. For testing you could
php Syntax (Toggle Plain Text)
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM `twc` WHERE `Account_No` = ".$Account_No),0) or die(mysql_error()); if ($total_results > 0) { // if one or more rows are returned an account with this id exists echo ("<center><h1>Sorry. Your account is already added.</h1></center>\n"); } else { //no rows were returned so we can add data
First you need to query the db and see if you get a result from the query. I'm not sure but the best I can remember the way it was would be true as the query would return true even if no rows matched your terms. You may also want to check to make sure that the Account_No variable is being processed correctly and passed correctly, this most likely where your problem lies as without this var being correct you will never get a correct query and all data would be added like your talking about. For testing you could
echo $Account_No; just before its used in the query Last edited by StatiX : Nov 3rd, 2007 at 11:13 pm.
Always do what you wish you could..
•
•
Join Date: Nov 2007
Posts: 13
Reputation:
Rep Power: 2
Solved Threads: 0
okay, I think I'm making head way with this little project. Thanks to all of you who have helped and guided me. I do appreciate it.
I have changed and update my code to include selecting the db and the SELECT statement.
Now when I execute it, I receive the following error:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\Accounts\national\wwwRoot\new_datain.php on line 53
Access denied for user: 'national_twc@localhost' to database 'national_test'
I'll post my updated code here for you to review.
Once again thanks for all your help! I'll look forward to hearing from anyone.
I have changed and update my code to include selecting the db and the SELECT statement.
Now when I execute it, I receive the following error:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\Accounts\national\wwwRoot\new_datain.php on line 53
Access denied for user: 'national_twc@localhost' to database 'national_test'
I'll post my updated code here for you to review.
Once again thanks for all your help! I'll look forward to hearing from anyone.
php Syntax (Toggle Plain Text)
<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 = "Comcast Digital Voice Welcome Kit\n"; } else { $req3 = "None\n"; } if (isset ($_POST['chk11'])) { $req4 = "Three Product Welcome Kit (Scientific Atlanta)\n"; } else { $req4 = "None\n"; } if (isset ($_POST['chk12'])) { $req5 = "Three Product Welcome Kit (Motorola)\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") { mysql_select_db($db); $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM `twc` WHERE `Account_No` = ".$Account_No),0) or die(mysql_error()); if ($total_results > 0) { // if one or more rows are returned an account with this id exists echo ("<center><h1>Sorry. Your account is already added.</h1></center>\n"); } else { //no rows were returned so we can add data $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>
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- PHP Problem, not sure what's causing. (PHP)
- php and mod_rewrite problem (PHP)
- PHP problem - register page (PHP)
- Learning PHP but problem with script (PHP)
- emails sent to bulk folder....(Is this a php problem?) (PHP)
- Large Array Problem (PHP)
Other Threads in the PHP Forum
- Previous Thread: PHP Content Management System from scratch
- Next Thread: php file export issue


Linear Mode