Update Command Again

From: Date: Wed, 02 Aug 2000 17:43:00 +0000
Subject: Update Command Again
Groups: php.general 
Request: Send a blank email to php-general+get-9757@lists.php.net to get a copy of this message
Ok I am really getting frustrated with this update project. I have a MYSQL table with the following characteristics: Monday - Saturday and Name = VarChar(25) Number = Int (unsigned) I have to different scripts to update the database. One retrevies all the information I want to keep the same (Name and Number). The script looks like this: // Define local variable for SQL entry $host = "localhost"; $username = "username"; $password = "password"; $database = "database"; $table = "table"; MYSQL_CONNECT ($host, $username, $password) or DIE ("Unable to open database"); @mysql_select_db("$database") or DIE ("Unable to select database"); $count_field = 0; $count = 0; $result = MYSQL_QUERY ("SELECT*FROM $table"); $rows = MYSQL_NUMROWS($result); $row_count = 0; while ($row_count < $rows) { $Name = mysql_result ($result, $row_count, "Name"); $Num = mysql_result ($result, $row_count, "Number"); echo "<tr>"; echo "<td>" , $Name; echo "<td>" , $Num , "<input type=\"hidden\" name=\"num[", $count_field , "]\" value=\"" ,$Num , "\">" ; echo "<td><input type=\"text\" size=\"8\" name=\"mon[" , $count_field , "]\">"; echo "<td><input type=\"text\" size=\"8\" name=\"tues[" , $count_field , "]\">"; echo "<td><input type=\"text\" size=\"8\" name=\"wed[" , $count_field , "]\">"; echo "<td><input type=\"text\" size=\"8\" name=\"thur[" , $count_field , "]\">"; echo "<td><input type=\"text\" size=\"8\" name=\"fri[" , $count_field , "]\">"; echo "<td><input type=\"text\" size=\"8\" name=\"sat[" , $count_field , "]\">"; $row_count++; // Increment all variables $count_field++; } echo "<input type=\"hidden\" name=\"i\" value=\"" , $count_field , "\">"; MYSQL_CLOSE(); ?> This script is where I put all my fill in all the fields I want to change. The next script actually does the updating. It takes all the fields I have entered and uses the update command to update the stuff I have put in. It looks like this: <?php // Update the entries made into the previous form // Define all MYSQL Variables $host = "localhost"; $username = "username"; $password = "password"; $database = "database"; $table = "table"; // Conect to the database MYSQL_CONNECT ($host) or DIE ("Unable to connect to databse"); @mysql_select_db("$database") or DIE ("Unable to select database"); // Set all counters to 0 for flag pruposes $count = 0; while ($count < $i) { // Get all the values out of the arrays just in case they cause a problem $mond = $mon[$count]; $tuesd = $tues[$count]; $wedd = $wed[$count]; $thurd = $thur[$count]; $frid = $fri[$count]; $satd = $sat[$count]; $numb = $num[$count]; $query = "UPDATE $table SET Monday = '$mond', Tuesday = '$tuesd' , Wednesday = '$wedd' , Thursday = '$thurd' , Friday = '$frid' , Saturday = '$satd' WHERE Number = $numb"; MYSQL_QUERY ($query); // Echo query to see if it sent the command in the right format echo $query; // Update Counters $count++; } MYSQL_CLOSE (); ?> If you have made it through this question thank you for you time so far. Any suggestions on why this would not be working? Nashirak

« previous php.general (#9757) next »