php update query syntax check

please see attached snippet.
if I run the update statement replacing variable names with values in phpmyadmin, the update is successful.

when  i run this php (through flash form) it shows the success message but update doesn't actually occur.

I'm not getting any syntax errors running this through the browser either and the update works.

http://127.0.0.1/employeeSoccer/admin/editGame.php?newGameName=bob&newStartDate=2010-06-01&newEndDate=2010-06-31&newTurnsPerDay=3&newActiveState=0&newNumAttempts=4&editGameID=73 

i've checked the values being sent from flash and they're correct.
i've tried various configurations of strings, not strings.





$newGameName = $_REQUEST['newGameName'];
        $newStartDate = $_REQUEST['newStartDate'];
		$newEndDate = $_REQUEST['newEndDate'];
		$newTurnsPerDay = $_REQUEST['newTurnsPerDay'];
		$newActiveState = $_REQUEST['newActiveState'];
		$newNumAttempts = $_REQUEST['newNumAttempts'];
		$editGameID = $_REQUEST['editGameID'];
		
	    $result = mysql_query("UPDATE gamedetails SET gameName = '".$newGameName."', startDate = '".$newStartDate."', endDate = '".$newEndDate."', turnsPerDay = '".$newTurnsPerDay."', numAttempts = '".$newNumAttempts."', isActive = '".$newActiveState."' WHERE gameID = '$editGameID='");

               echo '<?xml version="1.0"?>';
               echo '<dataxml>';
               if ($result){
			  	 	echo '<row type="success">';
            		 echo '<result>success</result>';  
					 echo '</row>';
                } else {
					echo '<row type="error">';
                    echo '<error>no results</error>';  
					echo '</row>';
                }
                echo '</dataxml>';

Open in new window

LVL 39
blue-genieAsked:
Who is Participating?
 
kumaranmcaConnect With a Mentor Commented:
Hi blue-genie,

I found some issues in your code...

DB connection property not in your code...and i made some changes...Kindly try the below code...
<?php
$conn=mysql_connect('localhost','******','*************');
$select_db=mysql_select_db('db_name',$conn);

			$newGameName = $_REQUEST['newGameName'];
			$newStartDate = $_REQUEST['newStartDate'];
			$newEndDate = $_REQUEST['newEndDate'];
			$newTurnsPerDay = $_REQUEST['newTurnsPerDay'];
			$newActiveState = $_REQUEST['newActiveState'];
			$newNumAttempts = $_REQUEST['newNumAttempts'];
			$editGameID = $_REQUEST['editGameID'];
                
            $result = mysql_query("UPDATE gamedetails SET 
			gameName = '".$newGameName."', 
			startDate = '".$newStartDate."', 
			endDate = '".$newEndDate."', 
			turnsPerDay = '".$newTurnsPerDay."', 
			numAttempts = '".$newNumAttempts."', 
			isActive = '".$newActiveState."' WHERE gameID = '".$editGameID."'");

               echo '<?xml version="1.0"?>';
               echo '<dataxml>';
               if ($result){
                                        echo '<row type="success">';
                         echo '<result>success</result>';  
                                         echo '</row>';
                } else {
                                        echo '<row type="error">';
                    echo '<error>no results</error>';  
                                        echo '</row>';
                }
                echo '</dataxml>';
?>

Open in new window

0
 
john-formbyConnect With a Mentor Commented:
Hi,

Please try the following code.

Hope this helps,

John
<?php
		$newGameName = $_REQUEST['newGameName'];
        $newStartDate = $_REQUEST['newStartDate'];
		$newEndDate = $_REQUEST['newEndDate'];
		$newTurnsPerDay = $_REQUEST['newTurnsPerDay'];
		$newActiveState = $_REQUEST['newActiveState'];
		$newNumAttempts = $_REQUEST['newNumAttempts'];
		$editGameID = $_REQUEST['editGameID'];
		
	    $result = mysql_query("UPDATE gamedetails SET gameName = '$newGameName', startDate = '$newStartDate', endDate = '$newEndDate', turnsPerDay = '$newTurnsPerDay', numAttempts = '$newNumAttempts', isActive = '$newActiveState' WHERE gameID = '$editGameID'") or die(mysql_error());

               echo '<?xml version="1.0"?>';
               echo '<dataxml>';
               if ($result){
			  	 	echo '<row type="success">';
            		 echo '<result>success</result>';  
					 echo '</row>';
                } else {
					echo '<row type="error">';
                    echo '<error>no results</error>';  
					echo '</row>';
                }
                echo '</dataxml>';
?>

Open in new window

0
 
hieloConnect With a Mentor Commented:
>>but update doesn't actually occur.
That's probably because the gameID is not matching your where clause. You have:
WHERE gameID = '$editGameID='

Notice that trailing equal sign? Get rid of it:
WHERE gameID = '$editGameID'
0
 
blue-genieAuthor Commented:

@kumaranmca connection happens with includes not included in snippet.

@hielo - hi I saw that trailing "=" after I posted and have removed that but indirectly you're right. I was outputting in flash correctly so didn't put 2 and 2 together, but in the php i'd changed the variable to editGameID put was passing it in flash as gameID (forgot to change it there)


0
 
blue-genieAuthor Commented:
thanks all.
John the or die bit throws an error on your snippet. is that best practice to put the die in there?
0
All Courses

From novice to tech pro — start learning today.