Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
Coco
Forum Contributor
Posts: 339 Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:
Post
by Coco » Fri Oct 04, 2002 7:05 am
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
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Fri Oct 04, 2002 7:22 am
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
Coco
Forum Contributor
Posts: 339 Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:
Post
by Coco » Fri Oct 04, 2002 7:25 am
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
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Fri Oct 04, 2002 7:32 am
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>');
Coco
Forum Contributor
Posts: 339 Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:
Post
by Coco » Fri Oct 04, 2002 7:36 am
well waddaya know...
my bad, it works
thanks twig
Coco
Forum Contributor
Posts: 339 Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:
Post
by Coco » Fri Oct 04, 2002 8:45 am
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
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Fri Oct 04, 2002 8:49 am
Try removing the single quotes from around the element name
instead of
Mac
Coco
Forum Contributor
Posts: 339 Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:
Post
by Coco » Fri Oct 04, 2002 8:52 am
my god im being such a newbie today
thanks twig
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Fri Oct 04, 2002 8:53 am
I know the feeling.