0

hello please me out regarding this function . Its searching script. when i am passing integer to it it work and when i pass like 12eh it doesnt work . although i have kept varchar as a datatype so it can work for both

function view($pno)
{
$this->query=("select * from user where pno=$pno");
$rd = $this->executeQuery();
@$data = $rd->fetch_assoc();
return $data; 
}
1
  • add single quotes to work for nonintegers. also use something like mysql_real_escape_chars so you dont have an sqlinject Commented Mar 20, 2011 at 19:00

3 Answers 3

3

You need to quote your variable in the SQL query:

$this->query=("select * from user where pno = '$pno'");

Also you would probably do well to do:

$pno = mysql_escape_string($pno);

Before sticking the variable in your SQL statement. The man page explains more.

Sign up to request clarification or add additional context in comments.

Comments

0
$this->query=("select * from user where pno='$pno'");

missing quotes around $pno

Comments

0

mysql_escape_string() is deprecated in PHP 5.3. Use instead mysql_real_escape_string()

Code will be something like this:

$this->query = "SELECT * FROM user WHERE pno = '" . mysql_real_escape_string($pno) . "'";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.