I am a newbie in web development and I have just installed xampp. The control panel show everything is fine. All the services are running.
I have created a database in mySQL using the phpMyAdmin and everything is fine with phpMyAdmin. I am trying to make a simple form which will make me able to add data in database table. My html form and php code are as follows. Both files are in htdocs folder:
form.html
<form action="signup.php" method="post">
Email: <input type="text" name="email"> <br>
Firstname: <input type="text" name="f_name"> <br>
Lastname: <input type="text" name="l_name"> <br>
Password: <input type="password" name="password"> <br>
Stream: <input type="text" name="stream"> <br>
<input type="submit">
</form>
</body>
</html>
signup.php:
$sql="INSERT INTO student (email,f_name,l_name,password,stream)
VALUES
('$_POST[email]','$_POST[f_name]','$_POST[l_name]','$_POST[password]','$_POST[stream]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>
When I click on the submit button in the form, my browser, Google Chrome, takes me to file:///C:/xampp/htdocs/signup.php and shows the contents of php script instead of running it.
If i manually enter into the address bar http://localhost/signup.php the script is executed and a record with all attributes blank is inserted into student table. So m conclusion is that php is running properly.
How to run the php script when I submit my form? Thanks :)
mysqlilike this still opens you up to SQL injection. Consider using prepared statements.