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.
$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
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')";
// After user signs up they get sent to login page
// Log in is not automatic on signup.
echo "Please enter valid information!";
<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>
<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>
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.
Since you are doing this for a class, I am not going to give you the solution, just point you in the right direction. Look at what I underlined in red and blue, then look at the request method. Notice how your form is sending a GET request.
Now, look at your code where you define this request: <form action="post">
Then look at the documentation to see what you did wrong:
Thank you so much! I changed action to method and then not even 5 seconds later you responded. Anyway, now when I hit the submit button it stays on the page and displays my warning message. So hopefully I’ll be able to get it working from here. If not I’ll be back. But thank you for the help and the links I’ll try to check them out.