JohnCooper Posted February 5, 2023 Share Posted February 5, 2023 (edited) Here is my "index.php" code: <!DOCTYPE html> <html lang="en"> <head> <meta charset = "UTF-8"> <meta name = "viewport" content="width=device-width,initial-scale=1.0"> <title>Registration Form</title> </head> <h1>Blood Donation Camp </h1> <body bgcolor="FBB917"> <div><h2>Registration Form</h2></div> <form action='connect.php' method="POST"> <label for="user">Name:</label><br> <input type="text" name="name" id="name" required/> <br><br> <label for="email">Email:</label><br> <input type="email" name="email" id="email" required/> <br><br> <label for="phone">Phone:</label><br> <input type="text" name="phone" id="phone" required/> <br><br> <label for="bgroup">Blood Group:</label><br> <input type="text" name="bgroup" id="bgroup" required/> <br><br> <input type="submit" name="submit" id="submit"> </form> </body> </html> Here is my "connect. php" code: <?php if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['submit'])) { $conn = mysqli_connect('localhost','root','','test1',3307) or die("Connection Failed!" .mysqli_connect_error()); if(isset($_POST['name']) && isset($_POST['email']) && isset($_POST['phone']) && isset($_POST['bgroup'])) { $name=$_POST['name']; $email=$_POST['email']; $phone=$_POST['phone']; $bgroup=$_POST['bgroup']; $sql="INSERT INTO 'users' ('name','email','phone','bgroup') VALUES ('$name','$email','$phone','$bgroup')"; $query = mysqli_query($conn,$sql); if($query) { echo "Entry Successful! <br>"; } else { echo "Error Occurred! <br>"; } } } ?> I change my default port of mysql database as 3307 and also change default port of Apache Web Server as 81. But I think there is no connection error as "Connection failed!" message doesn't show up. Only "Error Occurred!" message is appeared! Edited February 5, 2023 by JohnCooper Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted February 5, 2023 Solution Share Posted February 5, 2023 Remove the single quotes from around the tablename and column name identifiers. Quotes are for string literals. $sql="INSERT INTO 'users' ('name','email','phone','bgroup') VALUES ('$name','$email','$phone','$bgroup')"; ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ REMOVE Also, you should use a prepared statement instead of putting user-provided variables into your query. 1 Quote Link to comment Share on other sites More sharing options...
JohnCooper Posted February 5, 2023 Author Share Posted February 5, 2023 2 minutes ago, Barand said: Remove the single quotes from around the tablename and column name identifiers. Quotes are for string literals. $sql="INSERT INTO 'users' ('name','email','phone','bgroup') VALUES ('$name','$email','$phone','$bgroup')"; ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ REMOVE Also, you should use a prepared statement instead of putting user-provided variables into your query. Thanks,sir! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.