drakecai Posted May 7, 2009 Share Posted May 7, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/157292-php-coding-help/ Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 1. The form's action attribute tells you what file to redirect to or better yet, what file to send the data to. 2. As for the buttons, use CSS. Quote Link to comment https://forums.phpfreaks.com/topic/157292-php-coding-help/#findComment-829036 Share on other sites More sharing options...
chmpdog Posted May 8, 2009 Share Posted May 8, 2009 look at w3schools.com. They have a good html lesson. I would recommend having a general knowledge of css & html before diving straight into php Quote Link to comment https://forums.phpfreaks.com/topic/157292-php-coding-help/#findComment-829093 Share on other sites More sharing options...
drakecai Posted May 9, 2009 Author Share Posted May 9, 2009 TY, I will go study some CSS and HTML. But can you guys just help me code the register button real quick to redirect to register.php? its really urgent so I need it done. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/157292-php-coding-help/#findComment-830160 Share on other sites More sharing options...
Axeia Posted May 9, 2009 Share Posted May 9, 2009 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 . Quote Link to comment https://forums.phpfreaks.com/topic/157292-php-coding-help/#findComment-830163 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.