Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
updating data in a database
Old 05-05-2009, 08:02 AM updating data in a database
Junior Talker

Posts: 3
Trades: 0
Here's what i basically want to do :

A user, in this case a teacher, by selecting an appropriate option to be able to update data concerning his students absencies reports.

Here's what my table for the students' absencies looks like (nevermind the greek)




And here's what my browser shows up (yes thats in greek too but you'll get the idea):



Here's my code :

Quote:
if ($teacherclass=="e") // if teacher selects the EDIT option from a dropdown menu
{
include ("config.php"); // just plain connecting to the database
$con=mysql_connect($dbhost,$dbuser,$dbpass)
or die("Cannot connect to database");
mysql_select_db('dbusers');
mysql_query("set names utf8;"); //


echo "<br>Your class is :";

$myclass= $_SESSION['myclass']['class']; // That's a session started when the user logged in with his class.

echo $myclass; //e.g. B1
echo "<br>";
echo "<br>";


$query = "SELECT * FROM absencies WHERE class = '$myclass' " ; //shows all students that are in the same class as the teacher/user is
$result = mysql_query($query);



while ($row= mysql_fetch_array($result)){


echo "<table width=800 border=1 cellpading=1>
<tr>
<td><b>Real name:</b></td>
<td>".$row['realname']."</td>

</tr>
<tr>
<td> Unjustified absecnies of Year 1 , Semester 1 :</td>
<td>".$row['A1a']."</td>
<td>

<form action='absencies.php' method='POST' accept-charset='UTF-8'>

<input type='hidden' name='submitted' value=1>

<input type='text' name='A1a'>
<input type='submit' name='submit' value='Edit'></td>

</tr>
<tr>
<td>Justified absencies of Year 1, Semester 1 :</td>
<td>". $row['A1d']."</td>
<td><input type='text' name='A1d'><input type='submit' name='submit' value='Edit'></td>
</tr>
<tr>
<td>unjustified absencies of Year 1, semester 2:</td>
<td>".$row['A2a']."</td>
<td><input type='text' name='A2a'><input type='submit' name='submit' value='Edit'></td>
</tr>
<tr>
<td>Justified absencies of Year 1 , semester 2:</td>
<td>".$row['A2d']."</td>
<td><input type='text' name='A2d'><input type='submit' name='submit' value='Edit'></td>
</tr>



etc. for all semesters


...

</table>





if ($_POST['submitted']==1) {

// THIS WHERE I SHOULD enterMY queries *update" etc.


}



}
}
jeanmarat1793 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-05-2009, 08:39 AM Re: updating data in a database
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
...
And your problem is !???
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 05-05-2009, 08:59 AM Re: updating data in a database
Junior Talker

Posts: 3
Trades: 0
My problem IS HOW TO UPDATE the fields withouf UPDATING all of them but one at a time.

Ok I used the loop to show the students status however i dont want to get a loop updating every single student. But just the one i choose.

Thanks
jeanmarat1793 is offline
Reply With Quote
View Public Profile
 
Old 05-05-2009, 09:13 AM Re: updating data in a database
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Then you need to tell the db which row you want to update:
Code:
update tblStudents
set field1='x', field2='y', field3='z'
where studentId='$student_being_edited'
So, you design a screen where the teacher can edit each fields.
When the page is acessed, you get the student id from the url, do a SELECT query to load it's values, and display them in each fields of the page form.

When the teacher click the submit button, your target page extract the values from the POST (with the student id), and send the UPDATE query like up there.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 05-05-2009, 05:35 PM Re: updating data in a database
Junior Talker

Posts: 3
Trades: 0
Thanks !!!
jeanmarat1793 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to updating data in a database
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15046 seconds with 12 queries