Jump to content

Recommended Posts

I have a problem with this code..  the mysql connection is working.  there's nothing appear in the browser why??

 

<?php 
//Set the page title and include the HTML header
$page_title = 'Register';

include ('./header.inc');

if (isset($_POST['submit'])) {// Handle the form.
   	$message = NULL; // Create an empty new variable.

   		//Check for a first name.
   		if (empty($_POST['first_name'])){
		$fn = FALSE;
		$message .= '<p>You forgot to enter your first name!</p>';
	} else {
		$fn = $_POST['first_name'];
	}

	//Check for a last name.
	if(empty($_POST['last_name'])) {
		$ln = FALSE;	
		$message .= '<p>You forgot to enter your last name!</p>';
	} else {
		$ln = $_POST['last_name'];
	}

	//Check for an email address.
	if(empty($_POST['email'])) {
		$e = FALSE;	
		$message .= '<p>You forgot to enter your email address!</p>';
	} else {
		$e = $_POST['email'];
	}

	//Check for an username.
	if(empty($_POST['username'])) {
		$u = FALSE;	
		$message .= '<p>You forgot to enter your username!</p>';
	} else {
		$u = $_POST['username'];
	}

	//Check for the password and match against the confirmed password.
	if (empty($_POST['password1'])) {
		$p = FALSE;
		$message .= '<p>You forgot to enter your password!</p>';
	} else {
		if ($_POST['password1'] == $_POST['password2']} {
			$p = $_POST['password1'];
		} else {
			$p = FALSE;
			$message .='<p>Your password did not match the confirmed password!</p>';
		}
	}

if ($fn && $ln && $e && $u && $p) {//if everything's ok.
	//Register the user in the database.
	require_once ('./mysql_connect.php'); //Connect to the db.

	//Make the query.
	$query = "INSERT INTO users (username, first_name, last_name, email, password, registration_date)
	          VALUES ('$u', '$fn', '$ln', '$e', PASSWORD('$p'), NOW() )";

	$result = @mysql_query ($query); //Run the query.

	if ($result) { // If it ran ok
		//Send an email, if desired.
		echo '<p><b>You have been registered!</b></p>';
		include ('./footer.inc'); // Include the HTML footer.
		exit(); //Quit the script.
	} else { // If it did not run ok.
		$message = '<p>You could not be registered due to a system error. We appologise for any inconvenience.</p><p>'.mysql_error() . '</p>';
	}

	mysql_close(); //Close the database connection.
} else {
	$message = '<p>Please try again.</P>';
}

} //End of the main Submit conditional.

//Print the message if there is one.
if (isset($message)) {
	echo '<font color="red">', $message, '</font>';
}

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<fieldset><legend>Enter your information in the form below:</legend>

<p><b>First Name:</b> <input type="text" name="first_name" size="15" maxlength="15"
Value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p>

<p><b>Last Name:</b> <input type="text" name="last_name" size="30" maxlength="30"
Value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p>

<p><b>Email Address:</b> <input type="text" name="email" size="40" maxlength="40"
Value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p>

        <p><b>User Name:</b> <input type="text" name="username" size="10" maxlength="20"
Value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" /></p>

<p><b>Password:</b> <input type="password" name="password1" size="20" maxlength="20" /></p>

<p><b>Confirm Password:</b> <input type="password" name="password2" size="20" maxlength="20" /></p>

</fieldset>

<div align="center"><input type="submit" name="submit" value="Register" /></div>
</form><!--End of Form-->

include ('./footer.inc');//Include the HTML footer.
?>

Link to comment
https://forums.phpfreaks.com/topic/69551-solved-php-html-n-mysql/
Share on other sites

The mysql connection works fine you say... okay but what should be printed to the screen? which part of the code? please post that so we can have a look at the specific code...

 

On the screen, below code will shows the text box for user to fill in. i want all input will be stored in a database by using mysql and php..  what's wrong with my codes? ..sorry i'm newbie to php.  :-\

 

<p><b>First Name:</b> <input type="text" name="first_name" size="15" maxlength="15"
Value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p>

<p><b>Last Name:</b> <input type="text" name="last_name" size="30" maxlength="30"
Value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p>

<p><b>Email Address:</b> <input type="text" name="email" size="40" maxlength="40"
Value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p>

        <p><b>User Name:</b> <input type="text" name="username" size="10" maxlength="20"
Value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" /></p>

<p><b>Password:</b> <input type="password" name="password1" size="20" maxlength="20" /></p>

<p><b>Confirm Password:</b> <input type="password" name="password2" size="20" maxlength="20" /></p>

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.