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:

('$_POST[Teacher]','$_POST[sid]','$_POST[Student]','$_POST[Date]','$_POST[Tardy]','$_POST[Comment]','$_POST[Absent]','$_POST[Inhouse]','$_POST[Suspension]','$_POST[Allpresent]')";

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:

('$_POST[Teacher]','$sid,'$student','$_POST[Date]','$_POST[Tardy]','$_POST[Comment]','$_POST[Absent]','$_POST[Inhouse]','$_POST[Suspension]','$_POST[Allpresent]')";

With the code above, this is what's submitted to MYsql:
sid column and Student columns are blank.

Here is the complete action code:

<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

Where do you set the variable $tardy in your code?

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

I have the correct code on my computer, but doesn't work properly as noted above.

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...

Here's the form code (to-web.php):

<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's the action code (incoming.php):

<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..

It didn't make a difference.

<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

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..

Ok, I'll try that.
Thanks for taking the time to look at it.

Mike

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.