Page 1 of 1

SELECT * FROM TABLE

Posted: Sat Jun 27, 2009 4:37 am
by ThaJock
I'm having a difficult time selecting data from a table that I have inserted.
The first thing I did was inserted the following string into a table:
Time Marches On.mp3 <-this is the string.

I used mysql_real_escape_string($string) to insert the data.
Now want to select the string I just inserted. So I do the following:

$file = 'Time Marches On.mp3';
$query = mysql_query("SELECT * FROM audio WHERE name = $file");
while($row = mysql_fetch_array($query)){
echo $row['name']."</br>";
}

I get the following error:
PHP Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
I look through phpMyAdmin and see the string is in the table and the variable $string is spelled correctly but somewhere between php & mysql something is different in the string.

Any ideas why this might be happening? Any help would be appreciated.

Re: SELECT * FROM TABLE

Posted: Sat Jun 27, 2009 4:58 am
by Mark Baker
Strings need to be quoted in SQL queries

Code: Select all

 
$file = 'Time Marches On.mp3';
$query = mysql_query("SELECT * FROM audio WHERE name = '$file'");
 

Re: SELECT * FROM TABLE

Posted: Sat Jun 27, 2009 5:19 am
by ThaJock
Thank you very much Mark. I guess I looked too far into it. Nice work with PHPExcel Class