budder Posted April 19, 2010 Share Posted April 19, 2010 Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /login.php on line 33 Is it the variable $username that making the error? If so what to do? <?php session_start(); $dbHost = "s"; $dbUser = "u"; $dbPass = "u"; $dbDatabase = "t"; $db = mysql_connect($dbHost,$dbUser,$dbPass) or die("Unable to connect."); mysql_select_db($dbDatabase, $db) or die(mysql_error($db)); if (isset($_POST['username'])) { $username = trim($_POST['username']); } else { $username = ""; } if (isset($_POST['password'])) { $password = $_POST['password']; } else { $password = ""; } if (isset($_REQUEST['redirect'])) { $redirect = $_REQUEST['redirect']; } else { $redirect = "main.php"; } if (isset($_POST['submit'])) { $query = "SELECT USERNAME FROM site_user WHERE username='" . mysql_real_escape_string($username, $db) . "' AND password = password('" . mysql_real_escape_string($password, $db) . "') $result = mysql_query($query, $db) if (mysql_num_rows($result) > 0) { $_SESSION['username'] = $username; //Line 33 that makes the error. $_SESSION['logged'] = 1; header("Refresh: 5; URL=" . $redirect); echo "<p>Du vil blive sendt videre om 5 sekunder.</p>"; echo "<p>Hvis du ikke bliver sendt videre så klik <a href='" . $redirect . "'>her</a></p>"; die(); } else { $error = "<p>Du har angivet et forkert brugernavn eller kodeord. Prøv igen.</p>"; } } ?> <html> <head> <title>Login</title> </head> <body> <?php if (isset($error)) { echo $error; } ?> <form action="login.php" method"post"> <table> <tr> <td>Username:</td> <td><input type="text" name="username" maxlength="20" size="20" value="<?php echo $username; ?>" /> </td> </tr><tr> <td>Password:</td> <td><input type="password" maxlength="20" size="20" value="<?php $password; ?>" /></td> </tr><tr> <td> </td> <td> <input type="hidden" name="redirect" value="<?php echo $redirect ?>" /> <input type="submit" name="submit" value="login" /> </tr> </table> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/198994-parse-error/ Share on other sites More sharing options...
teamatomic Posted April 19, 2010 Share Posted April 19, 2010 The error is on your mysql_query line. HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/198994-parse-error/#findComment-1044508 Share on other sites More sharing options...
TeddyKiller Posted April 19, 2010 Share Posted April 19, 2010 mysql_real_escape_string($username, $db) I'm not too sure if that is possible? Quote Link to comment https://forums.phpfreaks.com/topic/198994-parse-error/#findComment-1044517 Share on other sites More sharing options...
budder Posted April 19, 2010 Author Share Posted April 19, 2010 Now the error have moved to the line above with the error: Parse error: syntax error, unexpected T_IF in login.php on line 32 Quote Link to comment https://forums.phpfreaks.com/topic/198994-parse-error/#findComment-1044520 Share on other sites More sharing options...
PFMaBiSmAd Posted April 19, 2010 Share Posted April 19, 2010 That's because there is also a missing "; on the line before the line teamatomic mentioned. Quote Link to comment https://forums.phpfreaks.com/topic/198994-parse-error/#findComment-1044521 Share on other sites More sharing options...
budder Posted April 19, 2010 Author Share Posted April 19, 2010 Excellent no problems now. The mysql_real_escape_string($username, $db) works with and without $db (: Quote Link to comment https://forums.phpfreaks.com/topic/198994-parse-error/#findComment-1044524 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.