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.
SELECT * FROM TABLE
Moderator: General Moderators
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: SELECT * FROM TABLE
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
Thank you very much Mark. I guess I looked too far into it. Nice work with PHPExcel Class