-1

hey guys please help me i am having this error when i tried to connect with my DB.

Fatal error: Can't use function return value in write context in C:\wamp\www\ipsem6\include\membersite_config.php on line 20

Below is My Code`

$host="localhost";
$username="root";
$password="";
$link=mysqli_connect($host,$username,$password,"a8172058_portal");
if(isset($_POST["submit"]))
 {
    $name=$_POST["name"];
    $email=$_POST["email"];
    $username=$_POST["username"];
    $pass=$_POST["password"];
    $contactno=$_POST["contact1"];
    $cont2=$_POST["contact2"];
    $dob=$_POST["date"];
    $role=$_POST["rle"];
    $gender=$_POST["s"];
    $qry="insert users          values('$name','$email','$username','$pass','$contactno','$cont2','$dob','$role','$gender')";
    $res=mysqli_query($link,$qry);
    if(mysqli_query_rows($link)=false)
    {
        echo 'you have registered successfully';
    }
    else
    {
        echo 'registration failed';
    }


?>` 

I checked so many solution but not able to understand them because am not so good in Data Base Programming..! Please help me to sole it as i have to submit my project tomorrow. :/

Ashish Bharwal
  • 157
  • 1
  • 3
  • 13

4 Answers4

2
if(mysqli_query_rows($link)=false)

You are trying to assign the value false to the function return value here.

The comparison operator in PHP is ==.

CBroe
  • 91,630
  • 14
  • 92
  • 150
0
if(mysqli_query_rows($link)==false) 

instead of:

if(mysqli_query_rows($link)=false)

== is used to check against a value (comparison Operator), = is the assignment operator.

Kuber Kanav
  • 13
  • 1
  • 1
  • 4
0

you must use this code :

 if(mysqli_query_rows($link)){}
A.EROUEL
  • 26
  • 1
0

The assignment in

if(mysqli_query_rows($link)=false)

does not make sense; it should rather be a type-obedient comparison operator ===.

Additionally, there is no such function mysqli_query_rows(). Maybe you were looking for mysqli_fetch_row() or mysqli_num_rows(). (But beware that these functions operate on result identifiers rather than database connection identifiers.)

You are doing an INSERT, so there will be no data to fetch. Rather, the query itself will return false on failure, so the correct representation should be:

if($res!==false)

(Notice that I used the inequality operator, because you branch to success as a result of the if.) Anyway, success and error should depend on tests on the input instead of the insert operation itself.

Last but by far not least, your script is vulnerable to SQL injection.

Community
  • 1
  • 1
syck
  • 2,984
  • 1
  • 13
  • 23