Jump to content

PHP Parse error: syntax error, unexpected T_STRING


stockton

Recommended Posts

I keep getting the following error in what should be a very simple php/html piece of code:-
[error] PHP Parse error: syntax error, unexpected T_STRING in /var/www/htdocs/events/doc/Register.php on line 61

The code is as follows:-
<?php
// [a href=\"http://www.free2code.net/plugins/articles/read.php?id=99\" target=\"_blank\"]http://www.free2code.net/plugins/articles/read.php?id=99[/a]
require('db_connect.php'); // database connect script.
?>

<html>
<head>
<title>Register a User</title>
</head>
<!--#include virtual="includes/logo.inc"-->
<?php
if (isset($_POST['submit'])) { // if form has been submitted
if (!$_POST['uname'] | !$_POST['passwd'] | !$_POST['passwd_again'] | !$_POST['accesslevel']) {
die('You did not fill in a required field.');
}
// check if username exists in database.
if (!get_magic_quotes_gpc()) {
$_POST['uname'] = addslashes($_POST['uname']);
}
$name_check = $db_object->query("SELECT Usrname FROM Users WHERE Usrname = '".$_POST['uname']."'");
if (DB::isError($name_check)) {
$Message = $name_check->getMessage();
trigger_error(E_USER_ERROR, $Message);
}
$name_checkk = $name_check->numRows();
if ($name_checkk != 0) {
$Message = sprintf("Sorry, the username: %s is already taken, please pick another one.", $_POST['uname']);
trigger_error(E_USER_ERROR, $Message);
}
if ($_POST['passwd'] != $_POST['passwd_again']) {
$Message = "Passwords did not match.";
trigger_error(E_USER_ERROR, $Message);
}
$_POST['Surname'] = strip_tags($_POST['Surname']);
$_POST['FirstName'] = strip_tags($_POST['FirstName']);
$_POST['uname'] = strip_tags($_POST['uname']);
$_POST['passwd'] = strip_tags($_POST['passwd']);
$_POST['accesslevel'] = strip_tags($_POST['accesslevel']);
$_POST['passwd'] = md5($_POST['passwd']);
if (!get_magic_quotes_gpc()) {
$_POST['passwd'] = addslashes($_POST['passwd']);
}
$regdate = date('Y-m-d H:i:s');
$insert = $db_object->prepare("INSERT INTO Users (FirstName, LastName, Usrname, Passwrd, AccessLevel, last_login, U
serID)
VALUES ('".$_POST['FirstName']."',
'".$_POST['Surname']."',
'".$_POST['uname']."',
'".$_POST['passwd']."',
'".$_POST['accesslevel']."',
$regdate.,
1));
if (PEAR::isError($insert)) {
$Message = $insert->getMessage();
trigger_error(E_USER_ERROR, $Message);
}
$add_member = $db_object->execute($insert);
if (DB::isError($add_member)) {
$Message = $add_member->getMessage();
trigger_error(E_USER_ERROR, $Message);
}
// header("location: index.shtml");
// exit;
} else { // if form hasn't been submitted
?>
<!--#include virtual="includes/logo.inc"-->
<br><br>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table align="center" border="3" cellspacing="0" cellpadding="3">
<tr><td>First Name:</td>
<td><input type="text" name="FirstName" maxlength="20"></td></tr>
<tr><td>Surname:</td>
<td><input type="text" name="Surname" maxlength="40"></td></tr>
<tr><td>Username*:</td>
<td><input type="text" name="uname" maxlength="40"></td></tr>
<tr><td>Password*:</td>
<td><input type="password" name="passwd" maxlength="50"></td></tr>
<tr><td>Confirm Password*:</td>
<td><input type="password" name="passwd_again" maxlength="50"></td></tr>
<tr><td>Access Level*:</td>
<td><input type="text" name="accesslevel" maxlength="2"></td></tr>
<tr><td colspan="2" align="right">
<input type="submit" name="submit" value="Submit"></td></tr>
</table>
</form>

<?php
}
?>
</body>
</html>

and line 61 is // header("location: index.shtml"); which one can see is commented out.
I actually suspect the problem lies in the sql insert string but I cannot see it.
Please help.
Link to comment
Share on other sites

Your problem is in this statement:
[code]<?php
$insert = $db_object->prepare("INSERT INTO Users (FirstName, LastName, Usrname, Passwrd, AccessLevel, last_login, U
serID)
VALUES ('".$_POST['FirstName']."',
'".$_POST['Surname']."',
'".$_POST['uname']."',
'".$_POST['passwd']."',
'".$_POST['accesslevel']."',
$regdate.,
1));?>[/code]
There is no termininating double quote before the ending ")".

Ken
Link to comment
Share on other sites

Maybe this insert statement will solve the problem:
[code]
$insert = $db_object->prepare("INSERT INTO Users (FirstName, LastName, Usrname, Passwrd, AccessLevel, last_login, U
serID)
VALUES ('".$_POST['FirstName']."',
'".$_POST['Surname']."',
'".$_POST['uname']."',
'".$_POST['passwd']."',
'".$_POST['accesslevel']."',
'".$regdate.",
1'");
[/code]
Link to comment
Share on other sites

[!--quoteo(post=378687:date=May 31 2006, 02:34 PM:name=Honoré)--][div class=\'quotetop\']QUOTE(Honoré @ May 31 2006, 02:34 PM) [snapback]378687[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Maybe this insert statement will solve the problem:
[code]
$insert = $db_object->prepare("INSERT INTO Users (FirstName, LastName, Usrname, Passwrd, AccessLevel, last_login, U
serID)
VALUES ('".$_POST['FirstName']."',
'".$_POST['Surname']."',
'".$_POST['uname']."',
'".$_POST['passwd']."',
'".$_POST['accesslevel']."',
'".$regdate.",
1'");
[/code]
[/quote]

Thank you. It is always the little things that frustrate one.
However I fail to understand the single quote double quote combination. ie What does '" after the 1 mean?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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