I have a form and php code to register a user. It's not complete, but right now I'm trying to get the insert query to work and put the data entered from the form into the sqlite database. I've tried entering the data by puting the form variables in the insert query and just putting direct data into the query just to see if it would work and neither did. I can't figure out whats wrong. I've put a or die("query error") after the insert statement as well and that error came up. I've also tested to make sure the data is being saved in the variables and it is. I've echoed out "test" to check to see if the if($submit) was working and it is. In my file where i created my table I tested insert querys with data saved into variables and it worked. So I am really confused as to what the problem is. I would really appreciate it if someone could help me. My code is below.
<?php
//error_reporting (E_ALL ^ E_NOTICE);
echo "<h1>Register</h1>";
$submit = $_POST['submit'];
//$fullname = strip_tags($_POST['fullname']);
//$username = strtolower(strip_tags($_POST['username']));
//$password = strip_tags($_POST['password']);
//$repeatpassword = strip_tags($_POST['repeatpassword']);
if ($submit)
{
echo "test";
//echo "$fullname/$username/$password/$repeatpassword";
try {
$db = new PDO('sqlite:users.db');
} catch (Exception $e) {
die ($e);
}
$db->exec("INSERT INTO users (fullname,username,password) VALUES ('jack','jacky','green9')");
}
?>
<html>
<form action='register2.php' method='POST'>
<table>
<tr>
<td>
Your full name:
</td>
<td>
<input type='text' name='fullname' value='<?php echo $fullname; ?>'>
</td>
</tr>
<tr>
<td>
Choose a user name:
</td>
<td>
<input type='text' name='username' value='<?php echo $username; ?>' >
</td>
</tr>
<tr>
<td>
Choose a password:
</td>
<td>
<input type='password' name='password'>
</td>
</tr>
<tr>
<td>
Repeat your password:
</td>
<td>
<input type='password' name='repeatpassword'>
</td>
</tr>
</table>
<p>
<input type='submit' name='submit' value='Register'>
</form>
</html>
The code I use to make the database is
<?php
try {
$db = new PDO('sqlite:users.db');
} catch (Exception $e) {
die ($e);
}
$db->exec("CREATE TABLE users (id INTEGER PRIMARY KEY,
fullname TEXT, username TEXT, password TEXT)");
//$name = 'jacob funchion';
//$user = 'jfunchi';
//$password = 'green7';
//$db->exec("INSERT INTO users (fullname,username,password) VALUES ('$name','$user','$password')");
//$db->exec("INSERT INTO users (fullname,username,password) VALUES ('bob frank','bobby7','green1')");
?>