• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 383
  • Last Modified:

function parameters and mysql select

Hi
i m passing parametrs via a function with the user choice:
if (empty($netw) && !empty($_POST['client'])){
  if(count($pulse1)==4){
         include('full.php');  
         p5($date,$date2,$report,$client=$client,null);
        
   }  

}
if (empty($client) && ($netw<>"")){
 
  if(count($pulse1)==4){
         include('full.php');  
         p5($date,$date2,$report,null,$netw=$netw);
        
   }  
}
if (empty($netw) && empty($client)){
   
   if(count($pulse1)==4){
      include('full.php');  
        p5($date,$date2,$report,null,null);
        
  }

Open in new window

i can see all the parameters in full.php
but on my select they are not getting the infos i want
full.php
<?php
 
function p5($v1,$v2,$v3,$v4,$v5){  
$auto=$_GET['auto'];
echo $a, PHP_EOL;
	echo $v1, PHP_EOL;
	echo $v2, PHP_EOL;
	echo $v3, PHP_EOL;
	echo $v4, PHP_EOL;
        echo $v5, PHP_EOL;

     $result1=mysql_query("SELECT unit_serial,DATE(tran_date)as datei,customer_no,pulse_channel 
        from count_transactions  
          WHERE DATE(tran_date) BETWEEN '$v1' AND '$v2' and account_no=$auto AND customer_no=$v4 AND unit_serial=$v5  
                              
group by customer_no,unit_serial ") ; 
         $num = mysql_num_rows($result1);

Open in new window

0
asaidi
Asked:
asaidi
  • 5
  • 4
1 Solution
 
Ray PaseurCommented:
Line 5 of the second code snippet -- what is the $a variable?  It appears to be undefined in the scope of the function.  You should add error_reporting(E_ALL) to the top of your scripts so you can avoid things like that.

You should also avoid putting a literal string into the mysql_query() function.  Instead, prepare the query string in a separate variable.  Then you can run the query with a line of code like this.  It will show you if the query fails.  In the code above, the query can fail and you will not get any information about the failure!
$res = mysql_query($sql) or die("FAIL: $sql<br>" . mysql_error());

Open in new window

0
 
asaidiAuthor Commented:
Hi
i can see the mistake it is when i send a function and inside an empty or null value it does not taken in mysql
FAIL: SELECT unit_serial,DATE(tran_date)as datei,customer_no,pulse_channel from count_transactions WHERE DATE(tran_date) BETWEEN '2012-07-01' AND '2012-07-07' and account_no=1 AND customer_no= AND unit_serial=3 group by customer_no,unit_serial
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND unit_serial=3 group by customer_no,unit_serial' at line 3

Open in new window

0
 
Ray PaseurCommented:
Try omitting the GROUP BY clause and see if it works without that.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
asaidiAuthor Commented:
Hi
no it is not working
0
 
Ray PaseurCommented:
What is the error output now?
0
 
asaidiAuthor Commented:
the same as precedent..
0
 
Ray PaseurCommented:
No, It cannot be if you removed the GROUP BY clause.
0
 
asaidiAuthor Commented:
Hi
that what i get when i remove group by clause
2012-07-01 2012-07-07 1 3 FAIL: SELECT unit_serial,DATE(tran_date)as datei,customer_no,pulse_channel from count_transactions WHERE DATE(tran_date) BETWEEN '2012-07-01' AND '2012-07-07' and account_no=1 AND customer_no= AND unit_serial=3 
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND unit_serial=3' at line 3

Open in new window

0
 
Ray PaseurCommented:
Here is the culprit:

AND customer_no= AND unit_serial=3

Note that customer_no= has no argument.  You can try putting quotes around it, or you can try testing to be sure that it is present in the function call.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now