0
<?php
include 'includes/db_connect.php';
//function to avoid Quotes to avoid sqlinjection
function pm($input)
{
    if(preg_match('/\"/',$input)){

    return true;
    }
    elseif(preg_match('/\'/',$input)){
    return true;
    }
    return false;

}
if($_SERVER["REQUEST_METHOD"]=="POST"){

if(pm($_POST['firstname']) || pm($_POST['lastname']) || pm($_POST['email']) || pm($_POST['password']) || pm($_POST['Pincode']) || pm($_POST['Password'])){
    $messageErr='<div class="alert alert-danger"><strong>Error! </strong>Invalid!!!! Donnot use Quotes in input</div>';
}
else {


mysqli_autocommit($conn,FALSE);

if(isset($_POST['createuser'])){

    if (!ctype_alpha($_POST["firstame"]))
    {
        $messageErr = '<div class="alert alert-danger"><strong>Error! </strong>Name Should Contain Only Alphabets.</div>';
    }
    elseif(!ctype_alpha($_POST["lastname"]))
    {
        $messageErr = '<div class="alert alert-danger"><strong>Error! </strong>Name Should Contain Only Alphabets.</div>';
    }
    elseif (!isset($_POST["email"])) 
    {
        if(!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL))
        {
            $messageErr = "<div class='alert alert-danger'><strong>Error! </strong>Invalid Email</div>";
        }
    }
    elseif(strlen($_POST["Password"]) < 8)
    {
        $messageErr = "<div class='alert alert-danger'><strong>Error! </strong>Password Should Be Atleast 8 Characters .</div>";
    }
    else
    {
        $fname = trim(mysqli_real_escape_string($conn,$_POST["firstname"]));
        $lname = trim(mysqli_real_escape_string($conn,$_POST["lastname"]));
        $mail = trim(mysqli_real_escape_string($conn,$_POST["email"]));
        $pass = trim(mysqli_real_escape_string($conn,$_POST["password"]));
    }
}

$mail_query = "SELECT * FROM signup WHERE email = '$mail'";
$mail_res = mysqli_query($conn,$mail_query);
if(mysqli_num_rows($mail_res) >= 1)
{
    $messageErr="<div class='alert alert-danger'><strong>Error! </strong>Email Already Exists</div>";
}
else
{
    $ins1 = "INSERT into signup (fname, lname, email, passwd) values( '$fname' , '$lname', '$mail','$pass')";
    $res1= = mysqli_query($conn,$ins1);
    mysqli_commit($conn);
    header("Location:index.php?registered=true");
}
mysqli_close($conn);
?>

I am new to PHP. I am getting this error and its been an hour and I am not able figure out the solution. Checked it online but got no solution.Checked for all the brackets but there is no issue in any bracket.

  • 1
    Just eyeballing it, you definitely seem to be missing some closing brackets. An IDE would catch that, as would better formatting. – elixenide Mar 12 '16 at 19:26
  • I tried that in PHPStorm but I got no result. – Kshitij Pandey Mar 12 '16 at 19:27
  • Even though you really want to make sure that assignment works: `$res1= = mysqli_query($conn,$ins1);` one equal sign is definitely enough – Rizier123 Mar 12 '16 at 19:29
  • @KshitijPandey Then you're doing something wrong. Just look at your formatting. Your indentation is inconsistent, and you have at least one `if` and one `else` that, as far as I can see (I'm on a phone, so I can't use PHPStorm myself right now) have no closing braces. – elixenide Mar 12 '16 at 19:30
  • Thanks. That was a typo error from my side. – Kshitij Pandey Mar 12 '16 at 19:31
  • @EdCottrell Then I'll check again for if and else statements. – Kshitij Pandey Mar 12 '16 at 19:32
  • @KshitijPandey Are you sure you look at the correct file? `C:\xampp\htdocs\ait\proc.php on line 69` – Rizier123 Mar 12 '16 at 19:35
  • @KshitijPandey I just dumped this into PHPStorm and confirmed that you are missing `}`s, in particular the `}`s to close the `if` block that begins on line 16 and the `else` block that begins on line 21. As Rizier123 said, you need to have `=` instead of `= =` on line 51. Also, you use some variables (`$fname` , `$lname`, `$mail`, `$pass`) that may never get initialized. PHPStorm will alert you to all of these problems unless you turned off the code inspections or are running in Power Save Mode. As I said above, formatting your code with proper indentation would make these errors very obvious. – elixenide Mar 12 '16 at 20:56

0 Answers0