Jump to content

EXPLODE combined with POST doesn't seem to work


mikeabe

Recommended Posts

Hi

I'm trying to get the sid and Student columns posted correctly to Mysql using a combination of POST and EXPLODE. (All the columns other than sid and Student are working well.) (The student name drop down in the form is poplulated from Mysql)

 

 

 

When I use this code snippet:

('$_POST[Teacher]','$_POST[sid]','$_POST[student]','$_POST[Date]','$_POST[Tardy]','$_POST[Comment]','$_POST[Absent]','$_POST[inhouse]','$_POST[s

uspension]','$_POST[Allpresent]')";

I get this result in Mysql (the sid column is blank, the Student column has sid|name):

 

id  |Teacher |sid|      Student      |    Date    |Tardy |  Comment |  Absent |  Inhouse  |  Suspension |  Allpresent  |

78  |Abraham|    | 13|Ackerman Joe|2008-12-12|    1  |    hello    |  yes    |    yes      |        yes    |      yes      |   

 

 

 

When I use this code snippet:

('$_POST[Teacher]','$sid','$student','$_POST[Date]','$_POST[Tardy]','$_POST[Comment]','$_POST[Absent]','$_POST[inhouse]','$_POST[s

uspension]','$_POST[Allpresent]')";

I get this result in Mysql: (sid and Student are blank)

 

id  |Teacher |sid|      Student      |    Date    |Tardy |  Comment |  Absent |  Inhouse  |  Suspension |  Allpresent  |

78  |Abraham|    |                        |2008-12-12|    1  |    hello    |  yes    |    yes      |        yes    |      yes      |   

 

 

 

 

 

 

Here is the complete code for the form: (notice this line of code under LOADS STUDENT NAMES,

echo '<option value="'.$nt[sid].'|'.$nt[snames].'">' .$nt['snames'].'</option>';

  Used to get both the student id and name sent to Mysql.

<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" /> &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp    
<b>Absent</b><input type="checkbox" name="Absent" value = "yes" />&nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp
<b>All Present:</b><input type="checkbox" name="Allpresent" value = "yes" /> &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  
<br><br>
<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"
<br>
<textarea rows="7" cols="60" name="Comment" wrap="physical"></textarea><br>
</form>
</body>
</html>

 

 

 

 

Here is the complete code for the action page: Notice the explode part used to separate sid from Student.

<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[s

uspension]','$_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)
?>

 

Any help you could give me would be greatly appreciated. I'm so close to putting it to use at my school .

Thanks, Mike

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.