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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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: Fri Sep 27 22:01:26 2024 UTC