Selecting specific data from MySql using php, working with numbers not letters

Hi,

The problem. I want to select all the data in my msql database which has a specific id. e.g. I have three primary ids ‘cell1’, ‘cell2’ and ‘cell3’ etc. okay so you get the idea.

Now I want to select all the data the has a primary id of say ‘cell2’ and spit it back.

I have got this working, but only when the primary key is a number and not when it is a combinantion of letters and numbers or just letters.

This is the php code I am using. The field in the mySql Database is of the varChar type so this shouldn’t be the problem, should it?

PHP CODE:

$phpvar1 = $_GET[“scell”];

$query = “SELECT * FROM tableName WHERE filePath = $phpvar1”;

$result = mysql_query($query);

$num_rows = mysql_num_rows($result);

while($row = mysql_fetch_array($result))
{
$filepath = $row[1];

     $data .= $filepath;
     $data .= "//";

}
echo “info=$data”;

The error I get when the primary ID has any letters in it is

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/devinchcom/public_html/flashupload/selectData.php on line **13”
**
Any help would be great.

Thanks!

DC

change to


$query = "SELECT * FROM tableName WHERE filePath = '$phpvar1'";

Thanks bwh2, it works now :slight_smile:

no problem. you’re also creating a bunch of unnecessary variables in your code, so you could clean it up by getting rid of them. when i first started learning php, my code looked a lot like yours, but now i’ve learned to clean it up.


$phpvar1 = $_GET["scell"];
$result = mysql_query( "SELECT * FROM tableName WHERE filePath = '$phpvar1'" )
$num_rows = mysql_num_rows($result);
while($row = mysql_fetch_array($result))
{
    $data .= $row[1].'//';
} 
echo 'info=$data';

btw, if you have any other code questions, you can use the [ php ] tags (take away the spaces before and after php).