Jump to content

Recommended Posts

Well im making a website but I encountered some problems on my login script

here are my questions, how do you make a submit button (mine is register) redirect to another page?

Also how do you align or space out the buttons?

 

here is my script

 

<LINK REL="SHORTCUT ICON" HREF="./images/icon.ico">
<title>Welcome to LegacyZ</title>
<?php
include("config.php"); // Includes the db and form info.
session_start(); // Starts the session.
if ($_SESSION['logged'] == 1) { // User is already logged in.
header("Location: index.php"); // Goes to main page.
exit(); // Stops the rest of the script.
} else {
if (!isset($_POST['submit'])) { // The form has not been submitted.
	echo "<form action=\"login.php\" method=\"POST\">";
	echo "<table>";

	echo "<tr>";
	echo "<font color=\"#FFFFFF\">Username:<input name=\"username\" size=\"18\" type=\"text\" />";
	echo "</tr>";
	echo "<tr>";
	echo "<br><font color=\"#FFFFFF\">Password:<input name=\"password\" size=\"18\" type=\"password\" />";
	echo "</tr>";
	echo "<tr>";
	echo "<td colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"Login\"</td>";
	echo "<td colspan=\"2\"><input type=\"submit\" name=\"register\" value=\"Register\"</td>";
	echo "</tr>";
	echo "</table>";
	echo "</form>";
} else {
	$username = form($_POST['username']);
	$password = sha1($_POST['password']); // Encrypts the password.

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

	if ($r == 1) { // There is something in the db. The username/password match up.
		$_SESSION['logged'] = 1; // Sets the session.
		header("Location: index.php"); // Goes to main page.
		exit(); // Stops the rest of the script.
	} else { // Invalid username/password.
		exit("Incorrect username/password!");// Stops the script with an error message.
	}
}
}
mysql_close($db_connect); // Closes the connection.
?><style type="text/css">
<!--
body {
background-image: url(images/homeG.png);
margin-left: 400px;
margin-top: 275px;
}
-->
</style> 

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

Look at the action attribute of your form tag.

Also, <font> is depecrated and should not be used.

 

deprecated elements and how a form works is all found on w3schools within seconds.

 

[edit]

Reading your post again, you can't set different targets for an input submit, there is however the possibility of using a button .

Link to comment
https://forums.phpfreaks.com/topic/157292-php-coding-help/#findComment-830163
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.