Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hey, I am currently reading the book, and have made my own register form and php script.

There is no problems with the database connection, but it just will not insert information into the database.

The MySQL database is named 'test' and the table 'users'. The table has user_id, first_name, last_name, email, pass and registration_date columns.

here is the registration form:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body><link rel="stylesheet" type="text/css" href="style.css">
<form action="script4.php" method="post">
<p>First Name:<input type="text" name="first_name" /></p>
<p>Last Name:<input type="text" name="last_name" /></p>
<p>Email: <input type="text" name="email" /></p>
<p>Password: <input type="password" name="pass1" /></p>
<p>Confirm Password: <input type="password" name="pass2" /></p>
<input type="submit" name="submit" value="Submit!" />
</form>
</body>
</html>

and here is script4.php :

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<?php
$first_name = $_REQUEST['first_name'];
$last_name =  $_REQUEST['last_name'];
$email =      $_REQUEST['email'];
$pass1 =      $_REQUEST['pass1'];
$pass2 =      $_REQUEST['pass2'];

require ('mysql_connect.php');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
	$errors = array();}
if (!empty($_POST['first_name'])) {
	$errors[] = "You forgot to enter your first name!";
} else {
	$fn = trim($_POST['first_name']);
}
if (!empty($_POST['last_name'])) {
	$errors[] = "You forgot to enter your first name!";
} else {
	$ln = trim($_POST['last_name']);
}
if (!empty($_POST['email'])) {
	$errors[] = "You forgot to enter your first name!";
} else {
	$e = trim($_POST['email']);
}
if (!empty($_POST['pass1'])) {
if ($_POST['pass1'] != $_POST['pass2']) {
	$errors[] = "Your passwords do not match.";
} else {
	$p = trim($_POST['pass1']);}
}else {
	$errors[] = "You forgot to enter your password."; 
}
if (empty($errors)) {
require ('mysql_connect.php');
@mysqli_query("INSERT INTO users (first_name, last_name, email, pass, registration_date) 
VALUES($first_name, $last_name,$email, SHA1($pass), NOW() )");}


?>
</body>
</html>

Please can someone help me. 

I am using WAMP server by the way.

Share this post


Link to post
Share on other sites

Hello, and welcome to the forums.

 

Have you confirmed that the values stored in the $first_name, $last\Name, $email and $pass variables are what you are expecting?

Also, have you tried running a static query on the DB directly to see if that works?

  • Upvote 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...