$DB_HOST = "localhost";
$DB_USER = "root";
$DB_PASSWORD = "";
$DB_NAME = "practice";
$conn = new mysqli($DB_HOST,$DB_USER,$DB_PASSWORD,$DB_NAME);
if ($conn->connect_errno) {
printf("Connect failed: %s\n", $conn->connect_error);
exit();
}else{
//printf("connected!!!");
}
function NewUser() {
$fullname = $_POST['name'];
$userName = $_POST['user'];
$email = $_POST['email'];
$password = $_POST['pass'];
$query = "INSERT INTO websiteusers (fullname,userName,email,pass) VALUES ('$fullname','$userName','$email','$password')";
$data = $conn->query($query);
if($data) { <br>
echo "YOUR REGISTRATION IS COMPLETED..."; <br>
}else{<br>
echo "something wrong!!!";<br>
}<br>
}
function SignUp() {
if(!empty($_POST['user'])){
$query1 = "SELECT userName,email";
$data1 = $conn->query($query1);
if($data1) {
NewUser();
} else {
echo "SORRY...YOU ARE ALREADY REGISTERED USER...";
}
}
}
if(!isset($_POST['submit'])) {
$result = $conn->query("SELECT * FROM websiteusers");
while ($row = $result->fetch_assoc()) {
printf ("%s (%s)\n", $row["userName"], $row["email"]);
}<br>
//SignUp();
}else{
SignUp();
}
?>
This is my PHP code for register but whenever i tried to register give me this error:
Notice: Undefined variable: conn in F:\Software\xampp\htdocs\LAB3\connectivity-sign-up.php on line 44
Fatal error: Call to a member function query() on null in
F:\Software\xampp\htdocs\LAB3\connectivity-sign-up.php on line 44 How to solve this problem? anyone please.
Aucun commentaire:
Enregistrer un commentaire