Jump to content

Can't get this query to execute. Always returns false.


ajoo

Recommended Posts

Hi all ! The following code has two similar queries. Query 1 and Query 2. While Query 1 works just fine, Query 2 simply fails persistently. I have not been able to figure out why?

 

I have checked every single variable and field names but found no discrepancy of any sort or any mismatch of spelling with the fields in the database.

 

I would be grateful if anybody can point out what is preventing the second query from returning a valid mysqli object as the first one does. Here is the code for the two.

<?php
$db_host = "localhost";
$db_user ="root";
$db_pass ="";
$db_database ="allscores";

//////////////// CHECKING VARIABLE FILEDS IN A UPDATE QUERY //////////////////////////////////
//////////////// QUERY 1 /////////////////////////////////////////////////////////////////////

/*
$db_database ="test";
$db_table ="users";
$RecNo = 1;			
		
$field1 = 'name';
$field2 = 'password';
$field3 = 'email'; 
$field4 = 'id';
$val1 = "Ajay";
$val2 = "howzatt";
$val3 = "[email protected]";


					$con = mysqli_connect($db_host,$db_user,$db_pass,$db_database) or die('Unable to establish a DB connection');
					$query = "UPDATE $db_table SET $field1 = ?,
							$field2 = ?, $field3 = ?
							WHERE $field4 = ? ";   // session terminated by setting the sessionstatus as 1 
					$stmt = $con->prepare($query);
					var_dump($stmt); 
					$stmt->bind_param('sssi',$val1,$val2,$val3,$RecNo);
					if($stmt->execute())
					{
						$count = $stmt->affected_rows;
						echo $count;
					}		
//////////////// QUERY 1  END /////////////////////////////////////////////////////////////////////
*/



//////////////// QUERY 2 /////////////////////////////////////////////////////////////////////

$con = mysqli_connect($db_host,$db_user,$db_pass,$db_database) or die('Unable to establish a DB connection');
$table = 'scores';
$date = date('Y-m-d H:i:s');


/*
$prestr 	= "Mrt_M_";		
$STATUS		= $prestr."Status";
$S_R1 		= $prestr."Scr_1";
$S_R2 		= $prestr."Scr_2";
$PCT 		= $prestr."PPT";
$DPM 		= $prestr."DSP";
$TIMETAKEN 	= $prestr."TimeTaken";
*/


$STATUS		= "Mrt_M_Status";
$S_R1 		= "Mrt_M_Scr_1";
$S_R2 		= "Mrt_M_Scr_2";
$PPT 		= "Mrt_M_PPT";
$DSP 		= "Mrt_M_DSP";
$TIMETAKEN 	= "Mrt_M_TimeTaken";

$TimeOfLogin	=	$date;	
$no_of_logins	=	10;
$time_of_nLogin	=	$date;
$m_scr_row1		=	5;
$m_scr_row2		=	5;
$m_ppt			=	20;
$m_dsp			=	60;
$m_time			=	120;
$date			=	$date;
$RecNo			=	24;

		$query = "UPDATE $table SET 
				TimeOfLogin = ?,
				no_of_logins = ?,
				time_of_nLogin = ?,
				$S_R1 = ?,					
				$S_R2 = ?,					
				$PPT = ?,						
				$DSP = ?,						
				$TIMETAKEN = ?,				
				$STATUS = '1',				
				TimeOfLogout = ?,
				WHERE RecNo = ?";			
		$stmt = $con->prepare($query);

		var_dump($stmt);

		$stmt->bind_param('sisiiddssi',$TimeOfLogin,$no_of_logins,$time_of_nLogin,$m_scr_row1
					$m_scr_row2,$m_ppt,$m_dsp,$m_time,$date,$RecNo);
		if($stmt->execute()) echo " DONE !";


?>	



Thanks to all

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.