Jump to content

Recommended Posts

I need to get this form to output something on the screen to let the user know the forms been successful. The sql and form work fine but once the submit button nothing is displayed onscreen indicating this. help please!

<?php
include("conf.inc.php"); // Includes the db and form info.
if (!isset($_POST['submit'])) { // If the form has not been submitted.
echo "<form action=\"register.php\" method=\"POST\">";
echo "<table>";
echo "<tr>";
echo "<td colspan=\"2\">Register:</td>";
echo "</tr>";
echo "<tr>";
echo "<td width=\"50%\">Username:</td><td width=\"50%\"><input name=\"username\" size=\"18\" type=\"text\" />";
echo "</tr>";
echo "<tr>";
echo "<td width=\"50%\">Password:</td><td width=\"50%\"><input name=\"password\" size=\"18\" type=\"text\" />";
echo "</tr>";
echo "<tr>";
echo "<td width=\"50%\">Email:</td><td width=\"50%\"><input name=\"email\" size=\"18\" type=\"text\" />";
echo "</tr>";
echo "<tr>";
echo "<td colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"submit\"</td>";
echo "</tr>";
echo "</table>";
echo "</form>";

} else { // The form has been submitted.
$username = form($_POST['username']);
$password = md5($_POST['password']); // Encrypts the password.
$email = form($_POST['email']);

if (($username == "") || ($password == "") || ($email == "")) { // Checks for blanks.
	exit("There was a field missing, please correct the form.");
}

$q = mysql_query("SELECT * FROM `users` WHERE username = '$username' OR email = '$email'") or die (mysql_error()); // mySQL Query
$r = mysql_num_rows($q); // Checks to see if anything is in the db.

if ($r > 0) { // If there are users with the same username/email.
	exit("That username/email is already registered!");
} else {
	mysql_query("INSERT INTO `users` (username,password,email) VALUES ('$username','$password','$email')") or die (mysql_error()); // Inserts the user.
}
}
mysql_close($db_connect); // Closes the connection.
?>

Link to comment
https://forums.phpfreaks.com/topic/155627-help/
Share on other sites

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.