Bryce
Bryce

Reputation: 1

Inserted data not going to phpMyAdmin database

I'm having a problem with my data not going through to phpMyAdmin. The server and database connects the PHP but the data is not inserted into the table.

This is what I have so far.

    <?php 

    $dbConnect = mysqli_connect("xxxxxxx", "xxxxx","xxxxx");
    if (!$dbConnect)
    die("<p>The database server is not available.</p>");
    echo "<p>Successfully connected to the database server.</p>";
    $dbSelect = mysqli_select_db( $dbConnect,"sxxxxxxx_db" );
    if (!$dbSelect)
    die("<p>The database is not available.</p>");
    echo "<p>Successfully opened the database.</p>";

    $sql = "INSERT INTO customer (Name,Password,Email,Phone) VALUES ('$_POST[namefield]', '$_POST[pwdfield]','$_POST[email]','$_POST[phone]' ) ";

     mysqli_query($sql,$dbConnect);

     mysqli_close($dbConnect);

    if(isset($_POST['namefield']) && isset($_POST['pwdfield']) && isset($_POST['cpwdfield']) && isset($_POST['email']) && isset($_POST['phone']) && isset($_POST['submit']))
        {
            $name = $_POST['namefield'];
            $password = $_POST['pwdfield'];
            $cpassword = $_POST['cpwdfield'];
            $email = $_POST['email'];
            $phone = $_POST['phone'];

            if ($_POST["pwdfield"] == $_POST["cpassword"])
    mysqli_query("INSERT INTO user VALUES('','$password')") or die(mysqli_error());

       else {
       echo("Password did not match! Try again. ");

Upvotes: 0

Views: 2181

Answers (3)

kammy
kammy

Reputation: 352

  • close your connection .
  • You should not use $_POST directly in your query, use following way to prevent SQL injection.

//Connect

$unsafe_variable = $_POST["user-input"];
$safe_variable = mysql_real_escape_string($unsafe_variable);

mysql_query("INSERT INTO table (column) VALUES ('" . $safe_variable . "')");

//Disconnect

Upvotes: 1

Raghav Aher
Raghav Aher

Reputation: 1

change sql slightly

$sql = "INSERT INTO customer (Name,Password,Email,Phone) VALUES ('".$_POST['namefield']."', '".$_POST['pwdfield']."','".$_POST['email']."','".$_POST['phone']."' ) "

Upvotes: 0

Rex Rex
Rex Rex

Reputation: 1030

You have closed the database connection

 mysqli_close($dbConnect);

Upvotes: 0

Related Questions