Arosha Mudalige Arosha Mudalige - 7 months ago 29
PHP Question

I have a database with primary key set to auto increment. But can't enter form data from a post method in php. Can anyone help me?

Here's the code. I have logins table in users database. Also a form whose action is set to below code.

if (isset($_POST['Full-name']) && isset($_POST['psd']) && isset($_POST['email'])) {
$link2 = @mysqli_connect('localhost', 'root', '') or die("Oops! Can't connect");
@mysqli_select_db($link2, 'users') or die("Can't find Database");
$fullname = $_POST['Full-name'];
$email2 = $_POST['email'];
$newpassword = $_POST['psd'];
echo $fullname.$email2.$newpassword; //print sucessfully

$query2 = mysqli_query($link2, "INSERT INTO logins VALUES (NULL, $email2, $newpassword)");
if ($query2) {
echo "You have signed up successfully";
} else {

echo "Error: "; //query prints this statement




You have to first remember that you have provide only 10 Character for username and 8 characters for password.

Even though if it is a varchar it will allow only 10 Charterers for Username and 8 Characters for Password and above that if you enter i am damp sure it will show you error wile inserting into the database.

Ensure updating or changing of the values that you provide for username and password in the database.

Note: By Chance if the user provided 11 Character for username and 8 Character for password too it will not be entering into the DB.

Cross Check: Try putting echo to the statement and exit the loop after that and you directly put the echoed query in MYSQL so that you can find the Error very Easy and rectify it as per the requirement you need.

And your query need to altered like this considering the id as auto-increment.

$query2 = mysqli_query($link2, "INSERT INTO logins(`username,password`) VALUES ('".$email2."', '".$newpassword."')");

Problem wasn't in the number of characters. But it was in the query.

$query2 = mysqli_query($link2, "INSERT INTO logins(`username,password`) VALUES ('".$email2."', '".$newpassword."')"); 

didn't worked. But replacing it with,

$query = "INSERT INTO logins(username,password) VALUES ('".$email2."', '".$newpassword."')";
$query2 = mysqli_query($link2, $query);