Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Programming Languages
PHP
Registration Form
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="strawbs, post: 5174949, member: 85255"] i'm trying to create a registration form for users to register on our site? basically i've created this script [CODE] <?php // Check if the form was submitted if ($_SERVER["REQUEST_METHOD"] == "POST") { // Get form data and sanitize inputs $yourname = filter_input(INPUT_POST, "yourname", FILTER_SANITIZE_STRING); $lastname = filter_input(INPUT_POST, "lastname", FILTER_SANITIZE_STRING); $username = filter_input(INPUT_POST, "username", FILTER_SANITIZE_STRING); $email = filter_input(INPUT_POST, "email", FILTER_SANITIZE_EMAIL); $password = $_POST["password"]; // Validate inputs if (empty($yourname) || empty($lastname) || empty($username) || empty($email) || empty($password)) { echo "Please fill in all fields."; } else { // Hash the password (ensure you have proper hashing and salting) $hashedPassword = password_hash($password, PASSWORD_DEFAULT); // Database connection settings $servername = "my_server_name"; // Replace with your actual server name $connection_username = "my_username"; // Replace with your actual database username $connection_password = "my_password"; // Replace with your actual database password $dbname = "my_database_name"; // Replace with your actual database name // Create connection $conn = new mysqli($servername, $connection_username, $connection_password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Prepare and bind the SQL statement to prevent SQL injection $stmt = $conn->prepare("INSERT INTO users (yourname, lastname, username, email, password) VALUES (?, ?, ?, ?, ?)"); $stmt->bind_param("sssss", $yourname, $lastname, $username, $email, $hashedPassword); if ($stmt->execute()) { echo "Registration successful!"; } else { echo "Error: " . $stmt->error; } // Close the connection $stmt->close(); $conn->close(); } } ?> [/CODE] now i've been getting alot of help from a friend of mine(OpenAi.com) i've tested the form and the form information isn't going into my database(phpmyadmin) i have setup tables for each column but don't know what's going on i have html here as well [CODE] <!DOCTYPE html> <html> <head> <title>Registration Form</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> </head> <body> <h4> <span class="boldp_line"><span></span></span> <span class="solid_line"></span> <a href="#" class="title_text">Register</a> </h4> <form id="registrationForm" method="post"> yourname: <input type="text" name="yourname"><br> lastname: <input type="text" name="lastname"><br> username: <input type="text" name="username"><br> email: <input type="email" name="email"><br> password: <input type="password" name="password"><br> <input type="submit" value="Register"> </form> <div id="responseMessage"></div> <script> $(document).ready(function() { $("#registrationForm").submit(function(event) { event.preventDefault(); $.ajax({ url: "form.php", // Update this to match the correct PHP script filename method: "POST", data: $(this).serialize(), success: function(response) { $("#responseMessage").html(response); } }); }); }); </script> </body> </html> [/CODE] could someone please tell me where i'm going wrong? i'v obviously set in the php code as my username ect but i have the rite database credentials [/QUOTE]
Verification
Post reply
Forums
Programming Languages
PHP
Registration Form
Top