问题
I am new to php so I used a Youtube tutorial to create this script, however the uploader seems to have disappeared so I cannot ask him any questions. My login form seems to work fine but the registration form is where I am having trouble
I have removed all html from code and all error else statements to try eliminate the error message but I cant seem to find it. Error always occurs at the end of my script.
Any suggestions
<?php
if ( $_POST['registerbtn'] ) {
//makes sure email, username is valid
$getuser = $_POST['user'];
$getemail = $_POST['email'];
$getpass = $_POST['pass'];
$getretypepass = $_POST['retypepass'];
if (!isset($getuser))
{
$error = "user not set ";
}
if ($getuser) {
if($getemail) {
if($getpass) {
if ($getretypepass) {
require("connection.php");
$query = mysql_query("SELECT * FROM users WHERE username ='$getuser'");
$numrows = mysql_num_rows($query);
if ($numrows == 0) {
$query = mysql_query("SELECT * FROM users WHERE email ='$getemail'");
$numrows = mysql_num_rows($query);
if ($numrows == 0) {
$password = md5(md5("19Dvdnj".$password."jndfFf20"));
$date = date("F d, Y");
$code = md5(rand());
mysql_query("INSERT INTO users VALUES ('', '$getuser', '$password', '$getmail', '0', '$code', '$date')");
$query = mysql_query("SELECT * FROM users WHERE username='$getuser'");
$numrows =mysql_num_rows($query);
if ($numrows == 1) {
$site ="http://www.inn.leedsmet.ac.uk/~c3314283/iis/register.php";
$webmaster = "admin@leedsmet.com";
$headers = "From: $webmaster";
$subject ="Activate your Account";
$message = "Thanks for registering. Click below to activate your account.\n";
$message .= "$site/activate.php?user=$getuser&code=$code";
$message .= "You must activate your account to login";
if (mail($getmail, $subject, $message, $headers)){
$errormsg = "You have been registered you must activate your account sent from the the activation link sent to<b>$getemail</b>";
$getuser = "";
$getemail = "";
}
mysql_close();
$form ="<form action='register.php' method='post'>
<table>
<tr>
<td></td>
<td><font color='red'>$errormsg</font></td>
</tr>
<tr>
<td>Username:</td>
<td><input type='text' name='user' value ='$getuser'/></td>
</tr>
<tr>
<td>Email:</td>
<td><input type='text' name='email' value ='$getemail'/></td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='pass' value =''/></td>
</tr>
<tr>
<td>Retype:</td>
<td><input type='password' name='retypepass' value =''/></td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='registerbtn' value ='Register'/></td>
</tr>
</table>
</form>";
{
echo $form;
}
?>
回答1:
Try autoformating (auto-indent) your code. If you do not have an editor that allows that, get one such as Sublime Text or Notepad++. :-) It will save you a lot of time in similar situations; instead of trying to locate the problem in such situations, after autoformating problems will stare you in the face. :-)
I believe you are missing around six closing braces }
(not sure I counted the number of unclosed if
s correctly) after the
{
echo $form;
}
Obviously if this is the case something terribly wrong has happened and it may take more than putting some }
s there to heal your code.
This could be a copy&paste problem. Maybe you did not copy the last few lines of the code you found in the Youtube tutorial you mention.
回答2:
Using any code editor with syntax highlighting (such as Notepad++) will clearly show you that you are missing a }
.
来源:https://stackoverflow.com/questions/13665831/parse-error-syntax-error-unexpected-end-for-my-uni-registration-assignment