SELECT * FROM TABLE

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ThaJock
Forum Newbie
Posts: 11
Joined: Tue Nov 04, 2008 10:15 pm

SELECT * FROM TABLE

Post 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.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: SELECT * FROM TABLE

Post 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'");
 
ThaJock
Forum Newbie
Posts: 11
Joined: Tue Nov 04, 2008 10:15 pm

Re: SELECT * FROM TABLE

Post by ThaJock »

Thank you very much Mark. I guess I looked too far into it. Nice work with PHPExcel Class
Post Reply