I have written a very basic HTML sign-up form:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Registration</title>
</head>
<body>
<form name="reg" action="code_exec.php" onsubmit="return validateForm()" method="post">
<table width="274" border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<td colspan="2">
<div align="center">
<?php
// $remarks=$_GET['remarks'];
if (!isset($_GET['remarks']))
{
echo 'Register Here';
}
if (isset($_GET['remarks']) && $_GET['remarks']=='success')
{
echo 'Registration Success';
}
?>
</div></td>
</tr>
<tr>
<td width="95"><div align="right">First Name:</div></td>
<td width="171"><input type="text" name="fname" /></td>
</tr>
<tr>
<td><div align="right">Last Name:</div></td>
<td><input type="text" name="lname" /></td>
</tr>
<tr>
<td><div align="right">Gender:</div></td>
<td><input type="text" name="gender" /></td>
</tr>
<tr>
<td><div align="right">Address:</div></td>
<td><input type="text" name="address" /></td>
</tr>
<tr>
<td><div align="right">Contact No.:</div></td>
<td><input type="text" name="contact" /></td>
</tr>
<tr>
<td><div align="right">Username:</div></td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td><div align="right">Password:</div></td>
<td><input type="text" name="password" /></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><input name="submit" type="submit" value="Submit" /></td>
</tr>
</table>
</form>
</body>
</html>
I am using PHP to connect my HTML page to a MySQL database on XAMPP server installed/configured locally.
I have divided my connection, and data storage logic across 2 different .php
files:
connection.php
<?php
$mysql_hostname = "localhost";
$mysql_user = "amitesh";
$mysql_password = "amitesh";
$mysql_database = "sign_up_form";
$prefix = "";
$bd = mysqli_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Could not connect database");
mysqli_select_db($mysql_database,$bd) or die("Could not select database");
?>
code_exec.php
<?php
session_start();
include('connection.php');
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$mname=$_POST['mname'];
$address=$_POST['address'];
$contact=$_POST['contact'];
$username=$_POST['username'];
$password=$_POST['password'];
mysqli_query($bd, "INSERT INTO member(fname, lname, gender, address, contact, username, password)VALUES('$fname', '$lname', '$mname', '$address', '$contact','$username', '$password')");
header("location: index.php?remarks=success");
mysqli_close($bd);
After I insert data in the page, when I click on the "submit" button, it shows me the code of the code_exec.php
file instead of storing the data in MySQL.
I did see couple of StackOverflow posts about this, but none of them seem to offer a working solution for my problem.
Why could this be happening?