I have a registration form at http://mutualpay.byethost7.com/wp/register.php?i=1.. my form action is signup.php..i created the file but it doesnt seem to work at all, when i click the signup button it loads to http://mutualpay.byethost7.com/wp/signup.php?i=2 , its like it is not executing the codes in the file
Here is my signup.php code
<?php session_start(); include 'dpconfig.php';
$first = $_POST['firsts'];
$last = $_POST['last'];
$uid = $_POST['uid'];
$pwd = $_POST['pwd'];
if (empty($firsts)){
header("Location: register.php?error=empty");
exit();
}
if (empty($last)){
header("Location: register.php?error=empty");
exit();
}
if (empty($uid)){
header("Location: register.php?error=empty");
exit();
}
if (empty($pwd)){
header("Location: register.php?error=empty");
exit();
}
else {
$sql = "INSERT INTO user (firsts, last, uid, pwd)
VALUES ('$firsts', '$last', '$uid', '$pwd')";
$result = $conn->query($sql);
header("Location: index.php")
}
its like this code are not executed, cos after clicking on the signup button, it brings a blank page, I dont know what can be the cause, any help appreciated.Thanks
In the first empty-check you check an undefined variable ($firsts
). I guess you meant $first
, but php does not guess like we humans do.
change your code to
if (empty($first)){
edit: you could also merge those 4 empty-checks into one if, in order to have less code and better readability:
if (empty($first) || empty($last) || empty($uid) || empty($pwd)){
header("Location: register.php?error=empty");
exit();
}
The problem comes from your host, byet.
Byet uses an "antibot" system, which redirects you with javascript (mostly not executed by bots) to the same location and adding 1 to the i passed argument.
The problem is: the post arguments aren't passed when redirecting which mean that the $_POST var'll be empty.
Also check if isset($_POST['firsts'])
and for your passed arguments to the $_POST variable or it might create undefined var errors.