PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Wed Nov 26, 2014 1:21 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Feb 14, 2012 8:13 pm 
Offline
Forum Newbie

Joined: Wed Sep 28, 2011 4:01 am
Posts: 13
hi i need help the about my code. i can get the form to post three row in my database but not all the values are being posted. the problem is when i post the form only one is posted in the three different row that is the recipid only but what i want to happen is for the recipid, title and message will be posted in three different row but also the output depends on what the user inputed so not all the three rows has the same output

here is my code:
<?php
if($dn1['recipid']!=$_SESSION['username'])
{

$id = $dn1['npm']+1;

foreach($_POST['id'] as $dn1['recipid']){
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","SECOND","SECOND")'))
{
?>
<div class="message">The Grade has been successfully sent to the Student.

<a href="list_grade.php">List of my Grades</a></div>
<?php
$form = false;
}
else
{
$error = 'An error occurred while sending the message';
}
}
}
else
{
$error = 'You cannot send a grade to yourself/fellow instructors.';
}
?>


<h1>Post Grade</h1>
<h1>IT, Fourth Year</h1>

Please fill the following form to send The Grade


<?
$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 '<input type="hidden" id="id" name="id[]" value="' . $row['id'] . '" />';
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[]" />
';

}
if($row1 = mysql_fetch_array($re7)){
echo '<input type="hidden" id="id" name="id[]" value="' . $row1['id'] . '" />';
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[]" />
';

}
if($row2 = mysql_fetch_array($re8)){
echo '<input type="hidden" id="id" name="id[]" value="' . $row2['id'] . '" />';
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[]" />
';

}
?>

help is needed :( :(


Top
 Profile  
 
PostPosted: Wed Feb 15, 2012 4:58 am 
Offline
Forum Newbie

Joined: Sun Feb 12, 2012 11:33 pm
Posts: 24
Try this:
Syntax: [ Download ] [ Hide ]
<?php

var_dump($_POST);

?>

<form action="" method="post">

<input type="hidden" id="id" name="test[1][id]" value="ID1" /><br />
Recipient<span class="small">(Username)</span><input type="text" value="Username1" id="recip" name="test[1][recip]" readonly="readonly"/><br />
Subject<input type="text" value="SUBJECT1" id="title" name="test[1][title]" /><br />
<input type="hidden" id="year" name="test[1][year]" value="YEAR1" />
<input type="hidden" id="sem" name="test[1][sem]" value="SEM1" />
<input type="text" id="message" name="test[1][message]" value="MESSAGE1" />

<input type="hidden" id="id" name="test[2][id]" value="ID2" /><br />
Recipient<span class="small">(Username)</span><input type="text" value="Username2" id="recip" name="test[2][recip]" readonly="readonly"/><br />
Subject<input type="text" value="SUBJECT2" id="title" name="test[2][title]" /><br />
<input type="hidden" id="year" name="test[2][year]" value="YEAR2" />
<input type="hidden" id="sem" name="test[2][sem]" value="SEM2" />
<input type="text" id="message" name="test[2][message]" value="MESSAGE2" />

<input type="submit" value="Send..." />

</form>


Top
 Profile  
 
PostPosted: Wed Feb 15, 2012 5:43 pm 
Offline
Forum Newbie

Joined: Wed Sep 28, 2011 4:01 am
Posts: 13
hi i still cant get it to post in my database but this time the recip only post array on three rows...need help pls


Top
 Profile  
 
PostPosted: Wed Feb 15, 2012 6:13 pm 
Offline
Forum Newbie

Joined: Sun Feb 12, 2012 11:33 pm
Posts: 24
I still don't get what you are trying to do...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group