mysql - How to Compare a String in an SQL Database to a PHP Variable -


ok, title says, want find out how can compare string in sql database php string.

<!doctype html> <html>  <head> <title>processing request</title> <link rel="stylesheet" href="style.css" type="text/css" /> </head>  <body> <h1>account creation</h1>     <h3>      <?php     $dbhost = "localhost";     $username = "root";     $password = "";     $connect = mysqli_connect("$dbhost", "$username", "$password");     $db = "accounts";      if (!$connect){         die("error: database connection failed: " . mysqli_connect_error());     }      mysqli_select_db($connect, $db);      $makeuser = $_post["makeuser"];     $makepass = $_post["makepass"];     $sql = "insert accounts (username, password) values ('$makeuser', '$makepass')";       if("select username accounts username = '$makeuser'"){ 

the line of code above trying compare value (from column "username" in table "accounts") in sql database string user entered create account ($makeaccount). specific piece of code suppose tell user if username trying set their account has been taken.

however, everytime run code (and enter username form can visually see in database not taken), still says username has been taken, though it's definetly not.

        header("location: createaccount.php?status=usertaken");     }     else{         mysqli_query($connect, $sql);         echo "account creation succesful!";     }      mysqli_close($connect);     ?>      click <a href="index.php">here</a> login.      </h3>     </body> </html> 

thank you, answers appretiated. :)

p.s. first program writing in php , first time using sql database, please, try keep simple, , understandable.

p.s.s have tried many solutions, no success.

please change if statement of comparison

from

if("select username accounts username = '$makeuser'"){ 

to

if(mysqli_query("select username accounts username = '$makeuser'")){ 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -