Jump to content

PHP coding help


drakecai

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.