Jump to content

SELECT: unknown sql error


bulrush

Recommended Posts

I'm trying to execute a SELECT query to see if a record exists before I delete it. Here is the code in my calling program, which calls my routine called crqryDelete().

      $query='bid='.$bid;
      $num=crqryDelete('zzbrands',$query);
      //if (!$result)
      if ($num<=0)
            {
            $msg=mysql_error();
            $msg.='Could not DELETE brand '.$brand.'<br/>'.$query; //There was an error.
            $msg.='num='.$num;
            crError($_SERVER['PHP_SELF'].' line '.__LINE__,$msg,true);
	    mysqli_close($dbc);
            }

 

Here is my utility program to delete the record. Note that 6 weeks ago this crqryDelete worked fine.

//====================================================
function crqryDelete($table, $where)
//Run a DELETE query. 
//Returns: records deleted
//Ex: $table='parts'
//$where='pid=10'
{
global $dbc;

if (strlen($table)==0)
{
$s='You cannot have a blank table name in param 1. No action taken.';
crError(__FUNCTION__,$s,true);
return 0;
}
if (strlen($where)==0)
{
$s='You cannot have a blank WHERE clause in param 2. No action taken.';
crError(__FUNCTION__,$s,true);
return 0;
}
//First select records to get count of records affected.
$n=0;
//Do query and loop here.
$query = "SELECT * FROM $table WHERE $where;";
if (!$result=mysqli_query($dbc,$query))
    {
    $msg=mysql_error();
    $s=$msg.$query;
    crError(__FUNCTION__,$s,true);
    }

$num=mysqli_num_rows($result);
if ($num<=0)
{
return $num;
}
$query='DELETE FROM '.$table.' WHERE '.$where;
//crDebug('crqryDelete: ',$query); //DEBUG
if (!$result=mysqli_query($dbc,$query))
    {
    $msg=mysql_error();
    $s=$msg.$query;
    crError(__FUNCTION__,$s,true);
    }

return $num; //crqryDelete
}

 

Here is the error I'm getting when I run this code:

ERROR in crqryDelete:
SELECT * FROM zzbrands WHERE bid=13;

 

What is wrong with this SELECT statement?

Is "bid" a reserved word?

 

The field "bid" is a longint, auto increment.

 

Thanks.

 

Link to comment
https://forums.phpfreaks.com/topic/209257-select-unknown-sql-error/
Share on other sites

Given that your code is using mysqli_query() but it is using mysql_error(), it would be a little hard to get any actual error information. If you switch to use mysqli_error(mysqli $link) you can probably find out why the queries are failing.

Archived

This topic is now archived and is 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.