Jump to content

[SOLVED] error with simple mysql query


daveh33

Recommended Posts

if ($free) {
$query = mysql_query("SELECT * FROM vids WHERE number='$free'") or die("cant get free vid info");
$row = mysql_fetch_array($query) or die("error with this row");
$videourlfree = $row['videourl'];
$imgurlfree = $row['imgurl'];
}

 

The code stops and displays the message: error with this row  -any ideas???

Link to comment
Share on other sites

You should not put a die on the fetch since there might not be any data returned as is that is not really considered an error.

 

The number column might be a reserved word in MySQL so you should enclose it in back tick marks. Also, display any MySQL errors to help yourself solve the problem.

 

Example:

 

<?php

if ($free) {
    $free = mysql_real_escape_string($free);
    $strSql = "SELECT * FROM `vids` WHERE `number` = '$free'";
    $objResult = mysql_query($strSql);
    if ($objResult) {
        $arrRow = mysql_fetch_assoc($objResult);
        if ($arrRow) {
            $videourlfree = $arrRow['videourl'];
            $imgurlfree    = $arrRow['imgurl'];
        } else {
             echo 'No data matched your query';
        }
    } else {
        die('SQL: ' . $strSql . ' Error: ' . mysql_error());
    }
}

?>

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.