Sctipt to modify records


I’m learning PHP by problem solving and I’m up against another problem. I want the user to enter a ID number which will display all records in a DB assigned to that ID. That part is working fine. The problem is that I’m getting all the records with a submit button under each record and it’s not updating. Is the problem in this code or in my form processing script? I would like it to display all records in the table and be able to modify any of those and click submit and have all records updated. Thank you very much for taking a look and leading me in the right direction

//$results variable = the results of the query
$results = mysql_query($sql)
	or die ("Stopped at the mysql_query");

while($row = mysql_fetch_array($results));

$sql1=mysql_query("SELECT sid FROM volunteer WHERE sid='$sid'");

if (mysql_num_rows($sql1)==0 || mysql_num_rows($sql1)<1)
{ die ("Sorry, the ID you submitted is not present in our database.  Please hit your browser's back button and reenter your student's ID.");


while ($i < $num) {

<form action="volchanged.php" method="post">
<table border='1'>
<th>Student ID</th>
<th>Person Working</th>
<th>March 1st</th>
<th>March 2nd</th>
<th>March 15th</th>
<th>March 16th</th>
<th>April 5th</th>
<th>April 10th</th>
<th>April 11th</th>
<td><input type="text" name="ud_sid" value="<? echo "$sid"?>"></td>
<td><input type="text" name="ud_wperson" value="<? echo "$wperson"?>"></td>
<td><input type="text" name="ud_student" value="<? echo "$student"?>"></td>
<td><input type="text" name="ud_hours1" value="<? echo "$hours1"?>"></td>
<td><input type="text" name="ud_hours2" value="<? echo "$hours2"?>"></td>
<td><input type="text" name="ud_hours3" value="<? echo "$hours3"?>"></td>
<td><input type="text" name="ud_hours4" value="<? echo "$hours4"?>"></td>
<td><input type="text" name="ud_hours5 value="<? echo "$hours5"?>"></td>
<td><input type="text" name="ud_hours6" value="<? echo "$hours6"?>"></td></tr>
<input type="Submit" value="Submit">



Not sure if your question is that you have a submit under each record or why when you press a submit it’s not working.

If it’s the multiple submit buttons, it’s because you have the inside your while loop.

If it’s the later, I can tell you that your Submit button is not unique to a record, and thus, each submit button will do exactly the same thing (and is therefore very redundant).

Also are you getting any error messages?

Thanks for your response.

What I would like is for all entries associated with one idea record to be displayed and able to be edited but with one submit button if that’s possible. No, I didn’t get any error messages.

First of all move the OUTSIDE of your WHILE. I would even take it a step further and don’t create a “Separate” FORM and TABLE for each element. Create ONE table and ONE form.

This is actually part of your problem. Because EACH element for every record has the same Tags and variable names (from the input tags) and they are all posting to the same document. You are not sure WHICH ud_hours# you are using for which ud_sid. (Does that make sense?)

For example
You might have for
ud_sid = 1
ud_wperson = “Joe”
ud_student = “Joe Smith”
ud_hours1 = 5
ud_hours2 = 4
ud_hours3 = 5
ud_hours4 = 2

but for
You might have for
ud_sid = 2
ud_wperson = “Bob”
ud_student = “Bob Jones”
ud_hours1 = 6
ud_hours2 = 2
ud_hours3 = 4
ud_hours4 = 1

When you submit it (to volchanged.php), it uses the names of ud_student, ud_hours1, ud_hours2, etc… . Only ONE of the values would be submitted.

You need to give the input fields like <input type=“text” name=“ud_student” value="<? echo "$student"?>"> a UNIQUE name more like
<input type=“text” name=“ud_student1” value="<? echo "$student"?>"> and
<input type=“text” name=“ud_student2” value="<? echo "$student"?>"> , etc…

In fact you could even use the ID (from your database assuming it’s unique) to help label the fields.

<input type=“text” name=“ud_student<? echo $id; ?> " value=”<? echo "$student"?>">

That way you get to your script to update it, you know the fields are unique, and based on the ID, you will know which fields to look for.

(Hope that makes sense)

First, thank you kindly for your well thought out response. I truly appreciate your time.

If I’m understanding you correctly, you’re saying to use the primary key (the entry number $id) as the identifier. The problem with that is that the student id number is the only identifying number that people will know. They will enter their child’s student id number that will pull up all records associated with it. Are you saying to pull up individual records rather than pulling all records associated with a student ID? If not, I’m not understanding correctly. By putting the submit button outside the loop, will that UPDATE all records (regardless of a change to the field or not) in the table when sent to the form processing script? If so, that would work fine. I will try it when I get up the courage to risk blowing up my database. :)

Again, thank you very much for your time.

Sponsor our Newsletter | Privacy Policy | Terms of Service