Aey John Aey John -4 years ago 66
PHP Question

Alpha Numeric values xcannot be retrieved in PHP

I am currently working on this project. Data can be retrieved from database with this code, if certificateNumber is numeric, but it does not search person if certificateNumber field has alphanumeric data.

Where am I wrong with this?

$flag = 0;
echo ($reg);
$con = mysqli_connect('localhost','neoncom_db','12345','neoncom_std');
$qur = 'select * from student where certificateNumber = '.$reg;
$check = mysqli_query($con,$qur);
$first = $row["first"];
$num = $row["certificateNumber"];
$name = $first ." ".$last;
$course = $row["course"];
$date = $row["signupDate"];

echo("NOT FOUND");

Answer Source

You need to encapsulate $reg in quotes. So your query string $qur should be like this:

$qur = "select * from student where  certificateNumber = '" . $reg . "'";

Sidenote: Learn about prepared statement because right now your query is susceptible to SQL injection attack. Also see how you can prevent SQL injection in PHP.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download