-6

I have a question, when cannot run this programme, it shows

Parse error: syntax error, unexpected 'username' (T_STRING) in C:\xampp\htdocs\fypp\index.php on line 9

<?php
    session_start();
    if (isset($_POST['bttLogin'])){
        require 'connect.php';
        $username = $_POST['username'];
        $password = $_POST['password'];
        $result = mysquli_query($con, 'select * from account where username="'.$username.'" and password="'.$password.'")
        if(mysqli_num_rows($result)==1) {
            $_SESSION['username'] = $username;
            header("Location: welcome.php");
        }
        else
            echo "account is invalid";
    }
    ?>
    <form method="post">
    <table cellpadding="2" cellspacing="2" border="1">
        <tr>
            <td>Username</td>
            <td><input type="text" name="username"></td>
        </tr>
        <tr>
            <td>Password</td>
            <td><input type="password"" name="password"></td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td><input type="submit" name="bttLogin" value="Login"></td>
        </tr>

thanks for answering :)

xrina
  • 3
  • 1
  • 3
    the syntax highlighter of SO already shows it – Kevin Jan 26 '16 at 07:25
  • how should i correct it :X thanks – xrina Jan 26 '16 at 07:27
  • `mysquli_query` there is no `mysquli` library, there's a `mysql`. Do some general debugging first. – Ohgodwhy Jan 26 '16 at 07:29
  • 3
    I'm voting to close this question as off-topic because the error is too specific and is not likely to help anyone in the future. – Ohgodwhy Jan 26 '16 at 07:31
  • i will not work, either u change to mysqli or not.... **WHY** because u missed the termination semi colon for this line **$result = mysquli_query($con, 'select * from account where username="'.$username.'" and password="'.$password.'")** – devpro Jan 26 '16 at 07:44

2 Answers2

0

First of all, paste your code correctly... You are missing </table> and </form> in the end...

Second of all, you were missing a simple apostrophe and a semi-colon in the line

$result = mysquli_query($con, 'select * from account where username="'.$username.'" and password="'.$password.'")

Also, you should use mysqli_query instead of mysqlui_query... Typo!

Your code should be as follows :

<?php
session_start();
if (isset($_POST['bttLogin'])){
    require 'connect.php';
    $username = $_POST['username'];
    $password = $_POST['password'];
    $result = mysqli_query($con, 'select * from account where username="'.$username.'" and password="'.$password.'"');
    if(mysqli_num_rows($result)==1) {
        $_SESSION['username'] = $username;
        header("Location: welcome.php");
    }
    else
        echo "account is invalid";
}
?>

<form method="post">
<table cellpadding="2" cellspacing="2" border="1">
    <tr>
        <td>Username</td>
        <td><input type="text" name="username"></td>
    </tr>
    <tr>
        <td>Password</td>
        <td><input type="password"" name="password"></td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td><input type="submit" name="bttLogin" value="Login"></td>
    </tr>
</table>
</form>
prateekkathal
  • 3,482
  • 1
  • 20
  • 40
  • 1
    `mysquli_query`. This is why these types of questions are a poor experience for SO. It's likely not to help anyone at all in the future, just a means to get Karma and help no one, including OP. – Ohgodwhy Jan 26 '16 at 07:31
  • @Ohgodwhy I fixed that too in my answer... Didn't mention it... Will do... – prateekkathal Jan 26 '16 at 07:34
  • @xrina Kindly select it as an answer if it has solved your problem... :| – prateekkathal Jan 26 '16 at 07:38
  • um..... idk why it still have many problems , after i replace it , it shows Parse error: syntax error, unexpected ';' in C:\xampp\htdocs\fypp\index.php on line 7 – xrina Jan 26 '16 at 07:40
  • because u r not using ending semi colon for termination @xrina – devpro Jan 26 '16 at 07:43
  • @xrina I edited my answer... It should be working fine now. You need to focus on proper encapsulation of your torrent. In any case, let me know if it still shows any problem... – prateekkathal Jan 26 '16 at 07:43
  • $result = mysquli_query($con, 'select * from account where username="'.$username.'" and password="'.$password.'") add ending semi colon.. @xrina – devpro Jan 26 '16 at 07:43
0

Change mysquli_query into mysqli_query, because it not a valid extension, and i think its typo error.

Modified Query:

$result = mysqli_query($con, "SELECT * FROM account 
                          WHERE username='" . $username . "' 
                          AND password ='". $password ."'");

Also note that, you missed the termination semi colon (;) on the same line.

devpro
  • 16,184
  • 3
  • 27
  • 38
Nairi Abgaryan
  • 616
  • 5
  • 16