PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
if(mysql_query('insert into post_grade (id, id2, title, user1, user2, message, timestamp, user1read, user2read,Year,Sem)values("'.$id.'", "1", "'.$title.'", "'.$_SESSION['userid'].'", "'.$dn1['recipid'].'", "'.$message.'", "'.time().'", "yes", "no","'.$year.'","'.$sem.'")'))
{
$re6 = mysql_query('select username from users where course = "BSIT" and yearlevel = "FOURTH"');
?>
<br />
<h1>Post Grade</h1>
<h1>IT, Fourth Year</h1>
<br />Please fill the following form to send The Grade<br />
<?
while($row = mysql_fetch_assoc($re6))
{
echo'<form action="grade_post.php" method="post">';
echo'Recipient<span class="small">(Username)</span><input type="text" value="'.$row['username'].'" readonly="readonly" id="recip" name="recip" />';
echo'Subject<input type="text" value="'.htmlentities($otitle, ENT_QUOTES, 'UTF-8').'" id="title" name="title" />';
echo'<input type="hidden" value="FOURTH" id="year" name="year" />';
echo'<input type="hidden" value="FIRST" id="sem" name="sem" />';
echo'Grade<input type="text" id="message" name="message" ><br />';
}
}
?>
i get all my recipients in every input type, but when i tried to post it in my database not all of them are posted rather only one of them are posted in my database ...what i want to happen is that all of my recipients in every input type will be posted in my database with different ids'...help pls...
hi i'm sorry but i still get the same errors but this time my grades and names dont appear and i still get one id...
this is my whole code...
i appreciate the help...tnks
im sorry i used your code but i still get the errors...i just posted my codes before i use yours just to show if i have errors in my whole codes...i hope you can check my whole codes and correct it with yours...i need your help pls...tnk u
That's not really an error. That's just the program doing exactly what you told it to do. Try my code and when you receive the post variables the will all be arrays.
hi...im sorry again but i still got nothing on my database...i still cant get my form to submit the data i need on my database the only thing i get on my database is the id and there is only one...im sorry i hope you will not get tired on helping me..pls thank you
So, did you try the code I posted? It shows what data is returned by the form. Then add the database code to build the $rows array -- and see what the data looks like. Finally, build SQL INSERT statements from the data.
hi im sorry it took me so long i hope you will still help me...finally i got my code to post many id's that i needed on my database but the problem is not all my data is posted in my dtababse only the id and the recip is posted plus the id's that o got is all the same...when i tried to post 3 different items...i got on my dtabase is a 3 row with only the recip posted with the same id's
here is my code hope you can help me again:
<?
foreach($_POST['recip'] as $value)
{
$id = $dn1['npm']+1;
if(mysql_query('insert into post_grade (id, id2, title, user1, user2, message, timestamp, user1read, user2read,Year,Sem)values("'.$id.'", "1", "'.$title.'", "'.$_SESSION['userid'].'", "'.$dn1['recipid'].'", "'.$message.'", "'.time().'", "yes", "no","'.$year.'","'.$sem.'")'))
{
?>
<div class="message">The Grade has been successfully sent to the Student.<br />
<a href="list_grade.php">List of my Grades</a></div>
<?php
$form = false;
}
else
{
$error = 'An error occurred while sending the message';
}
}
$re6 = mysql_query('select username, id from users where course = "BSIT" and yearlevel = "SECOND" order by id limit 1');
$re7 = mysql_query('select username, id from users where course = "BSIT" and yearlevel = "SECOND" order by id limit 1,1');
$re8 = mysql_query('select username, id from users where course = "BSIT" and yearlevel = "SECOND" order by id limit 2,1');
echo'<form action="grade_post.php" method="post">';
if($row = mysql_fetch_array($re6)){
echo 'Recipient<span class="small">(Username)</span><input type="text" value="'.$row['username'].'" id="recip" name="recip[]" readonly="readonly"/>';
echo 'Subject<input type="text" value=" '.htmlentities($otitle, ENT_QUOTES, 'UTF-8').' " id="title" name="title[]" />';
echo '<input type="hidden" id="year" name="year[]" value="SECOND" />';
echo '<input type="hidden" id="sem" name="sem[]" value="SECOND" />';
echo 'Grade<input type="text" id="message" name="message[]" /><br />';
}
if($row1 = mysql_fetch_array($re7)){
echo 'Recipient<span class="small">(Username)</span><input type="text" value="'.$row1['username'].'" id="recip" name="recip[]" readonly="readonly"/>';
echo 'Subject<input type="text" value=" '.htmlentities($otitle, ENT_QUOTES, 'UTF-8').' " id="title" name="title[]" />';
echo '<input type="hidden" id="year" name="year[]" value="SECOND" />';
echo '<input type="hidden" id="sem" name="sem[]" value="SECOND" />';
echo 'Grade<input type="text" id="message" name="message[]" /><br />';
}
if($row2 = mysql_fetch_array($re8)){
echo 'Recipient<span class="small">(Username)</span><input type="text" value="'.$row2['username'].'" id="recip" name="recip[]" readonly="readonly"/>';
echo 'Subject<input type="text" value=" '.htmlentities($otitle, ENT_QUOTES, 'UTF-8').' " id="title" name="title[]" />';
echo '<input type="hidden" id="year" name="year[]" value="SECOND" />';
echo '<input type="hidden" id="sem" name="sem[]" value="SECOND" />';
echo 'Grade<input type="text" id="message" name="message[]" /><br />';
}
echo '<input type="submit" value="Send" id="up" name="up"/>';
echo '</form>';
?>