Jump to content

Recommended Posts

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();
?>

Link to comment
https://forums.phpfreaks.com/topic/242090-my-update-statement-doesnt-update/
Share on other sites

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?

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.