Pranav Kumar
Pranav Kumar

Reputation: 104

MySQL insert username and password via php error

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.

Upvotes: 0

Views: 2643

Answers (2)

Pranav Kumar
Pranav Kumar

Reputation: 104

I found out what the error was . It was happening because the database.php was coded like this.

PHP:

   <?php
         $username="pranav";
         $password="pranav";
         $host="localhost";
         $database="requester";

              $server = mysql_connect($host, $username, $password);
              $connection = mysql_select_db ($database, $server);

              $table='verify'
   ?>

The username and password was getting rewritten. Thanks Grommy

Upvotes: 0

Grommy
Grommy

Reputation: 367

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

Upvotes: 1

Related Questions