syntax error, unexpected '$sql_query' (T_VARIABLE)

Hey guys can you pls help me to find any error in this particular code I'm new to php i don't know much but the error is

Parse error: syntax error, unexpected '$sql_query' (T_VARIABLE)

<?php

require"init.php";

$user_name = "Nikhil123";
$user_pass = "Sawant"

$sql_query = "select name from user_info where username like '$user_name' and userpass like '$user_pass' ;" ;

$result = mysqli_query($con,$sql_query);

if(mysqli_num_rows($result)>0)
{
    $row = mysqli_fetch_assoc($result);
    $name = $row("name");
    echo "<h3> HELLO welcome".$name "</h3>";
}
else
{
    echo "No INFO";
}

?>

2 answers

  • answered 2017-06-17 18:06 Mohammad Hamedani

    Add ; after $user_pass = "Sawant". Add . between $name and "</h3>"; in echo "<h3> HELLO welcome".$name "</h3>";:

    <?php
    
    require"init.php";
    
    $user_name = "Nikhil123";
    $user_pass = "Sawant";
    
    $sql_query = "select name from user_info where username like '$user_name' and userpass like '$user_pass' ;" ;
    
    $result = mysqli_query($con,$sql_query);
    
    if(mysqli_num_rows($result)>0)
    {
        $row = mysqli_fetch_assoc($result);
        $name = $row("name");
        echo "<h3> HELLO welcome".$name ."</h3>";
    }
    else
    {
        echo "No INFO";
    }
    
    ?>
    

  • answered 2017-06-17 18:06 V. Krukov

    Use single quotes instead of "..." for sql -- i.e. 'select ..."'.$var.'" ....';


    $sql_query = 'select name from user_info where username like "'.$user_name.'" and userpass like "'.$user_pass.'" ;' ;