-3

I've got this error. I thought it's on misplaced of ' the $_POST, but if I do that (eg $_POST['regno']) it will give T_ESCAPED error. How I can fix this? Here is the code of line 33:

$sql = "SELECT * FROM students WHERE RegNo='$_POST[regno]' AND
password='$_POST[password]' AND Status='Enabled'";

I'm using Wamp as my localhost. Thanks!

Sirko
  • 72,589
  • 19
  • 149
  • 183
IlhamideaZ
  • 103
  • 10

3 Answers3

1

You need to check the post value like this

 $reg_no = isset($_POST['regno']) ? $_POST['regno'] : '';
 $sql = "SELECT * FROM students WHERE RegNo='".$reg_no."' AND password='".$_POST['password']."' AND Status='Enabled'";
Arun Krish
  • 2,153
  • 1
  • 10
  • 15
1

First be sure that your variables exists before trying to save them :

<?php
if(isset($_POST['regno']) && !empty($_POST['regno'])){
    $regno =$_POST['regno'];
}

if(isset($_POST['password']) && !empty($_POST['password'])){
    $password =$_POST['password'];
}

if(isset($password) && isset($regno)){
    $sql = "SELECT * FROM students WHERE RegNo='$regno' AND password='$password' AND Status='Enabled'";
}
?> 

Also keep in mind that using POST var like this is very exposed to SQL injections.

Nirnae
  • 1,315
  • 11
  • 23
0

try this :

$sql = "SELECT * FROM students WHERE RegNo='".$_POST['regno']."' AND password='".$_POST['password']."' AND Status='Enabled'";
Akhil Thayyil
  • 9,263
  • 6
  • 34
  • 48