PHP MySQL not submitting or working

Home / Uncategorized / PHP MySQL not submitting or working

Question:
I have some PHP and HTML code which should send data from the form to my MySQL database. However, on clicking Submit in the form, the page reloads and nothing happens. No echo or anything. The HTML is in the same file as the PHP file.

PHP
setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO accounts (username, password)
VALUES (‘$usernamep’, ‘$passwordp’)";
// use exec() because no results are returned
$conn->exec($sql);
echo "Success";
}
catch(PDOException $e)
{
echo $sql . "
" . $e->getMessage();
}
$conn = null;
}
?>

HTML




Note: I know this code is currently subject to SQL injection, and the password is not encrypted. It is temporary starting code in an attempt to get it working first.


Answer:
You lack the name attribute in the submit button, add name="submit".




Read more

Leave a Reply

Your email address will not be published. Required fields are marked *