Jump to content


Photo

PHP Parse error: syntax error, unexpected T_STRING


  • Please log in to reply
3 replies to this topic

#1 stockton

stockton
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts
  • LocationMidrand South Africa

Posted 31 May 2006 - 12:13 PM

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.
Regards,
Alf Stockton   Programmer for rent.

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 31 May 2006 - 12:19 PM

Your problem is in this statement:
<?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));?>
There is no termininating double quote before the ending ")".

Ken

#3 Honoré

Honoré
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts
  • LocationAntwerp - Belgium

Posted 31 May 2006 - 12:34 PM

Maybe this insert statement will solve the problem:
$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'");


#4 stockton

stockton
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts
  • LocationMidrand South Africa

Posted 31 May 2006 - 03:45 PM

[!--quoteo(post=378687:date=May 31 2006, 02:34 PM:name=Honoré)--][div class=\'quotetop\']QUOTE(Honoré @ May 31 2006, 02:34 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Maybe this insert statement will solve the problem:
$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'");
[/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?
Regards,
Alf Stockton   Programmer for rent.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users