Page 1 of 1

unknown update error :/

Posted: Fri Oct 04, 2002 7:05 am
by Coco
can anyone see the error in this script? i cant :(

Code: Select all

<?php
$result = mysql_query("SELECT or1, --------- or40 FROM Players WHERE user='{$HTTP_SESSION_VARSї'user']}'");
$orderrow = mysql_fetch_row($result);
print_r($orderrow);
echo '<br>';
print_r($HTTP_POST_VARS);
if($HTTP_POST_VARSї'ref1a']){
	$string1 = $HTTP_POST_VARSї'order1'] . ',' . $HTTP_POST_VARSї'ref1a'];
	if($HTTP_POST_VARSї'ref1b']){
		$string1 = $string1 . ',' . $HTTP_POST_VARSї'ref1b'];
		if($HTTP_POST_VARSї'ref1c']){
			$string1 = $string1 . ',' . $HTTP_POST_VARSї'ref1c'];
			if($HTTP_POST_VARSї'ref1d'])
				$string1 = $string1 . ',' . $HTTP_POST_VARSї'ref1d'];
		}
	}
	echo "string1 = $string1";
	$i = 0;
	while($i<40){
		if(!isset($orderrowї'$i'])){
			$i++;
			$stringa = 'or'.$i;
			echo "stringa = $stringa";
			$query = '"UPDATE Players SET ' . $stringa . ' = ''' . $string1 . "' WHERE user= '{$HTTP_SESSION_VARSї'user']}'"";
			echo $query;
			mysql_query($query);
			break;
		}
		else
			$i++;
	}
}

?>
the output is this:
Array ( [0] => ------ [39] => )
Array ( [order1] => 1 [ref1a] => 1 [ref1b] => 4 [ref1c] => [ref1d] => ) string1 = 1,1,4 stringa = or1 "UPDATE Players SET or1 = '1,1,4' WHERE user= 'Jim'"
the output is as expected, but the script itself isnt executing the update (i checked the database) any help would be appreciated 8O

Posted: Fri Oct 04, 2002 7:22 am
by twigletmac
Try changing

Code: Select all

$query = '"UPDATE Players SET ' . $stringa . ' = ''' . $string1 . "' WHERE user= '{$HTTP_SESSION_VARSї'user']}'"";
to

Code: Select all

$query = "UPDATE Players SET ".$stringa." = '". $string1."' WHERE user= '".$HTTP_SESSION_VARSї'user']."'";
Mac

Posted: Fri Oct 04, 2002 7:25 am
by Coco
ill try that but i dont think that will make much difference since i outputted the query string and it was as it should be

Posted: Fri Oct 04, 2002 7:32 am
by twigletmac
The ammended version should produce:

Code: Select all

UPDATE Players SET or1 = '1,1,4' WHERE user= 'Jim'
whereas the previous version gives

Code: Select all

"UPDATE Players SET or1 = '1,1,4' WHERE user= 'Jim'"
note the lack of double quotes around the ammended version. Putting double quotes around the SQL statement will probably cause an error. Try adding some error handling after the mysql_query() call:

Code: Select all

mysql_query($query) or die(mysql_error().'<p>'.$query.'</p>');

Posted: Fri Oct 04, 2002 7:36 am
by Coco
well waddaya know...

my bad, it works

thanks twig

Posted: Fri Oct 04, 2002 8:45 am
by Coco
ok it updates properly now, but im having trouble with this line (from above):

Code: Select all

<?php
    if(!isset($orderrowї'$i'])) 
?>
this doesnt work...
no matter what the contents of the database, the update always applies to the first 3 elements :(

ive also tried if($orderrow['$i']==NULL) but it didnt work either

Posted: Fri Oct 04, 2002 8:49 am
by twigletmac
Try removing the single quotes from around the element name

Code: Select all

$orderrowї$i]
instead of

Code: Select all

$orderrowї'$i']
Mac

Posted: Fri Oct 04, 2002 8:52 am
by Coco
my god im being such a newbie today :cry: :oops: :cry:

thanks twig

Posted: Fri Oct 04, 2002 8:53 am
by twigletmac
:lol: I know the feeling.