Link to home
Start Free TrialLog in
Avatar of asaidi
asaidi

asked on

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

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

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

Avatar of asaidi
asaidi

ASKER

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

Try omitting the GROUP BY clause and see if it works without that.
Avatar of asaidi

ASKER

Hi
no it is not working
What is the error output now?
Avatar of asaidi

ASKER

the same as precedent..
No, It cannot be if you removed the GROUP BY clause.
Avatar of asaidi

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial