PDA

View Full Version : [php]function with mysql


yoda
02-05-2003, 03:12 PM
hi, made a plain simple function to retrieve some data from a table but it screws up .. here's what i got

<--- header.php flie --->
echo data(tick);
echo mysql_error();

<--- config file --->
function data($option) {
$result = mysql_query("SELECT * FROM cw_data WHERE option='$option'");
$row = mysql_fetch_array($result);
$value = $row["value"];
return $value;
}

I did everything ok, db connection etc but this is what i get:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/virtual/site99/fst/var/www/html/cw/cw/config_data.php on line 11
You have an error in your SQL syntax near 'option='tick'' at line 1 - Server Status:

thx in advance

scoutt
02-06-2003, 08:18 AM
that is because "option" is a reserved word in mysql. you have to change it to something else.

CTCecil
02-06-2003, 02:41 PM
<--- header.php flie --->
echo data(tick);
echo mysql_error();

<--- config file --->
function data($option) {
$result = mysql_query("SELECT * FROM `cw_data` WHERE `option`='$option'");
$row = mysql_fetch_array($result);
$value = $row["value"];
return $value;
}


That would probably be the best way but putting the `'s before it might work too.

scoutt
02-06-2003, 02:44 PM
the ` do nothing what-so-ever. it is becasue he is using a mysql reserved word.

CTCecil
02-06-2003, 02:48 PM
Sorry scoutt, heh, once agian you prove me wrong... :) I used to come here alot but I forgot my username, I am back and more advanced with php/mysql...

scoutt
02-06-2003, 02:53 PM
cool, glad to have ya back and more experienced mask person :P

CTCecil
02-06-2003, 02:56 PM
Oh and I really prefer for the beginners of mySQL to go to scotts site (http://snippetlibrary.com) it doesnt have alot but what it does have on mysql was very useful to me when I knew nothing. Also, me and a friend are almost finished with PHPToolBox.com it allready has a lot of content.