User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Nov 2007
Posts: 13
Reputation: jaydude23 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
jaydude23 jaydude23 is offline Offline
Newbie Poster

Question PHP problem!

  #1  
Nov 2nd, 2007
  1. <HTML>
  2. <?php
  3. 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))
  4. {echo "<h2>Please make sure you have filled in all required fields. Please use your browsers Back button</h2>\n";
  5. echo "<h2>******REQUEST WAS NOT SUBMITTED******</h2>\n";}
  6. if (isset ($_POST['chk8'])) {
  7. $req1 = "Pre Band Mailer\n";
  8. } else {
  9. $req1 = "None\n";
  10. }
  11. if (isset ($_POST['chk9'])) {
  12. $req2 = "At Brand Mailer\n";
  13. } else {
  14. $req2 = "None\n";
  15. }
  16. if (isset ($_POST['chk10'])) {
  17. $req3 = "Welcome Kit\n";
  18. } else {
  19. $req3 = "None\n";
  20. }
  21. if (isset ($_POST['chk11'])) {
  22. $req4 = "Three Product Welcome Kit -1\n";
  23. } else {
  24. $req4 = "None\n";
  25. }
  26. if (isset ($_POST['chk12'])) {
  27. $req5 = "Three Product Welcome Kit -2\n";
  28. } else {
  29. $req5 = "None\n";
  30. }
  31. if (isset ($_POST['chk13'])) {
  32. $req6 = "...\n";
  33. } else {
  34. $req6 = "None\n";
  35. }
  36. if (isset ($_POST['chk14'])) {
  37. $req7 = "...\n";
  38. } else {
  39. $req7 = "None\n";
  40. }
  41. $ShipTo_Address = stripcslashes($ShipTo_Address);
  42. $Additional_Info = stripcslashes($Additional_Info);
  43. ?>
  44. <?php
  45. $usr = "national_twc";
  46. $pwd = "timewarnercable";
  47. $db = "national_test";
  48. $host = "localhost";
  49. $cid = mysql_connect($host,$usr,$pwd);
  50. if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); }
  51. if ($REQUEST_METHOD=="POST") {
  52. if mysql_query("SELECT * FROM test WHERE Account_No = '$Account_No'"){
  53. echo ("<center><h1>Sorry. Your account is already added.</h1></center>\n");
  54. } else {
  55. $SQL = " INSERT INTO twc ";
  56. $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 ";
  57. $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') ";
  58. $result = mysql_db_query($db,"$SQL",$cid);
  59. }
  60. if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); }
  61. echo ("<center><h1>Thank You.</h1></center>\n");
  62. echo ("<center>Please use back button to go back.</center>\n");
  63. }
  64. mysql_close($cid);
  65. ?>
  66. </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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2007
Location: Budapest
Posts: 252
Reputation: fatihpiristine has a little shameless behaviour in the past 
Rep Power: 0
Solved Threads: 14
fatihpiristine's Avatar
fatihpiristine fatihpiristine is offline Offline
Posting Whiz in Training

Re: PHP problem!

  #2  
Nov 2nd, 2007
this is integer right? then u cannot assign integer as text

change this :
Account_No = '$Account_No'"
to this:
Account_No = $Account_No"

it ll work
Do a favour, leave me alone
Reply With Quote  
Join Date: Sep 2007
Location: Buenos Aires
Posts: 30
Reputation: chmazur is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
chmazur's Avatar
chmazur chmazur is offline Offline
Light Poster

Re: PHP problem!

  #3  
Nov 2nd, 2007
I wil try with:
if mysql_query("SELECT * FROM test WHERE Account_No = ".$Account_No)

If it don`t work.
Try with:
if mysql_query("sql", $cid)

ch.-
Last edited by cscgal : Nov 3rd, 2007 at 11:31 pm. Reason: Fake sig snipped
Reply With Quote  
Join Date: Nov 2007
Posts: 13
Reputation: jaydude23 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
jaydude23 jaydude23 is offline Offline
Newbie Poster

Question Re: PHP problem!

  #4  
Nov 2nd, 2007
  1. <HTML>
  2. <?php
  3. 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))
  4. {echo "<h2>Please make sure you have filled in all required fields. Please use your browsers Back button</h2>\n";
  5. echo "<h2>******REQUEST WAS NOT SUBMITTED******</h2>\n";}
  6. if (isset ($_POST['chk8'])) {
  7. $req1 = "Pre Band Mailer\n";
  8. } else {
  9. $req1 = "None\n";
  10. }
  11. if (isset ($_POST['chk9'])) {
  12. $req2 = "At Brand Mailer\n";
  13. } else {
  14. $req2 = "None\n";
  15. }
  16. if (isset ($_POST['chk10'])) {
  17. $req3 = "Voice Welcome Kit\n";
  18. } else {
  19. $req3 = "None\n";
  20. }
  21. if (isset ($_POST['chk11'])) {
  22. $req4 = "Welcome Kit (Scientific Atlanta)\n";
  23. } else {
  24. $req4 = "None\n";
  25. }
  26. if (isset ($_POST['chk12'])) {
  27. $req5 = "Three Product Welcome Kit (Motorola)\n";
  28. } else {
  29. $req5 = "None\n";
  30. }
  31. if (isset ($_POST['chk13'])) {
  32. $req6 = "...\n";
  33. } else {
  34. $req6 = "None\n";
  35. }
  36. if (isset ($_POST['chk14'])) {
  37. $req7 = "...\n";
  38. } else {
  39. $req7 = "None\n";
  40. }
  41. $ShipTo_Address = stripcslashes($ShipTo_Address);
  42. $Additional_Info = stripcslashes($Additional_Info);
  43. ?>
  44. <?php
  45. $usr = "national_twc";
  46. $pwd = "timewarnercable";
  47. $db = "national_test";
  48. $host = "localhost";
  49. $cid = mysql_connect($host,$usr,$pwd);
  50. if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); }
  51. if ($REQUEST_METHOD=="POST") {
  52. if (mysql_query("SELECT * FROM twc WHERE Account_No = $Account_No")) {
  53. echo ("<center><h1>Sorry. Your account is already added.</h1></center>\n");
  54. } else {
  55. $SQL = " INSERT INTO twc ";
  56. $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 ";
  57. $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') ";
  58. $result = mysql_db_query($db,"$SQL",$cid);
  59. }
  60. if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); }
  61. echo ("<center><h1>Thank You.</h1></center>\n");
  62. echo ("<center>Please use back button to go back.</center>\n");
  63. }
  64. mysql_close($cid);
  65. ?>
  66. </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
Reply With Quote  
Join Date: Sep 2007
Location: Budapest
Posts: 252
Reputation: fatihpiristine has a little shameless behaviour in the past 
Rep Power: 0
Solved Threads: 14
fatihpiristine's Avatar
fatihpiristine fatihpiristine is offline Offline
Posting Whiz in Training

Re: PHP problem!

  #5  
Nov 2nd, 2007
you get empty record or you get full data you entered into fields. ??
Do a favour, leave me alone
Reply With Quote  
Join Date: Nov 2007
Posts: 13
Reputation: jaydude23 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
jaydude23 jaydude23 is offline Offline
Newbie Poster

Re: PHP problem!

  #6  
Nov 2nd, 2007
I get a record entered with data each time. It does not check to see if the account number exists before adding it to the db.

Thanks

Jason
Reply With Quote  
Join Date: Sep 2007
Location: Buenos Aires
Posts: 30
Reputation: chmazur is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
chmazur's Avatar
chmazur chmazur is offline Offline
Light Poster

Re: PHP problem!

  #7  
Nov 2nd, 2007
On line 52, you are not select the DB yet.

mysql_select_db($db);

ch.-
Last edited by cscgal : Nov 3rd, 2007 at 11:30 pm. Reason: Fake signature removed: use signatures in member profiles
Reply With Quote  
Join Date: Sep 2007
Location: Budapest
Posts: 252
Reputation: fatihpiristine has a little shameless behaviour in the past 
Rep Power: 0
Solved Threads: 14
fatihpiristine's Avatar
fatihpiristine fatihpiristine is offline Offline
Posting Whiz in Training

Re: PHP problem!

  #8  
Nov 3rd, 2007
dump your table into text document n zip it with this page n upload here.. i ll check it...
Do a favour, leave me alone
Reply With Quote  
Join Date: Aug 2006
Posts: 32
Reputation: StatiX is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
StatiX's Avatar
StatiX StatiX is offline Offline
Light Poster

Re: PHP problem!

  #9  
Nov 3rd, 2007
Starting from line 52:
  1.  
  2. $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM `twc` WHERE `Account_No` = ".$Account_No),0) or die(mysql_error());
  3.  
  4. if ($total_results > 0) {
  5. // if one or more rows are returned an account with this id exists
  6. echo ("<center><h1>Sorry. Your account is already added.</h1></center>\n");
  7.  
  8. } else {
  9. //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..
Reply With Quote  
Join Date: Nov 2007
Posts: 13
Reputation: jaydude23 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
jaydude23 jaydude23 is offline Offline
Newbie Poster

Question Re: PHP problem!

  #10  
Nov 5th, 2007
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.

  1. <HTML>
  2. <?php
  3. 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))
  4. {echo "<h2>Please make sure you have filled in all required fields. Please use your browsers Back button</h2>\n";
  5. echo "<h2>******REQUEST WAS NOT SUBMITTED******</h2>\n";}
  6. if (isset ($_POST['chk8'])) {
  7. $req1 = "Pre Band Mailer\n";
  8. } else {
  9. $req1 = "None\n";
  10. }
  11. if (isset ($_POST['chk9'])) {
  12. $req2 = "At Brand Mailer\n";
  13. } else {
  14. $req2 = "None\n";
  15. }
  16. if (isset ($_POST['chk10'])) {
  17. $req3 = "Comcast Digital Voice Welcome Kit\n";
  18. } else {
  19. $req3 = "None\n";
  20. }
  21. if (isset ($_POST['chk11'])) {
  22. $req4 = "Three Product Welcome Kit (Scientific Atlanta)\n";
  23. } else {
  24. $req4 = "None\n";
  25. }
  26. if (isset ($_POST['chk12'])) {
  27. $req5 = "Three Product Welcome Kit (Motorola)\n";
  28. } else {
  29. $req5 = "None\n";
  30. }
  31. if (isset ($_POST['chk13'])) {
  32. $req6 = "...\n";
  33. } else {
  34. $req6 = "None\n";
  35. }
  36. if (isset ($_POST['chk14'])) {
  37. $req7 = "...\n";
  38. } else {
  39. $req7 = "None\n";
  40. }
  41. $ShipTo_Address = stripcslashes($ShipTo_Address);
  42. $Additional_Info = stripcslashes($Additional_Info);
  43. ?>
  44. <?php
  45. $usr = "national_twc";
  46. $pwd = "timewarnercable";
  47. $db = "national_test";
  48. $host = "localhost";
  49. $cid = mysql_connect($host,$usr,$pwd);
  50. if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); }
  51. if ($REQUEST_METHOD=="POST") {
  52. mysql_select_db($db);
  53. $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM `twc` WHERE `Account_No` = ".$Account_No),0) or die(mysql_error());
  54. if ($total_results > 0) {
  55. // if one or more rows are returned an account with this id exists
  56. echo ("<center><h1>Sorry. Your account is already added.</h1></center>\n");
  57. } else {
  58. //no rows were returned so we can add data
  59. $SQL = " INSERT INTO twc ";
  60. $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 ";
  61. $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') ";
  62. $result = mysql_db_query($db,"$SQL",$cid);
  63. }
  64. if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); }
  65. echo ("<center><h1>Thank You.</h1></center>\n");
  66. echo ("<center>Please use back button to go back.</center>\n");
  67. }
  68. mysql_close($cid);
  69. ?>
  70. </HTML>
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 6:39 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC