harlequeen Posted July 15, 2011 Share Posted July 15, 2011 Hi I have a form which passes 3 values x 14 instances to a processing page. I am getting the arrays of the variables and am able to echo to screen to check that the pairs of values that I want are there. This all works OK. Then I have an update statement which should go to the sprcified table, update the column with the values from the arrays where the condition is met. However, it just isn't updating. I don't get an error message unless there is a problem in the code (I set one to check it, then took it out). My code is below, could someone please look and tell me if they can see the problem. I connect to my database by calling a connect file, which is correct as it is getting the information for the form page correctly. I'm going cross eyed looking at it now. Any help would be appreciated. <?php //database connection include'myconnect.php'; //Receiving information from form in teaminputtest.php $team_id[]=$_GET['team_id']; $teamName[]=$_GET['teamName']; $Points[]=$_GET['Points']; //Looping through each item in the array to get the info foreach ($_GET['team_id'] as $row=>$name) { //Looping through each item in the array to get the info $team_id = $name; $teamName = $_GET['teamName'][$row]; $Points = $_GET['Points'][$row]; //printing each item to the screen echo "$name "; echo"$teamName "; echo "$Points<br>"; }// end for each loop // Count how many teams there are in the division $size=count($_GET['team_id']); echo "$size <br>"; //Set the counter to zero, then loop through while the counter is less than the count figure $i=0; while ($i < $size) { //Call the information from the GET strings passed from previous page. $team_id=$_GET['team_id'] [$i]; $Points=$_GET['Points'] [$i]; //Update the database $query="UPDATE teams SET Points = '$Points' WHERE team_id = '$team_id' "; //If there is an erro, let me know mysql_query($query) or die ("Error in query: $query"); //echo to screen the team ID Number echo "$team_id "; //echo to screen the Points allocated print "$Points <br/><br/><em>Updated!</em><br/><br/>"; ++$i; }//end while loop mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/242090-my-update-statement-doesnt-update/ Share on other sites More sharing options...
mikesta707 Posted July 15, 2011 Share Posted July 15, 2011 What happens exactly? Is the loop never entered? do you see the print "$Points <br/><br/><em>Updated!</em><br/><br/>"; line being output for every iteration through the loop? Can you post the form that is submitting to this page? Quote Link to comment https://forums.phpfreaks.com/topic/242090-my-update-statement-doesnt-update/#findComment-1243274 Share on other sites More sharing options...
harlequeen Posted July 15, 2011 Author Share Posted July 15, 2011 Hi Yes, I see the "$Points <br/><br/><em>Updated!</em><br/><br/>"; line being printed for every iteration. Here is the code for the form, but I don't think it can be that as I'm able to echo the values I want as part of the while loop <?php //database connection include'myconnect.php'; $sql=mysql_query("SELECT teams.teamName, teams.team_id, contacts.division FROM teams LEFT JOIN contacts ON teams.teamName = contacts.teamName WHERE contacts.division=4 "); while(@$row=mysql_fetch_array($sql)) { //Form generated from database calling teams identified by Division number in query above. ?> <table width="30%" align="center" border="1"> <form name="inputpoints" method="GET" action="checkresults3.php"> <tr> <td width=40%> <input type="char" name='team_id[]'size="2" value=" <? echo $row['team_id'];?>"></td><td> <input type="text" name='teamName[]' size="36" value=" <? echo $row['teamName']; ?>"></td> <td> <SELECT name='Points[]'> <OPTION value=1>1</OPTION> <OPTION value=2>2</OPTION> <OPTION value=3>3</OPTION> <OPTION value=4>4</OPTION> <OPTION value=5>5</OPTION> <OPTION value=6>6</OPTION> <OPTION value=7>7</OPTION> <OPTION value=0>0</OPTION><?php echo $row['Points'];?>"> </select> </td> <?php } ?> <input type="submit" value="submit" action="submit"> </table> </form> <?php When I go into phpMyAdmin and put a similar statement in there( to check the syntax) it updates - although it is only 1 entry. Regards H Quote Link to comment https://forums.phpfreaks.com/topic/242090-my-update-statement-doesnt-update/#findComment-1243288 Share on other sites More sharing options...
PFMaBiSmAd Posted July 15, 2011 Share Posted July 15, 2011 In your previous thread on this, someone mentioned the spaces (they show up as + characters in the submitted URL) in the submitted data values and that you should find and eliminate the cause of them. Your $team_id values have a space in front of each of them and since you are comparing them to the team_id column as as string in the query (surrounded by single-quotes), they don't match the values in your team_id column - WHERE team_id = '$team_id' "; In the value="space..." attributes in your form, you have a space after the initial ", that is adding a space before each value. Quote Link to comment https://forums.phpfreaks.com/topic/242090-my-update-statement-doesnt-update/#findComment-1243293 Share on other sites More sharing options...
harlequeen Posted July 15, 2011 Author Share Posted July 15, 2011 HI Yes, that fixed it. I didn't realise that it was a problem because I was able to echo out the values. Thanks for that, you've been a great help. Cheers Harlequeen Quote Link to comment https://forums.phpfreaks.com/topic/242090-my-update-statement-doesnt-update/#findComment-1243296 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.