stockton Posted May 31, 2006 Share Posted May 31, 2006 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 61The 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"--><?phpif (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, UserID) 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. Quote Link to comment https://forums.phpfreaks.com/topic/10849-php-parse-error-syntax-error-unexpected-t_string/ Share on other sites More sharing options...
kenrbnsn Posted May 31, 2006 Share Posted May 31, 2006 Your problem is in this statement:[code]<?php $insert = $db_object->prepare("INSERT INTO Users (FirstName, LastName, Usrname, Passwrd, AccessLevel, last_login, UserID)VALUES ('".$_POST['FirstName']."','".$_POST['Surname']."','".$_POST['uname']."','".$_POST['passwd']."','".$_POST['accesslevel']."',$regdate.,1));?>[/code]There is no termininating double quote before the ending ")".Ken Quote Link to comment https://forums.phpfreaks.com/topic/10849-php-parse-error-syntax-error-unexpected-t_string/#findComment-40537 Share on other sites More sharing options...
Honoré Posted May 31, 2006 Share Posted May 31, 2006 Maybe this insert statement will solve the problem:[code]$insert = $db_object->prepare("INSERT INTO Users (FirstName, LastName, Usrname, Passwrd, AccessLevel, last_login, UserID)VALUES ('".$_POST['FirstName']."','".$_POST['Surname']."','".$_POST['uname']."','".$_POST['passwd']."','".$_POST['accesslevel']."','".$regdate.",1'");[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10849-php-parse-error-syntax-error-unexpected-t_string/#findComment-40542 Share on other sites More sharing options...
stockton Posted May 31, 2006 Author Share Posted May 31, 2006 [!--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, UserID)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? Quote Link to comment https://forums.phpfreaks.com/topic/10849-php-parse-error-syntax-error-unexpected-t_string/#findComment-40600 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.