samedi 3 juin 2017

Not adding the user to mySQL database

Good evening, I am a beginner in PHP + mySQL specifically. Now, I've been having some troubles when I click the 'submit' button to add the user to mySQL database. I am currently using netbeans for IDE and XAMPP for local host.

Could you please help me? If there's too much complicated/technical information, could you please explain?

index.php file:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Index.php FILE</title>
    </head>
    <body>
        <form action="signup.php" method="POST">
            <input type="text" name="first" placeholder="Enter your first name">
            <br/>
            <input type="text" name="last" placeholder="Enter your last name">
            <br/>
            <input type="text" name="uid" placeholder="Enter your username">
            <br/>
            <input type="password" name="pwd" placeholder="Enter your password">
            <br/>
            <button type="submit">SIGN UP</button>
            <br/>
        </form>
    </body>
</html>

signup.php file:

include 'dbc.php';

$first = $_POST['first'];
$last = $_POST['last'];
$uid = $_POST['uid'];
$pwd = $_POST['pwd'];

$sql = "INSERT INTO user (first, last, uid, pwd) VALUES ('$first', '$last', '$uid', '$pwd')";
$result = mysqli_query($c, $sql);

echo $first . "<br/>"; //just to test
echo $last . "<br/>";
echo $uid . "<br/>";
echo $pwd . "<br/>";

if ($result) {
    echo "<p>Successfully signed up!<p/>";
} else {
    echo "<p>Sorry, we could not sign you in.<p/>";
}

//header("Location: index.php"); //Take us to the front page again.

dbc.php file:

<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

mysql_connect('localhost', 'root', '');

mysql_select_db('register');

$sql = "SELECT * FROM `customers`";
$records = mysql_query($sql);

If you have any doubts, let me know. Thank you very much.




Aucun commentaire:

Enregistrer un commentaire