I am having issues connecting php to mysql. I don’t really know what I am doing in the first place but I need to make a signup page that will send the user’s data to my database but I can’t seem to get it working.
Here is connection.php. I removed my credentials.
<?php
$dbhost = "sql201.epizy.com";
$dbuser = "";
$dbpass = "";
$dbname = "";
if (!$con = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname))
{
die ("Failed to connect to database!");
}
?>
Here is my signup.php
<?php
session_start();
include("connection.php");
include("functions.php");
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$city = $_POST['city'];
$zip = $_POST['zip'];
$password = $_POST['password'];
if (!empty($first_name) && !empty($last_name) && !empty($email) && !empty($address) && !empty($city) && !empty($state) && !empty($zip) && !empty($password))
{
$user_id = random_num(20);
$query = "insert into users (user_id, first_name, last_name, email, phone, address, city, state, zip, password) values ('$user_id', '$first_name', '$last_name', '$email', '$phone', '$address', '$city', '$state', '$zip', '$password')";
mysqli_query($con, $query);
// After user signs up they get sent to login page
// Log in is not automatic on signup.
header("Location: login.php");
die;
}
else
{
echo "Please enter valid information!";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel='stylesheet' href='http://raeridinglessons.infinityfreeapp.com/login.css'>
<title>Rae Riding Lessons | Signup</title>
</head>
<body>
<div id="box">
<form action="post">
<div style="font-size: 20px; margin: 10px">Signup</div>
First Name<input id="text" type="text" name="first_name"><br><br>
Last Name<input id="text" type="text" name="last_name"><br><br>
Email<input id="text" type="text" name="email"><br><br>
Phone<input id="text" type="text" name="phone"><br><br>
Street Address<input id="text" type="text" name="address"><br><br>
City<input id="text" type="text" name="city"><br><br>
State<input id="text" type="text" name="state"><br><br>
Zip<input id="text" type="text" name="zip"><br><br>
Password<input id="text" type="text" name="password"><br><br>
<input id="button" type="submit" value="Signup"><br><br>
<a href="login.php">Already have an Acount?</a><br><br>
</form>
</div>
</body>
</html>
Again I don’t really know how to do any of this so I have been following YouTube videos to set things up. And according to the video when I press the “Sign up” button it should submit the users data to the database and then got to the login.php page but it just takes me to a infinityfree 404 page and the data doesn’t get inserted into the database.
Any help is appreciated. Just let me know if you need more information.
Thank you!