Explode and Post doesn't seem to work together

Reply

Join Date: Oct 2008
Posts: 6
Reputation: mikeabe is an unknown quantity at this point 
Solved Threads: 0
mikeabe mikeabe is offline Offline
Newbie Poster

Explode and Post doesn't seem to work together

 
0
  #1
Dec 12th, 2008
Hi
(In my php form, i'm getting a bunch of data to Mysql, all of which is working correctly except id and name. id and name are fed from Mysql to the form.)

Here's the problem area:

I'm getting an id AND name from a dropdown menu using EXPLODE.

With this code, all columns are fed correctly to Mysql EXCEPT sid and Student:
  1. ('$_POST[Teacher]','$_POST[sid]','$_POST[Student]','$_POST[Date]','$_POST[Tardy]','$_POST[Comment]','$_POST[Absent]','$_POST[Inhouse]','$_POST[Suspension]','$_POST[Allpresent]')";
  2.  
With the code above, this is what's submitted to MYsql:
sid column is blank. Student column has id AND Student with pipe inbetween (ex: 468|Grundy Joe)




When i use this code:
  1. ('$_POST[Teacher]','$sid,'$student','$_POST[Date]','$_POST[Tardy]','$_POST[Comment]','$_POST[Absent]','$_POST[Inhouse]','$_POST[Suspension]','$_POST[Allpresent]')";
  2.  
With the code above, this is what's submitted to MYsql:
sid column and Student columns are blank.





Here is the complete action code:
  1. <html><a href="http://10.49.5.99/">Home </a><br><br>
  2. <BODY BGCOLOR="EED6AF">
  3. </html>
  4.  
  5. <?php
  6. $con = mysql_connect("localhost","root","");
  7. if (!$con)
  8. {
  9. die('Could not connect: ' . mysql_error());
  10. }
  11. mysql_select_db("DisciplineIncoming", $con);
  12.  
  13. $part = explode("|", $_POST['student']);
  14. // $part[0] is now client_id// $part[1] is now name
  15. $sid=$part[0];
  16. $student=$part[1];
  17.  
  18.  
  19.  
  20. $sql="INSERT INTO incoming (Teacher, sid, Student, Date, Tardy, Comment, Absent, Inhouse, Suspension, Allpresent)
  21. VALUES
  22.  
  23.  
  24. ('$_POST[Teacher]','$sid','$tardy','$_POST[Date]','$_POST[Tardy]','$_POST[Comment]','$_POST[Absent]','$_POST[Inhouse]'
  25.  
  26. ,'$_POST[Suspension]','$_POST[Allpresent]')";
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. if (!mysql_query($sql,$con))
  36. {
  37. die('Error: ' . mysql_error());
  38. }
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. echo "<h3>Thanks!
  48. <br><br>Your input is now recorded on the master discipline/tardy spreadsheet.
  49. <br><br>Click the Back arrow if you need to input data for another student.
  50. <br><br>If you're finished, you can close this window.";
  51.  
  52. mysql_close($con)
  53. ?>


Can anybody see where i goofed up the code?

Thanks, Mike
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 141
Reputation: robothy is an unknown quantity at this point 
Solved Threads: 19
robothy robothy is offline Offline
Junior Poster

Re: Explode and Post doesn't seem to work together

 
0
  #2
Dec 12th, 2008
Where do you set the variable $tardy in your code?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 6
Reputation: mikeabe is an unknown quantity at this point 
Solved Threads: 0
mikeabe mikeabe is offline Offline
Newbie Poster

Re: Explode and Post doesn't seem to work together

 
0
  #3
Dec 12th, 2008
OH JEEZE, I had to leave and didn't have time to check it.
I'm sorry.
&tardy should be $student.

I'm such a dummy
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 6
Reputation: mikeabe is an unknown quantity at this point 
Solved Threads: 0
mikeabe mikeabe is offline Offline
Newbie Poster

Re: Explode and Post doesn't seem to work together

 
0
  #4
Dec 12th, 2008
I have the correct code on my computer, but doesn't work properly as noted above.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 94
Reputation: sikka_varun is an unknown quantity at this point 
Solved Threads: 11
sikka_varun's Avatar
sikka_varun sikka_varun is offline Offline
Junior Poster in Training

Re: Explode and Post doesn't seem to work together

 
0
  #5
Dec 12th, 2008
Hii...
post your complete code.. also your main html code in here.... coz it will give us more clear idea about how the thing is working...
VâRûN
---Happy to Help---
sikka_varun@yahoo.com
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 6
Reputation: mikeabe is an unknown quantity at this point 
Solved Threads: 0
mikeabe mikeabe is offline Offline
Newbie Poster

Re: Explode and Post doesn't seem to work together

 
0
  #6
Dec 12th, 2008
Here's the form code (to-web.php):
  1. <html>
  2. <body>
  3. <a href="http://10.49.5.99/">Home </a>
  4. <BODY BGCOLOR="EED6AF">
  5. <h2><FONT COLOR="#FF0000">Discipline-Praise-Tardy-Absence-Form</FONT></h2>
  6.  
  7. <b>Click in the Teacher name field and choose your name</b>
  8. </body>
  9. </html>
  10. <form action="incoming.php" method="post">
  11. <?php
  12. $dbhost = 'localhost';
  13. $dbuser = 'root';
  14. $dbpass = '';
  15. $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error
  16. connecting to mysql');
  17. $dbname = 'teacher';
  18. mysql_select_db($dbname);
  19. /*LOADS TEACHER NAMES*/
  20. $query="SELECT tnames FROM tchnames ORDER BY tnames ASC";
  21. $result = mysql_query ($query);
  22. echo "<select name=Teacher>";
  23. // printing the list box select command
  24. while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
  25. echo "<option value='$nt[tnames]'>$nt[tnames]</option>";
  26. /* Option values are added by looping through the array */
  27. }
  28. echo "</select>";// Closing of list box
  29. ?>
  30. <html>
  31. <body>
  32. <br><br><br>
  33. <b>Click in the Student name field and choose student</b>
  34. <br>
  35. </body>
  36. </html>
  37. <?php
  38. $dbhost = 'localhost';
  39. $dbuser = 'root';
  40. $dbpass = '';
  41. $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error
  42. connecting to mysql');
  43. $dbname = 'student';
  44. mysql_select_db($dbname);
  45.  
  46.  
  47.  
  48.  
  49. //*LOADS STUDENT NAMES*/
  50. $query="SELECT sid, snames FROM studnames ORDER BY snames ASC";
  51. /* You can add order by clause to the sql statement if the names are to be displayed in
  52. alphabetical order */
  53. $result = mysql_query ($query);
  54. echo "<select name=Student>";
  55. // printing the list box select command
  56. while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
  57.  
  58.  
  59.  
  60. echo '<option value="'.$nt[sid].'|'.$nt[snames].'">' .$nt['snames'].'</option>';
  61.  
  62.  
  63. /* Option values are added by looping through the array */
  64. }
  65. echo "</select>";// Closing of list box
  66. ?>
  67. <html><body>
  68. <br><br><br>
  69. <b>You can change today's date to another date <FONT COLOR="#FF0000">IF</FONT> you need to.<b>
  70. <br>
  71. <b>Date :</b>
  72. <input type="text" name="Date" value="<?php echo date("Y-m-d"); ?>" />
  73. <br><br>
  74. <b>Tardy:</b><input type="checkbox" name="Tardy" value = "1" /> &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
  75. <b>Absent</b><input type="checkbox" name="Absent" value = "yes" />&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
  76. <b>All Present:</b><input type="checkbox" name="Allpresent" value = "yes" /> &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
  77. <br><br>
  78. <b>comment:</b>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp&nbsp<input type="submit" VALUE = "Click Here to Submit This Form"
  79. <br>
  80. <textarea rows="7" cols="60" name="Comment" wrap="physical"></textarea><br>
  81. </form>
  82. </body>
  83. </html>
  84.  




Here's the action code (incoming.php):
  1. <html><a href="http://10.49.5.99/">Home </a><br><br>
  2. <BODY BGCOLOR="EED6AF">
  3. </html>
  4.  
  5. <?php
  6. $con = mysql_connect("localhost","root","");
  7. if (!$con)
  8. {
  9. die('Could not connect: ' . mysql_error());
  10. }
  11. mysql_select_db("DisciplineIncoming", $con);
  12.  
  13.  
  14.  
  15.  
  16. $sql="INSERT INTO incoming (Teacher, sid, Student, Date, Tardy, Comment, Absent, Inhouse, Suspension, Allpresent)
  17. VALUES
  18.  
  19.  
  20. ('$_POST[Teacher]','$sid','$student','$_POST[Date]','$_POST[Tardy]','$_POST[Comment]','$_POST[Absent]','$_POST[Inhouse]'
  21.  
  22. ,'$_POST[Suspension]','$_POST[Allpresent]')";
  23.  
  24.  
  25. $part = explode("|", $_POST['student']);
  26. // $part[0] is now client_id// $part[1] is now name
  27. $sid=$part[0];
  28. $student=$part[1];
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. if (!mysql_query($sql,$con))
  36. {
  37. die('Error: ' . mysql_error());
  38. }
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. echo "<h3>Thanks!
  48. <br><br>Your input is now recorded on the master discipline/tardy spreadsheet.
  49. <br><br>Click the Back arrow if you need to input data for another student.
  50. <br><br>If you're finished, you can close this window.";
  51.  
  52. mysql_close($con)
  53. ?>


Thanks, Mike
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 94
Reputation: sikka_varun is an unknown quantity at this point 
Solved Threads: 11
sikka_varun's Avatar
sikka_varun sikka_varun is offline Offline
Junior Poster in Training

Re: Explode and Post doesn't seem to work together

 
0
  #7
Dec 12th, 2008
Hey.. in incoming.php file...
make sure that the explode is not called after the insert query..
Because in the code you pasted above.. it seems to be that explode is called after the $sid and $student are assigned to query..

put explode and $sid=$part[0]..... statement before $sql insert query statement...
Then check again..
VâRûN
---Happy to Help---
sikka_varun@yahoo.com
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 6
Reputation: mikeabe is an unknown quantity at this point 
Solved Threads: 0
mikeabe mikeabe is offline Offline
Newbie Poster

Re: Explode and Post doesn't seem to work together

 
0
  #8
Dec 12th, 2008
It didn't make a difference.

  1. <html><a href="http://10.49.5.99/">Home </a><br><br>
  2. <BODY BGCOLOR="EED6AF">
  3. </html>
  4.  
  5. <?php
  6. $con = mysql_connect("localhost","root","");
  7. if (!$con)
  8. {
  9. die('Could not connect: ' . mysql_error());
  10. }
  11. mysql_select_db("DisciplineIncoming", $con);
  12.  
  13.  
  14. $part = explode("|", $_POST['student']);
  15. // $part[0] is now client_id// $part[1] is now name
  16. $sid=$part[0];
  17. $student=$part[1];
  18.  
  19.  
  20.  
  21. $sql="INSERT INTO incoming (Teacher, sid, Student, Date, Tardy, Comment, Absent, Inhouse, Suspension, Allpresent)
  22. VALUES
  23.  
  24.  
  25. ('$_POST[Teacher]','$sid','$','$student','$_POST[Date]','$_POST[Tardy]','$_POST[Comment]','$_POST[Absent]','$_POST[Inhouse]'
  26.  
  27. ,'$_POST[Suspension]','$_POST[Allpresent]')";
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37. if (!mysql_query($sql,$con))
  38. {
  39. die('Error: ' . mysql_error());
  40. }
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. echo "<h3>Thanks!
  50. <br><br>Your input is now recorded on the master discipline/tardy spreadsheet.
  51. <br><br>Click the Back arrow if you need to input data for another student.
  52. <br><br>If you're finished, you can close this window.";
  53.  
  54. mysql_close($con)
  55. ?>

I made another database and forms to debug with.

and when i use ($sid','$','$student',) by themselves, it posts id and student to Mysql, just like it's supposed to:




Thanks, Mike
Last edited by mikeabe; Dec 12th, 2008 at 1:44 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 94
Reputation: sikka_varun is an unknown quantity at this point 
Solved Threads: 11
sikka_varun's Avatar
sikka_varun sikka_varun is offline Offline
Junior Poster in Training

Re: Explode and Post doesn't seem to work together

 
0
  #9
Dec 14th, 2008
Hi..
tried to find out the error in your code... i could not find any problem... if possible try to debug your code by using stub variables to display the intermediate values... so that you will know till wt point the values are coming correctly.. and you might reach to the trouble point in this way..
VâRûN
---Happy to Help---
sikka_varun@yahoo.com
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 6
Reputation: mikeabe is an unknown quantity at this point 
Solved Threads: 0
mikeabe mikeabe is offline Offline
Newbie Poster

Re: Explode and Post doesn't seem to work together

 
0
  #10
Dec 14th, 2008
Ok, I'll try that.
Thanks for taking the time to look at it.

Mike
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC