Pranav Kumar Pranav Kumar - 10 months ago 24
PHP Question

MySQL insert username and password via php error

Please help, MySQL is not inserting the correct username and password in the database. The php code is:

<?php
$username = $_POST["email"];
$password = $_POST["password"];
require 'database.php';

$myquery = "INSERT INTO verify (`username`, `password`) VALUES ('$username','$password')";
$query = mysql_query($myquery);

if (!$query) {
echo mysql_error();
die;
}
?>


I checked the database.php, it is absolutely fine. It is showing username and password as pranav even though the values are different.

Thanks in advance.

Answer

Try to re-order you code, maybe some vars are overwritting his values:

<?php
    require 'database.php';
    $username = $_POST["email"];
    $password = $_POST["password"];

    $myquery = "INSERT INTO verify (`username`, `password`) VALUES ('$username','$password')";
    $query = mysql_query($myquery);

    if (!$query) {
        echo mysql_error();
        die;
    }
?>