473,728 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parse error: syntax error, unexpected $end in...

mideastgirl
65 New Member
I keep getting this error and I cannot figure it out. My curly brackets are closed, and I am using the correct tags for <?php to open and ?> to close my code. Can someone please help me!

Here is my code:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. //Connect To Database
  3. $hostname='mideasthonors2.db.4381361.hostedresource.com';
  4. $username='**************';
  5. $password='***********';
  6. $dbname='mideasthonors2';
  7. $usertable='admin_tasks';
  8. $yourfield = 'Name';
  9.  
  10. mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
  11. mysql_select_db($dbname);
  12.  
  13. $query = 'SELECT * FROM $usertable';
  14. $result = mysql_query($query);
  15. if($result) {
  16.     while($row = mysql_fetch_array($result)){
  17.         $name = $row['$yourfield'];
  18.         echo 'Name: '.$name;
  19.  
  20. mysql_select_db("mideasthonors2");
  21.  
  22. $sql="INSERT INTO $usertable (Name, Address 1, Address 2, City, State, Zip Code, Website, Contact Name, Position, Phone Number, Email Address)
  23.  
  24. VALUES
  25.  
  26. {$_POST['name']},{$_POST['address 1']},{$_POST['address 2']},{$_POST['city']},{$_POST['state']},{$_POST['zip code']},{$_POST['website']},{$_POST['contact name']},{$_POST['position']},{$_POST['phone number']},{$_POST['email address']};
  27.  
  28. if (!mysql_query($sql,$con))
  29.  
  30.   {
  31.  
  32.   die('Error: ' . mysql_error());
  33.  
  34.   }
  35.  
  36. echo '1 record added';
  37.  
  38. mysql_close($con);
  39.     }
  40. }    
  41. ?>
Jun 23 '09
68 11163
mideastgirl
65 New Member
Thank you for your help. I deleted the start session at the top of this page and no error message came up, but it still will not go to the next page of admintasks.php which is where it should go to after logging in. Here is my script:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include("admin-dbcon.php");
  3.  
  4. //Check to see if the username and password is valid (if it is in the database)
  5. $validate = mysql_query("select * from admin_login where username = '$_POST[username]' and password = '$_POST[password]'"); 
  6.  
  7. $isvalid=mysql_num_rows($validate);
  8.  
  9. //if valid login send on, if not send to error page
  10. if ($isvalid != 0) {
  11.     $_SESSION['username'] = $_POST[username];
  12.     while ($row=mysql_fetch_array($validate)){
  13.         $_SESSION['userid']=$row["ID"];
  14.     }
  15.      header("Location: admintasks.php");
  16. //else {
  17. //    header("Location: login-error.php");
  18. //}
  19. ?>
Jun 25 '09 #11
mideastgirl
65 New Member
I am still getting an error message when I try to login from page www.mideasthonors.org/adminlogin.php this is the error I am receiving:

Warning: Cannot modify header information - headers already sent by (output started at /home/content/m/i/d/mideasthonors/html/adminloginproce ss.php:1) in /home/content/m/i/d/mideasthonors/html/adminloginproce ss.php on line 15
This is the code I am using:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include("admin-dbcon.php");
  3.  
  4. //Check to see if the username and password is valid (if it is in the database)
  5. $validate = mysql_query("select * from admin_login where username = '$_POST[username]' and password = '$_POST[password]'"); 
  6.  
  7. $isvalid=mysql_num_rows($validate);
  8.  
  9. //if valid login send on, if not send to error page
  10. if ($isvalid != 0) {
  11.     $_SESSION['username'] = $_POST[username];
  12.     while ($row=mysql_fetch_array($validate)){
  13.         $_SESSION['userid']=$row["ID"];
  14.     }
  15.      header("Location: admintasks.php");
  16. //else {
  17. //    header("Location: login-error.php");
  18. //}
  19. ?>
  20.  
Jun 25 '09 #12
code green
1,726 Recognized Expert Top Contributor
Cannot modify header information - headers already sent by
This generally means the browser has already output something or recieved HTML headers before receiving some header information.

I am not very experienced with header stuff but session_start must be called before any other output to the browser, including header().

What is admin-dbcon.php up to?

Just check you have no white space either side of <?php, this has got me a few times
Jun 25 '09 #13
mideastgirl
65 New Member
This is the code in admin-dbcon.php:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $dbHost = 'mideasthonors.db.4381361.hostedresource.com';
  3. $dbName = 'mideasthonors';
  4. $dbUser = 'xxx';
  5. $dbPass = 'xxx';
  6.  
  7. mysql_connect("$dbHost","$dbUser","$dbPass") or die("Error: Unable to connect to database! Please try again later.");
  8.  
  9. //Select the database we want to use
  10. mysql_select_db($dbName) or die("Error: Could not select database");
  11. ?>
  12.  
I have not opened a session in either one or a header at the top. So I will re-add session start () and see what happens
Jun 25 '09 #14
mideastgirl
65 New Member
I feel like code needs to be in adminlogin.php and admintasks.php to get the two to connect to the actual loginprocess.ph p page. I am trying to get from adminlogin.php to admintasks.php through a login process which is in loginprocess.ph p. The code to connect to mysql is in admin-dbcon.php...in other words, I feel like all five pages should be linked someone??? Maybe I am wrong...but I am literally only a week into all the php stuff and have looked up how to do what I have so far online. I really do appreciate the help you all are giving.
Jun 25 '09 #15
code green
1,726 Recognized Expert Top Contributor
Lets improve your code a bit to narrow down the problem
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. include("admin-dbcon.php"); 
  3.  
  4. //Check to see if the username and password is in database
  5. $username = $_POST['username']; 
  6. echo $username; #disable for header to work
  7. $password = $_POST['password'];  
  8. echo $password; #disable for header to work
  9.  
  10. $sql = "select * from admin_login 
  11.     where username = '$username' 
  12.     and password = '$password'";
  13. echo $sql; #disable for header to work
  14.  
  15. if($validate = mysql_query($sql))
  16. {  
  17.      $isvalid = mysql_num_rows($validate);
  18.      echo $isvalid; 
  19.  
  20.      //if valid login send on, if not send to error page 
  21.     if ($isvalid) 
  22.     { 
  23.        $_SESSION['username'] = $_POST[username]; 
  24.        while ($row=mysql_fetch_array($validate))
  25.        { 
  26.              $_SESSION['userid']=$row["ID"]; 
  27.        } 
  28.        print_r($_SESSION);#disable for header to work
  29.        //If everything is OK up to here un-comment header
  30.        #header("Location: admintasks.php"); 
  31.     } 
  32.    else 
  33.    { 
  34.      echo 'invalid login';
  35.      #header("Location: login-error.php"); 
  36.    } 
  37. }else echo 'empty recordset';
  38. ?> 
Jun 25 '09 #16
Atli
5,058 Recognized Expert Expert
Code_green is right there.
The header function, as well as any function that alters the HTTP headers, can't be called after you have started sending output.

Output being; echo calls, HTML before the <?php ?> block, white-spaces before the <?php ?> block... anything like that.

The reason for this, just to clarify, is that a HTTP response is composed of two parts; the headers and the content.
The headers must be sent before the contents, which is why you can not alter the headers after you start sending content.

P.S.
To reiterate my earlier point about SQL Injection.
The login script you posted there, where you put the $_POST values directly into the SQL query, is wide open for even a novice hacker.
Something as simple as passing ' or 1='1 as the password might be enough to log in using an invalid user-name.

mysql_real_esca pe_string - If your data hasn't been passed through this function, do not use it! (99% of the time, anyway)
Jun 25 '09 #17
mideastgirl
65 New Member
Unfortunately that did not go as planned:( I replaced the script with your suggestions and now my username and password are on the adminloginproce ss.php page:

usernamepasswor dselect * from admin_login where username = 'xxx' and password = 'xxx'1Array ( [username] => xxx [userid] => )

That was not exactly the desired result I was looking for, however I do appreciate all of your help!
Jun 26 '09 #18
code green
1,726 Recognized Expert Top Contributor
No! The code I posted is part of the debugging process.
It was to help you 'see' what is happening.
It hasn't a chance in hell of making your script 'work'.

You need to understand that you cannot keep hacking at a piece of code.
You have to take it apart, find out where it is going wrong then put it back together.

Nobody here is going to give you a completed script.
But we will help you overcome specific problems.

So the code supplied is demonstrating this process.
Are all the ecoed vales as expected?

Repeat what I have done in your other files.
Jun 26 '09 #19
mideastgirl
65 New Member
Atli,
You said that the _POST information should not be seen because it can be hacked into, but I am not really sure where this should go then? These are my database files, which will not actually be viewed by anyone because in theory when the user logs in it should either go to the error page or the admintasks page. I have been informed by the IT Department here on campus, where I am a student, to make sure I have database files where I keep these scripts. He has also suggested putting my login for the database in a seperate file, which I have done. I guess I am lost, because you are suggesting one thing while someone else is suggesting another.
Jun 26 '09 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2294
by: Janwillem Borleffs | last post by:
Q: I'm getting an unexpected $ or $end parse/syntax error, what's causing this? A: This is caused when an expression is started with an opening brace, but the closing brace is omitted. Examples: if ($condition) { .... // No closing brace; the error is thrown
8
46196
by: Wescotte | last post by:
The error message Parse error: syntax error, unexpected $end in FILE on line X is one I run into frequently and I know the cause is I missed an ending quote. Is there an easy way to determine where the inital " started? I find myself adding /* */ blocks or cutting/pasting sections of code out in order to find where the error occured. Wouldn't it it be nice if the warning message included the line in teh source where the initial quote ...
4
2196
mikeinspain
by: mikeinspain | last post by:
Keep getting this error! Parse error: syntax error, unexpected $end in /home/9144/domains/cbweb.co.uk/html/faq_finance.php on line 139 PHP Below.. Script was working 1 minute and copied the script from another file that was working great. elseif (!trim($name)) { echo "<p>Ooops!, it appears that you did not enter a Name</p><p><a href='javascript: history.go(-1)'>Click here to go back</a>.</p>"; }
4
22153
kestrel
by: kestrel | last post by:
I have some html code that is supposed to be displayed by php echo. But for some reason i keep getting a syntax error, and i cant figure out what is going on. Heres what i have <?php if(isset($_GET)) { echo "<div id="visible">"; echo "<span onclick="swapform()">Log In Form</span>"; echo "</div>"; echo "<div id="theform" style="visibility: hidden">";
5
10029
praclarush
by: praclarush | last post by:
I've just started php, and this is a class assignment, but my question is Iím getting this error PHP Parse error: syntax error, unexpected T_IF, expecting T_VARIABLE or '$' in C:\wamp\www\ssp\SSP04\guessingGame.php on line 42. Iíve tried to make sense of it but Iím at a lose, there error is referring to this segment of the code. else{ if(!isset($_GET)){ echo "<p>****</p>"; $guess = "****"; }//end if //declaring some...
9
4030
by: ajd335 | last post by:
Hi all... I am getting an error Parse error: syntax error, unexpected $end in http:/..... on line 117...(117 is the EOF).. can you plz help me out..I have checked out for the < , > ,{ ,} etc.... I donno where m wrong.... <?php class S_Shipping { // Private variables.
2
3226
by: Lawrence Krubner | last post by:
Imagine a template system that works by getting a file, as a string, and then putting it through eval(), something like this: $formAsString = $controller->command("readFileAndReturnString", $formName); // 06-22-07 - the next commands try to import all the functions that the
2
3242
by: fburn | last post by:
I need some help with an error I'm getting using php 5.2.5 running on linux. I receive an error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/html/inventoryControl/supplier.php on line 26 (line number changed to match code tags) The code is as follows: // get a supplier using the supplier id
9
3531
akohistani
by: akohistani | last post by:
I am having Parse error problem with my newly purchased Php upload script I have uploaded the script and I get the error below Parse error: syntax error, unexpected $end in URL/functions.php on line 400 Someone please help me I contacted the owner of the script where I purchased he is not replying me I bought it from http://www.scubadivingcalculators.com/ and this is the url where I have uploaded the script...
10
5665
by: benicio | last post by:
Parse error: syntax error, unexpected T_STRING, expecting '(' in C:\wamp\www\study_group\includes\functions.php on line 19 I got this error and this syntax is from 8 to 19th line. <?php $subject_set = get_all_subjects(); while ($subject = mysql_fetch_array($subject_set)) { echo "<li>{$subject}</li>"; $page_set = get_pages_for_subject($subject);
0
8894
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8753
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9188
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9122
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6704
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Duprť who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4522
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4787
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3230
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.