mysql - Why isn't my PHP Sign-Up not working?

274

I have a question about my PHP Login Script. I am very, very new to PHP and MySQL, so keep that in mind when looking at my code.

<?php

include('connectdb.php')

//define
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$passwordconfirm=$_POST['passwordconfirm'];
$email=$_POST['email'];
$firstname=$_POST['firstname'];

//prevents from MySQL Injection
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$passwordconfirm = stripslashes($passwordconfirm);
$email = stripslashes($email);
$firstname = stripslashes($firstname);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$passwordconfirm = mysql_real_escape_string($passwordconfirm);
$email = mysql_real_escape_string($email);
$firstname = mysql_real_escape_string($firstname);

//Inserting In to Table
$sql = "INSERT INTO login3 (username, password, confirmpass, email, firstname)
VALUES ($myusername, $mypassword, $passwordconfirm, $email, $firstname)";

?>

Shouldn't this be inserting all of the values into the table login3?

349

Answer

Solution:

You have not used a quotation mark for strings while inserting. Also you should use backticks. You should also use mysqli_* instead of mysql_* functions as they are deprecated. Also, there is no reason to store the confirmed password as @AndyIbanez has said, thus alter your table structure. You have not even queried the sql statement. Try this :-

$sql = "INSERT INTO `login3` (`username`, `password`, `email`,    
`firstname`)
VALUES ('$myusername', '$mypassword', '$email', '$firstname')"; 

$conn = new mysqli($host, $user, $password, $database);
if(!$conn->query($sql)){
    echo "ERROR : " . mysqli_error($conn);//this will display error while insering into the table
}
132

Answer

Solution:

Use this query

$sql = "INSERT INTO login3 ('username', 'password', 'confirmpass', 'email', 'firstname')
VALUES ('".$myusername."', '".$mypassword."', '".$passwordconfirm."', '".$email."', '".$firstname."')";

People are also looking for solutions to the problem: php - XPath query in an XPath query

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.