php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42873 mysql query is not getting executed when i'm using a variable in query
Submitted: 2007-10-06 06:39 UTC Modified: 2007-10-06 10:06 UTC
From: pankaj_rohtas at yahoo dot co dot in Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 5.2.4 OS: windows xp
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: pankaj_rohtas at yahoo dot co dot in
New email:
PHP Version: OS:

 

 [2007-10-06 06:39 UTC] pankaj_rohtas at yahoo dot co dot in
Description:
------------
$query = 'SELECT * FROM emp WHERE empid="$empid"' ;
query is not getting executed if i'm using $empid as variable.
if i'm providing direct empid which i have defined as INT then it is working good.

Reproduce code:
---------------
                $empid=FALSE;
		$ename=FALSE;
		$dept=FALSE;
		$sal=FALSE;
 
		$empid=$_POST["empid"];
		$ename=$_POST["ename"];
		$dept=$_POST["dept"];
		$sal=$_POST["salary"];
		

 If ($empid==TRUE)
 {
	$query = 'SELECT * FROM emp WHERE empid="$empid"' ;	
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	//echo "$result";
	while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) 
	{
   echo "\t<tr>\n";
    foreach ($line as $col_value)
	 {
		
        echo "\t\t<td align=center>$col_value</td>\n";
	  
	 }
    echo "\t</tr>\n";
}
echo "</table>\n";

 //Free resultset
mysql_free_result($result);

Expected result:
----------------
full details about that row...

Actual result:
--------------
getting blank page


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-06 10:06 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Check mysql_error() and learn about the difference between double and single quotes.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jun 18 13:01:32 2024 UTC