Navigate
Home
ArticleWiki
Forum
Journal
Search
Newsletter
Links
Tech News
expertsrt.com
Welcome Guest.
Username:

Password:

Remember me

Query was empty
Welcome, Guest. Please login or register.
November 21, 2008, 02:20:13 PM
11306 Posts in 1249 Topics by 501 Members
Latest Member: rosaline
Experts Round Table Network  |  Databases  |  MySQL  |  Query was empty « previous next »
Pages: [1]
Author Topic: Query was empty  (Read 440 times)
thepreacher

Offline Offline

Posts: 77


« 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
Logged
VGR
Mentor

Offline Offline

Posts: 682



WWW
« Reply #1 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.
Logged

techie overlord, answers all kind of questions on http://www.europeanexperts.org
mishkad

Offline Offline

Posts: 15


« Reply #2 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.

Logged
Pages: [1]
« previous next »
    Jump to: