Experts Round Table Network

Databases => MySQL => Topic started by: thepreacher on March 28, 2007, 02:07:09 AM



Title: Query was empty
Post by: thepreacher on March 28, 2007, 02:07:09 AM
I get the message query was empty any time i try to delete a record from a table. The same script performs update and indert without problems. Below is the code

Code
Language: php (GeSHi-highlighted)
<?php
 
 //create short variable names
 //$gad1=$_POST['gad1'];
 $tramount=$_POST['tramount'];
 $credebcard=$_POST['credebcard'];
 $cash=$_POST['cash'];
 $cheque=$_POST['cheque'];
 $deptopcard=$_POST['deptopcard'];
 $standord=$_POST['standord'];
 $bico=$_POST['bico'];
 $curency=$_POST['curency'];
 $transtype=$_POST['transtype'];
 
 $actiontype = $_POST['actiontype'];
 
 
//addslashes before store
 //$gad1=addslashes($gad1);
 $tramount=addslashes($tramount);
 $credebcard=addslashes($credebcard);
 $cash=addslashes($cash);
 $cheque=addslashes($cheque);
 $deptopcard=addslashes($deptopcard);
 $standord=addslashes($standord);
 $bico=addslashes($bico);
 $curency=addslashes($curency);
 $transtype=addslashes($transtype);
 
  // start session which may be needed later
  // start it now because it must go before headers
  session_start();
 
  $host = 'localhost';      
  $user = '******';
  $password = '*****';
  $dbName = '******';
 
  // connect and select the database
  $conn = mysql_connect($host, $user, $password) or die(mysql_error());
  $db = mysql_select_db($dbName, $conn) or die(mysql_error());
 
if ($actiontype == "addRec")
  // insert new entry into database
   $sql = "insert into chargestable (tramount, credebcard, cash, cheque, deptopcard, standord, bico, curency, transtype) values ('$tramount', '$credebcard', '$cash', '$cheque', '$deptopcard', '$standord', '$bico', '$curency', '$transtype')";

elseif ($actiontype == "deleteRec")
$sql = "DELETE FROM chargestable WHERE tramount = '$tramount'";

elseif ($actiontype == "amendRec")
$sql = "UPDATE chargestable SET credebcard = '$credebcard', cash = '$cash', cheque = '$cheque', deptopcard = '$deptopcard', standord = '$standord', bico = '$bico' WHERE tramount = '$tramount'";

 

     $result = mysql_query($sql, $conn) or die(mysql_error());
     
     header('Location: charges.php');            
?>
 
 

thnx


Title: Re: Query was empty
Post by: VGR on March 28, 2007, 07:11:30 AM
no idea for the reason, but a tip for your debugging :

in stead of
Code:
die(mysql_error());

do

Code:
die(mysql_error()." in '$sql'");

this way you'll see what is the query passed.

If it looks ok, try it manually in the mysql client console. if it works, then I'm stuck.


Title: Re: Query was empty
Post by: mishkad on March 28, 2007, 09:23:43 AM
Also way for debuging:

output your sql statement to screen like:
echo $sql;

then cut and paste this output to your mysql tool (mysql front, mysql admin,... there are plenty of them) then run the query within it and see the results (or errors) ;-).

M.D.