I am a complete php beginner. My trainer dived into it without much explanation.
Other php questions in stackoverflow seems to follow some other syntax, so I'm confused.
Below are config.php and index.php files. Database name is practice in this code. Table name is fbsign. Trainer said values should be inserted into database but when I tried with table, it worked last time. This is driving me crazy for half a day. I don't know what I am doing wrong.
Also, does field name in the database and php code should be the same?
Q update: Yes, I did run the code. It says,'connected but not saved'? PS: I thought SOF is to help people. I wouldn't ask the question if I knew the answer.
<?php
$con=new mysqli('localhost','root','','practice') or die(mysqli_error());
if(!$con)
{
echo "not connected";
}
else
{
echo "connected";
}
?>
**index.php**
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>sign up form</title>
</head>
<body>
<div id="content">
<h2>Create an account</h2>
<p>It's free and always will be.</p>
<form name="signup" method="post" action=" ">
<table>
<tr>
<td><input type="text" name="fname" placeholder="first
name" /></td>
</tr>
<tr>
<td><input type="text" name="sname"
placeholder="surname" /></td>
</tr>
<tr>
<td><input type="numbers" name="mob" placeholder="mobile
number or email address" /></td>
</tr>
<tr>
<td><input type="password" name="pass" placeholder="new
password" /></td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Create
Account"/> </td>
</tr>
</table>
</form>
</div> <!-- end of content -->
</body>
</html>
<!-- start of php -->
<?php
include('config.php');
extract($_POST);
if(isset($submit))
{
$query="insert into fbsign values('$fname','$sname','$mob,'$pass')";
if($con->query($query))
{
echo "data saved";
}
else
{
echo "not saved";
}
}
?>