| | |
Explode and Post doesn't seem to work together
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2008
Posts: 6
Reputation:
Solved Threads: 0
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:
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:
With the code above, this is what's submitted to MYsql:
sid column and Student columns are blank.
Here is the complete action code:
Can anybody see where i goofed up the code?
Thanks, Mike
(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:
PHP Syntax (Toggle Plain Text)
('$_POST[Teacher]','$_POST[sid]','$_POST[Student]','$_POST[Date]','$_POST[Tardy]','$_POST[Comment]','$_POST[Absent]','$_POST[Inhouse]','$_POST[Suspension]','$_POST[Allpresent]')";
sid column is blank. Student column has id AND Student with pipe inbetween (ex: 468|Grundy Joe)
When i use this code:
PHP Syntax (Toggle Plain Text)
('$_POST[Teacher]','$sid,'$student','$_POST[Date]','$_POST[Tardy]','$_POST[Comment]','$_POST[Absent]','$_POST[Inhouse]','$_POST[Suspension]','$_POST[Allpresent]')";
sid column and Student columns are blank.
Here is the complete action code:
PHP Syntax (Toggle Plain Text)
<html><a href="http://10.49.5.99/">Home </a><br><br> <BODY BGCOLOR="EED6AF"> </html> <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("DisciplineIncoming", $con); $part = explode("|", $_POST['student']); // $part[0] is now client_id// $part[1] is now name $sid=$part[0]; $student=$part[1]; $sql="INSERT INTO incoming (Teacher, sid, Student, Date, Tardy, Comment, Absent, Inhouse, Suspension, Allpresent) VALUES ('$_POST[Teacher]','$sid','$tardy','$_POST[Date]','$_POST[Tardy]','$_POST[Comment]','$_POST[Absent]','$_POST[Inhouse]' ,'$_POST[Suspension]','$_POST[Allpresent]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "<h3>Thanks! <br><br>Your input is now recorded on the master discipline/tardy spreadsheet. <br><br>Click the Back arrow if you need to input data for another student. <br><br>If you're finished, you can close this window."; mysql_close($con) ?>
Can anybody see where i goofed up the code?
Thanks, Mike
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...
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...
•
•
Join Date: Oct 2008
Posts: 6
Reputation:
Solved Threads: 0
Here's the form code (to-web.php):
Here's the action code (incoming.php):
Thanks, Mike
PHP Syntax (Toggle Plain Text)
<html> <body> <a href="http://10.49.5.99/">Home </a> <BODY BGCOLOR="EED6AF"> <h2><FONT COLOR="#FF0000">Discipline-Praise-Tardy-Absence-Form</FONT></h2> <b>Click in the Teacher name field and choose your name</b> </body> </html> <form action="incoming.php" method="post"> <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'teacher'; mysql_select_db($dbname); /*LOADS TEACHER NAMES*/ $query="SELECT tnames FROM tchnames ORDER BY tnames ASC"; $result = mysql_query ($query); echo "<select name=Teacher>"; // printing the list box select command while($nt=mysql_fetch_array($result)){//Array or records stored in $nt echo "<option value='$nt[tnames]'>$nt[tnames]</option>"; /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box ?> <html> <body> <br><br><br> <b>Click in the Student name field and choose student</b> <br> </body> </html> <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'student'; mysql_select_db($dbname); //*LOADS STUDENT NAMES*/ $query="SELECT sid, snames FROM studnames ORDER BY snames ASC"; /* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */ $result = mysql_query ($query); echo "<select name=Student>"; // printing the list box select command while($nt=mysql_fetch_array($result)){//Array or records stored in $nt echo '<option value="'.$nt[sid].'|'.$nt[snames].'">' .$nt['snames'].'</option>'; /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box ?> <html><body> <br><br><br> <b>You can change today's date to another date <FONT COLOR="#FF0000">IF</FONT> you need to.<b> <br> <b>Date :</b> <input type="text" name="Date" value="<?php echo date("Y-m-d"); ?>" /> <br><br> <b>Tardy:</b><input type="checkbox" name="Tardy" value = "1" />               <b>Absent</b><input type="checkbox" name="Absent" value = "yes" />              <b>All Present:</b><input type="checkbox" name="Allpresent" value = "yes" />               <br><br> <b>comment:</b>                                                          <input type="submit" VALUE = "Click Here to Submit This Form" <br> <textarea rows="7" cols="60" name="Comment" wrap="physical"></textarea><br> </form> </body> </html>
Here's the action code (incoming.php):
PHP Syntax (Toggle Plain Text)
<html><a href="http://10.49.5.99/">Home </a><br><br> <BODY BGCOLOR="EED6AF"> </html> <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("DisciplineIncoming", $con); $sql="INSERT INTO incoming (Teacher, sid, Student, Date, Tardy, Comment, Absent, Inhouse, Suspension, Allpresent) VALUES ('$_POST[Teacher]','$sid','$student','$_POST[Date]','$_POST[Tardy]','$_POST[Comment]','$_POST[Absent]','$_POST[Inhouse]' ,'$_POST[Suspension]','$_POST[Allpresent]')"; $part = explode("|", $_POST['student']); // $part[0] is now client_id// $part[1] is now name $sid=$part[0]; $student=$part[1]; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "<h3>Thanks! <br><br>Your input is now recorded on the master discipline/tardy spreadsheet. <br><br>Click the Back arrow if you need to input data for another student. <br><br>If you're finished, you can close this window."; mysql_close($con) ?>
Thanks, Mike
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..
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..
•
•
Join Date: Oct 2008
Posts: 6
Reputation:
Solved Threads: 0
It didn't make a difference.
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
PHP Syntax (Toggle Plain Text)
<html><a href="http://10.49.5.99/">Home </a><br><br> <BODY BGCOLOR="EED6AF"> </html> <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("DisciplineIncoming", $con); $part = explode("|", $_POST['student']); // $part[0] is now client_id// $part[1] is now name $sid=$part[0]; $student=$part[1]; $sql="INSERT INTO incoming (Teacher, sid, Student, Date, Tardy, Comment, Absent, Inhouse, Suspension, Allpresent) VALUES ('$_POST[Teacher]','$sid','$','$student','$_POST[Date]','$_POST[Tardy]','$_POST[Comment]','$_POST[Absent]','$_POST[Inhouse]' ,'$_POST[Suspension]','$_POST[Allpresent]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "<h3>Thanks! <br><br>Your input is now recorded on the master discipline/tardy spreadsheet. <br><br>Click the Back arrow if you need to input data for another student. <br><br>If you're finished, you can close this window."; mysql_close($con) ?>
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.
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..
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..
![]() |
Similar Threads
- how to explode records? (PHP)
- [Revised] vBulletin Mod_rewrite Tutorial (PHP)
- Search Script help (PHP)
- Internet Explorer Running SLOW (Web Browsers)
- Form not sending email (PHP)
- Can php allow me to create whatever.homepage.com address (PHP)
Other Threads in the PHP Forum
- Previous Thread: Headers already written.
- Next Thread: Getting MP3 metadata
| Thread Tools | Search this Thread |
apache api array beginner binary body broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions global google href htaccess html image include insert ip javascript joomla limit link list login mail mediawiki menu mlm msqli_multi_query multiple mycodeisbad mysql number oop parameter paypal pdf php phpincludeissue problem query radio random recourse recursion regex remote script search seo server sessions sms source sp space speed sql static subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign white wordpress xml youtube





