-1

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";
}

?>
Nikhil Sawant
  • 103
  • 10

2 Answers2

2

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";
}

?>
Mohammad Hamedani
  • 3,304
  • 3
  • 10
  • 22
-1

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.'" ;' ;

Valery K.
  • 147
  • 1
  • 5
  • That is not the source of the problem. https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks-in-mysql – Rickard Jun 17 '17 at 18:11