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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.