0
I have created a PHP file to store in my database but it displays nothing upon submit
it displays a blank page
19 Antworten
+ 1
that was what was displayed
+ 1
and the data is not stored in the database
0
What is the script in your file?
0
<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'e_cramer');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?>
<?php
if(isset($_POST["submit"])){
$firstname=$_POST['firstname'];
$surname=$_POST['surname'];
$username=$_POST['username'];
$pwd=$_POST['pwd'];
$cnf=$_POST['cnf'];
$gender=$_POST['gender'];
$dob=$_POST['dob'];
$country=$_POST['country'];
$email=$_POST['email'];
$tel=$_POST['tel'];
$address=$_POST['address'];
$bloodgroup=$_POST['bloodgroup'];
$sicklecell=$_POST['sicklecell'];
$history=$_POST['history'];
$firstname= mysqli_real_escape_string($db, $firstname);
$surname= mysqli_real_escape_string($db, $surname);
$username= mysqli_real_escape_string($db, $username);
$pwd= mysqli_real_escape_string($db, $pwd);
$pwd = md5($pwd);
$cnf= mysqli_real_escape_string($db, $cnf);
$gender= mysqli_real_escape_string($db, $gender);
$dob= mysqli_real_escape_string($db, $dob);
$country= mysqli_real_escape_string($db, $country);
$email= mysqli_real_escape_string($db, $email);
$tel= mysqli_real_escape_string($db, $tel);
$address= mysqli_real_escape_string($db, $address);
$bloodgroup= mysqli_real_escape_string($db, $bloodgroup);
$sicklecell= mysqli_real_escape_string($db, $sicklecell);
$history= mysqli_real_escape_string($db, $history);
0
//authenticate username, password & email
$sql = "SELECT username FROM registration WHERE username='$username'";
$result = mysqli_query($db,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
if(mysqli_num_rows($result) == 1){
echo "Sorry...This username already exist..";
}
else{
}
$sql = "SELECT pwd FROM registration WHERE pwd='$pwd'";
$result = mysqli_query($db,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
if(mysqli_num_rows($result) == 1){
echo "Sorry...password already exist..";
}
else{
}
$sql = "SELECT email FROM registration WHERE email='$email'";
$result = mysqli_query($db,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
if(mysqli_num_rows($result) == 1){
echo "Sorry...This email already exist..";
}
else{
}
$query = mysqli_query($db, "INSERT INTO 'registration'(firstname,surname,username,pwd,cnf,gender,dob,country,email,tel,address,bloodgroup,sicklecell,history)
VALUES('$firstname','$surname','$username','$pwd','$cnf','$gender','$dob','$country','$email','$tel','$address','$bloodgroup','$sicklecell','$history')");
if($query){
echo "Thank You! you are now registered.";
}
}
?>
0
$db->prepare("INSERT INTO users ("firstname", "username"... ) VALUES($firstname, $username... ) )->execute
0
you mean I should delete
$query = mysqli_query ($db,
0
and replace it with
$db->prepare (
0
Maybe but went I posted the message, your second message wasn't appear
0
so what's wrong with my codes now?
0
Try with prepare and execute by replacing "$
query = mysqli_query"
0
it didn't work
0
error appeared
0
Maybe because you write ->execute instead of ->execute()
0
on which line
0
there is no ->execute in my codes
0
$req = $db->prepare("INSERT INTO users SET username = ?, country = ?, gender= ?,... ");
$req->execute([$username,$country,$gender]);
Instead of:
$query = mysqli_query...
0
Ok let me try
0
Warning: mysqli_stmt::execute() expects exactly 0 parameters, 1 given in C:\xampp\htdocs\assar\database.php on line 81
Thank You! you are now registered.