Hello everybody! I need some help from you (the experts)! :-)

I have a form that shows information on a particular student based 
on a numeric value in the field studentno (student number). The form 
fields are editable. The student may have multiple transactions 
which could show when the student's transaction history is viewed. 
When I click my "Update Record(s)" button, I get results, though the 
query overwrites all of that student's records with the first record 
for that student.

I can't seem to figure out how to make my UPDATE query update 
multiple records for the student's particular studentno. Rather, my 
query takes only the value of the first record, and duplicates that 
information for the first record, and the remainder of that 
student's records. I really stink at arrays, loops, etc. I don't 
really understand them that well, although I have tried to study 
them. It's the syntax and logic that always gets me in a bind.


To give you an example of what's happening, 

If the first record for the student already looks like this in the 
database before I make any updates to it...

Record Number 1 > (Record Number is not an actual field)

Date: 8/17/2006
Item Description: DEPOSIT
Cost of Items: $0.00
Item Quantity: N/A
Deposits: $20.00


Then, when I submit the form (assuming I just made some changes), 

This...

Record Number 2

Date: 8/17/2006
Item Description: A LA CARTE 3.00
Cost of Items: $3.00
Item Quantity: 1
Deposits: N/A

Record Number 3

Date: 8/17/2006
Item Description: A LA CARTE 4.00
Cost of Items: $4.00
Item Quantity: 1
Deposits: N/A

Record Number 4

Date: 8/17/2006
Item Description: A LA CARTE 1.50
Cost of Items: $1.50
Item Quantity: 1
Deposits: N/A


Becomes These...

Record Number 2

Date: 8/17/2006
Item Description: DEPOSIT
Cost of Items: $0.00
Item Quantity: N/A
Deposits: $20.00

Record Number 3

Date: 8/17/2006
Item Description: DEPOSIT
Cost of Items: $0.00
Item Quantity: N/A
Deposits: $20.00

Record Number 4

Date: 8/17/2006
Item Description: DEPOSIT
Cost of Items: $0.00
Item Quantity: N/A
Deposits: $20.00

etc, etc.


Please help! Much thanks in advance for your help! Deadline for this 
program is Tuesday of next week. Working code is appreciated!

Here's what I have so far...

<?PHP

        echo "<form name=\"form\" method=\"POST\" 
action=\"$PHP_SELF\" enctype=\"multipart/form-data\">";


        $studentno = $_GET['studentno'];
        $query = "SELECT * FROM ctkdata WHERE studentno 
= '$studentno'";
        $result = mysql_query($query) or die ("Could Not Select User 
Records!");
        $nrows = mysql_num_rows($result);

        while ($row = mysql_fetch_array($result))
        {
        extract($row);
        echo "Deposit: <input type=\"text\" name=\"deposit\" 
value=\"$deposit\" size=\"8\"></ BR>";
        echo "Description: <input type=\"text\" name=\"description\" 
value=\"$description\" size=\"25\"></ BR>";
        echo "Cost: <input type=\"text\" name=\"cost\" 
value=\"$cost\" size=\"8\"></ BR>";
        echo "Quantity: <input type=\"text\" name=\"qty\" 
value=\"$qty\" size=\"8\"></ BR>";
        echo "<input type=\"submit\" name=\"update\" value=\"Update 
Record(s)\">";
        }
        echo "</ form>";


        if(isset($_POST['update']))
        {
        //If the Submit button was pressed, do the following:
        $deposit = addslashes($_POST['deposit']);
        $description = addslashes($_POST['description']);
        $cost = addslashes($_POST['cost']);
        $qty = addslashes($_POST['qty']);
        $dateposted = date("n/j/Y");

        $updatequery = "UPDATE ctkdata SET
                        deposit='$deposit',
                        description='$description',
                        cost='$cost',
                        qty='$qty',
                        dateposted='$dateposted'
                        WHERE studentno = '$studentno'";

        $updateresults = mysql_query($updatequery)
          or die ("Could Not Execute Update Query!");
        echo "<script language='javascript'>";
        echo "location.href='$PHP_SELF?studentno=$studentno'";
        echo "</script>";
        }
?>





The php_mysql group is dedicated to learn more about the PHP/MySQL web database 
possibilities through group learning.  
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php_mysql/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to