Lodius2000 Posted May 13, 2008 Share Posted May 13, 2008 so this script prints Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /hsphere/local/home/maddenbain/maddenbain.com/0/admin/index.php on line 64 line 64 reads print "Welcome, $_SESSION['username']"; i is the last real line of code also, if i try to comment off line 64 i get this error Parse error: syntax error, unexpected $end in /hsphere/local/home/maddenbain/maddenbain.com/0/admin/formhelpers.php on line 65 here is my code <?php session_start(); require_once ('../../../dbfiles/db_login.php'); require_once ('formhelpers.php'); if($_POST['_submit_check']){ if($form_errors = validate_form()){ show_form($form_errors); } else { process_form(); } } else { show_form(); } function show_form($errors = '') { if ($errors){ $error_text = '<ul><li>'; $error_text .= implode('</li><li>', $errors); $error_text .= '</li></ul>'; } else { $error_text =''; } print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">'; //begin the unique form print 'Username:'; input_text('username', $_POST); print '<br />'; print 'Password:'; input_password('password', $_POST); print '<br />'; input_submit('submit', 'Log In'); print '<input type="hidden" name="_submit_check" value="1" />'; print '</form>'; } function validate_form(){ global $db; $errors = array(); //is password valid? $encrypted_password = $db->getOne('SELECT password FROM users WHERE username = ?', array($_POST['username'])); if ($encrypted_password != crypt($_POST['password'], $encrypted_password)){ $errors[] = 'Please enter a valid password'; } return $errors; } function process_form(){ //add username to session $_SESSION['username'] = $_POST['username']; print "Welcome, $_SESSION['username']"; } ?> i thought that unexpected T_ENCAPSED_AND_WHITESPACE means you missed a quote or something somewhere but I cant find it help me out Thanks Link to comment https://forums.phpfreaks.com/topic/105378-yet-another-unexpected-t_encapsed_and_whitespace-error-help/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 13, 2008 Share Posted May 13, 2008 Unfortunately, the php parser needs help in figuring out where an array variable begins and ends inside of a double-quoted string. Use the curly-bracket/brace syntax - print "Welcome, {$_SESSION['username']}"; Once you fix this you will probably have an $end error as your next problem (edit: due to something in your require_once() files.) Link to comment https://forums.phpfreaks.com/topic/105378-yet-another-unexpected-t_encapsed_and_whitespace-error-help/#findComment-539699 Share on other sites More sharing options...
Lodius2000 Posted May 13, 2008 Author Share Posted May 13, 2008 thanks, I do have the $end error but now i at least know where to look Link to comment https://forums.phpfreaks.com/topic/105378-yet-another-unexpected-t_encapsed_and_whitespace-error-help/#findComment-539703 Share on other sites More sharing options...
Lodius2000 Posted May 13, 2008 Author Share Posted May 13, 2008 new question: fixed the $end error, but now when the script runs it is inserting a <br /> into the username and password fields, for some reason php is picking up <br /> as the value of both username and password her is the code for formhelpers.php <?php //print a text box function input_text($element_name, $values){ print '<input type="text" name="' . $element_name .'" value="'; print htmlentities($values[$element_name]) . '"/>'; } //print a password box function input_password($field_name, $values) { print '<input type="password" name="' . $field_name .'" value="'; print htmlentities($values[$field_name]) . '"/>'; } //print a submit button function input_submit($element_name, $label){ print '<input type="submit" name="' . $element_name .'" value="'; print htmlentities($label) . '"/>'; } //print a textarea function input_textarea($element_name, $values){ print '<textarea name="' . $element_name .'">'; print htmlentities($values[$element_name]) . '</textarea>'; } //print a radio button or checkbox function input_radiocheck($type, $element_name, $values, $element_value){ print '<input type="' . $type . '" name="' . $element_name . '" value="' . $element_value . '" '; if ($element_value == $values[$element_name]){ print ' checked="checked"'; } print '/>'; } //print a select menu function input_select($element_name, $selected, $options, $multiple = false){ //print out the <select> tag print '<select name="' . $element_name; // if multiple choices are permitted, add the multiple attribute // and add a [] to the end of the tag name if ($multiple){ print '[]" multiple="multiple'; } print '">'; //set up the list of things to be selected $selected_options = array(); if ($multiple) { foreach ($selected[$element_name] as $val){ $selected_options[$val] = true; } } else { $selected_options[ $selected[$element_name] ] = true; } //print out the <option> tags foreach ($options as $option=>$label) { print '<option value="' . htmlentities($option) . '"'; if ($selected_options[$option]){ print ' selected="selected"'; } print '>' . htmlentities($label) . '</option>'; } print '</select>'; } ?> and here is the code form a ctrl+U of the main script <br /> <b>Notice</b>: Undefined index: _submit_check in <b>/admin/index.php</b> on line <b>6</b><br /> <form method="POST" action="/0/admin/index.php">Username:<input type="text" name="username" value="<br /> <b>Notice</b>: Undefined index: username in <b>/admin/formhelpers.php</b> on line <b>5</b><br /> "/><br />Password:<input type="password" name="password" value="<br /> <b>Notice</b>: Undefined index: password in <b>/admin/formhelpers.php</b> on line <b>11</b><br /> "/><br /><input type="submit" name="submit" value="Log In"/><input type="hidden" name="_submit_check" value="1" /></form> thanks Link to comment https://forums.phpfreaks.com/topic/105378-yet-another-unexpected-t_encapsed_and_whitespace-error-help/#findComment-539706 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.