Can any of you geniuses help... im getting this error and cant think of a reason: Parse error: syntax error, unexpected $end in C:\Documents and Settings\Sol\My Documents\php\xampplite\htdocs\login3\register.php on line 50 heres the code: <?php // Connects to your Database mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("login2") or die(mysql_error()); //This code runs if the form has been submitted if (isset($_POST['submit'])) { //This makes sure they did not leave any fields blank if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) { die('You did not complete all of the required fields'); } // checks if the username is in use if (!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']); } $usercheck = $_POST['username']; $check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { die('Sorry, the username '.$_POST['username'].' is already in use.'); } // this makes sure both passwords entered match if ($_POST['pass'] != $_POST['pass2']) { die('Your passwords did not match.'); } // here we encrypt the password and add slashes if needed $_POST['pass'] = md5($_POST['pass']); if (!get_magic_quotes_gpc()) { $_POST['pass'] = addslashes($_POST['pass']); $_POST['username'] = addslashes($_POST['username']); } // now we insert it into the database $insert = "INSERT INTO users (username, password) VALUES ('".$_POST['username']."', '".$_POST['pass']."')"; $add_member = mysql_query($insert); ?> <h1>Registered</h1> <p>Thank you, you have registered - you may now login</a>.</p> some one please help!!!!!! cheers guys!!
Try this: <?php // Connects to your Database mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("login2") or die(mysql_error()); //This code runs if the form has been submitted if (isset($_POST['submit'])) { //This makes sure they did not leave any fields blank if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) { die('You did not complete all of the required fields'); } // checks if the username is in use if (!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']); } $usercheck = $_POST['username']; $check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { die('Sorry, the username '.$_POST['username'].' is already in use.'); } // this makes sure both passwords entered match if ($_POST['pass'] != $_POST['pass2']) { die('Your passwords did not match.'); } // here we encrypt the password and add slashes if needed $_POST['pass'] = md5($_POST['pass']); if (!get_magic_quotes_gpc()) { $_POST['pass'] = addslashes($_POST['pass']); $_POST['username'] = addslashes($_POST['username']); } // now we insert it into the database $insert = "INSERT INTO users (username, password) VALUES ('".$_POST['username']."', '".$_POST['pass']."')"; $add_member = mysql_query($insert); } ?> <h1>Registered</h1> <p>Thank you, you have registered - you may now login</a>.</p> PHP:
Parse error: syntax error, unexpected $end in C:\Documents and Settings\Sol\My Documents\php\xampplite\htdocs\login3\register.php on line 50 unexpected end
You don't have a table called users in the login2 database, you'll need to create that or alter the code to the correct table/db name
hi guys its me again, When i run the below i have the following error: Warning: Cannot modify header information - headers already sent by (output started at C:\Documents and Settings\Sol\My Documents\php\xampplite\htdocs\site.php:6) in C:\Documents and Settings\Sol\My Documents\php\xampplite\htdocs\site.php on line 66 can anyone help
btw heres the code lol: <html> <head> <title>Order Book System</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" href="css/styles.css" type="text/css"> <style type="text/css"> <!-- .style1 {color: #408080} .style3 {color: #00FFFF} .style10 {color: #CC0000} --> </style> </head> <body> <table width="775" border="0" align="center" cellpadding="0" cellspacing="0" height="140"> <tr> <td background="images/image1.jpg" class="logo style1" style="padding-left:30px"><p><img src="images/m3.jpg" width="151" height="111"><span class="style3">OrderBook Training</span></p></td> </tr> </table> <table width="775" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td bgcolor="#BFE1E7" width="200" valign="top" align="center"> <br> <table width="150" border="0" align="center" cellpadding="3" cellspacing="3" class="text"> <tr> <td><b><a href="#">About Us</a></b></td> </tr> <tr> <td><b><a href="#">Services</a></b></td> </tr> <tr> <td><b><a href="#">Products</a></b></td> </tr> <tr> <td><b><a href="#">Downloads</a></b></td> </tr> <tr> <td><b><a href="#">Contact Us</a></b></td> </tr> </table> <p> <?php // Connects to your Database mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("login2") or die(mysql_error()); //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) //if there is, it logs you in and directes you to the members page { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: members.php"); } } } //if the login form is submitted if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['username'] | !$_POST['pass']) { //header("Location: members.php"); die('You did not fill in a required fieldxczxczxczxc.'); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database.<a href=add.php>Click Here to Register</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); $_POST['pass'] = md5($_POST['pass']); //gives error if the password is wrong if ($_POST['pass'] != $info['password']) { die('Incorrect password, please try again.'); } else { // if login is ok then we add a cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['pass'], $hour); //then redirect them to the members area header("Location: members.php"); } } } else { // if they are not logged in ?> <form name="form2" method="post" action="login.php"> <table border="0"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?> </p> <p> </p></td> <td style="padding-left:25px; padding-right:25px; padding-top:25px; padding-bottom:25px" class="text" bgcolor="#FFFFFF"><span class="title">Welcome To Online Order Book Training</span> <p>OrderBook is a training service that provides students with notes and online quizes. Orderbook also enables you to study at your own pace and also in the comfort of your home. Signing up to orderbook plus will enable you to have a tutor who will guide you through the course and set up appointments to discuss your progress. Please click sign in (existing users) or register to register (new users) </p> <p><br> <a href="http://www.lunarpages.com/?id=webdotcom&campaign=tytempls" target="_blank"></a> </p> </td> </tr> <tr> <td bgcolor="#BFE1E7" valign="top" align="center"> </td> <td style="padding-left:25px; padding-right:25px; padding-top:25px; padding-bottom:25px" class="text" bgcolor="#FFFFFF"> </td> </tr> </table> <table width="775" border="0" align="center" cellpadding="0" cellspacing="0" height="30"> <tr> <td class="text" align="center" bgcolor="#D0ECF1">Designed by Solomon Arthur. All rights reserved. </td> </tr> </table> </body> </html>
You should really spend the few seconds it takes to comprehend the errors yourself, or you will never learn. I don't think the problem is with brackets or the script would bunk out without any processing. The issue is you are trying to do a header redirect but you have already output headers (Due to the HTML at the top of the page). You need to bring your PHP up above the html to do the processing before output. I am not going to post a cut-and-paste solution because if you can fix it yourself, then you will have learned something Also you should probably exit(); after the header();