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

asaidiAsked:
Who is Participating?
 
Ray PaseurConnect With a Mentor Commented:
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
 
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
Ray PaseurCommented:
Try omitting the GROUP BY clause and see if it works without that.
0
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.