FarhanKhalaf Posted April 18, 2009 Share Posted April 18, 2009 Hey guys...first post here - pretty new to PHP. I have the following code, which is yielding me an unexpected #end . Usually I expect this to be a missing bracket, however I scanned multiple times and could not find it, AND I have the same second half of the code on another page and works just fine. Perhaps my eyes are not seeing something, any help would be great. Thanks. <?php include "base.php"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="en"> <!-- google_ad_section_start(weight=ignore) --> <head> <title>blahblah</title> <link rel="stylesheet" type="text/css" href="style.css"> <link rel="stylesheet" href="loginstyle.css" type="text/css" /> </head> <body> <?php /*test */ echo "$_SESSION[itemnum2]"; ?> <div id="header"> <h1 class="logo"><a href="index.php"><span class="emp"></span></h1></a> <ul class="navlist"> <?php if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username'])) { echo "<li class='cart'><a href='logout.php'>Logout</a></li>"; } ?> <li class="tour"><a href="#">Take the tour</a></li> <?php $username = $_SESSION['Username']; if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username'])) { echo "<li class='myaccount'><a href='MyAccount.php'>$username</a>"; } else { echo "<li class='login'><a href='login2.php'>Join now / Login</a></li>"; } ?> </ul> </div> <div id="container"> <div id="summary"> <p class="tagline">Never pay retail again, ever.</p> <br /> <p class="description">discount. </p> <a href="register2.php"><img class="homebutton" src="JoinNow.png"></a> </div> <div id="about"> <div id="topleft"> <span class="tagline2">Shopper Sign Up</span> </div> <?php if(!empty($_POST['username']) && !empty($_POST['password'])) { $username = mysql_real_escape_string($_POST['username']); $password = md5(mysql_real_escape_string($_POST['password'])); $email = mysql_real_escape_string($_POST['email']); $checkusername = mysql_query("SELECT * FROM users WHERE Username = '".$username."'"); if(mysql_num_rows($checkusername) == 1) { echo "<div id='shopperlogin'><p>Sorry, that username is taken.<br /> Please go back and try again.</p></div>"; } else { $registerquery = mysql_query("INSERT INTO users (Username, Password, EmailAddress) VALUES('".$username."', '".$password."', '".$email."')"); if($registerquery) { //test if(!empty($_POST['username']) && !empty($_POST['password'])) { $username = mysql_real_escape_string($_POST['username']); $password = md5(mysql_real_escape_string($_POST['password'])); $checklogin = mysql_query("SELECT * FROM users WHERE Username = '".$username."' AND Password = '".$password."'"); if(mysql_num_rows($checklogin) == 1) { $row = mysql_fetch_array($checklogin); $email = $row['EmailAddress']; $_SESSION['Username'] = $username; $_SESSION['EmailAddress'] = $email; $_SESSION['LoggedIn'] = 1; /*test*/ $_SESSION['itemnum2'] = $_SESSION['itemnum2']; echo "<big>Success</big><br />"; echo "<p>Continue with your oder below.</p>"; //test - create entry (add sql...) if ($_SESSION["itemnum2"]!=null) echo '<b>Item Number: </b>'.$_SESSION["itemnum2"]; ?> <?php if ($_POST["itemtype"]!=null) echo '<br /><b>Item Type: </b>'.$_POST["itemtype"]; ?> <?php if ($_POST["box"]!=null) echo '<br /><b>Item Size: </b>'.$_POST["box"]; ?> <?php if ($_POST["box2"]!=null) echo '<br /><b>Waist Size: </b>'.$_POST["box2"]; ?> <?php if ($_POST["box25"]!=null) echo '<br /><b>Length Size: </b>'.$_POST["box25"]; ?> <?php if ($_POST["box3"]!=null) echo '<br /><b>Sneaker Size: </b>'.$_POST["box3"]; ?> <?php if ($_POST["box4"]!=null) echo '<br /><b>Ladys Top Size: </b>'.$_POST["box4"]; ?> <?php if ($_POST["box5"]!=null) echo '<br /><b>Ladys Dress Size: </b>'.$_POST["box5"]; ?> <?php if ($_POST["box6"]!=null) echo '<br /><b>Ladys Bottom Size: </b>'.$_POST["box6"]; ?> <?php if ($_POST["box7"]!=null) echo '<br /><b>Ladys Shoe Size: </b>'.$_POST["box7"]; ?> <?php if ($_POST["box8"]!="Specify...") echo '<br /><b>Accessory / Other: </b>'.$_POST["box8"]; ?> <?php if ($_POST["itemcolor"]!=null) echo '<br /><b>Item Color: </b>'.$_POST["itemcolor"]; $con = mysql_connect("localhost","retai13_me","password"); //Replace with your actual MySQL DB Username and Password if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("retai13_employeediscounted", $con); //Replace with your MySQL DB Name $customer = mysql_query("SELECT UserID FROM users WHERE Username = '".$username."'"); if(mysql_num_rows($customer) == 1) { $get = mysql_fetch_array($customer); $ShopperID = $get['UserID']; } if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username'])) { $sql="INSERT INTO nordstromlisting (ShopperID,itemnum,itemtype,itemsize,waistsize,lengthsize,sneakersize,ladystopsize,ladysdresssize,ladysbottomsize,ladysshoesize,other,itemcolor) VALUES ('$ShopperID','$itemnum','$itemtype','$box','$box2','$box25','$box3','$box4','$box5','$box6','$box7','$box8','$itemcolor')"; /*form_data is the name of the MySQL table where the form data will be saved. name and email are the respective table fields*/ } if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "<br />You have successfully created a listing."; mysql_close($con) ?> <div id="footer"> <ul class="foot"> <li><a href="#">About</a></li> <li><a href="#">Blog</a></li> <li><a href="#">Contact</a></li> <li><a href="#">Terms of Service</a></li> </ul> </div> <!-- google_ad_section_end --> </body> </html> And, I already have the following portion of code on another page - and it works fine : if ($_SESSION["itemnum2"]!=null) echo '<b>Item Number: </b>'.$_SESSION["itemnum2"]; ?> <?php if ($_POST["itemtype"]!=null) echo '<br /><b>Item Type: </b>'.$_POST["itemtype"]; ?> <?php if ($_POST["box"]!=null) echo '<br /><b>Item Size: </b>'.$_POST["box"]; ?> <?php if ($_POST["box2"]!=null) echo '<br /><b>Waist Size: </b>'.$_POST["box2"]; ?> <?php if ($_POST["box25"]!=null) echo '<br /><b>Length Size: </b>'.$_POST["box25"]; ?> <?php if ($_POST["box3"]!=null) echo '<br /><b>Sneaker Size: </b>'.$_POST["box3"]; ?> <?php if ($_POST["box4"]!=null) echo '<br /><b>Ladys Top Size: </b>'.$_POST["box4"]; ?> <?php if ($_POST["box5"]!=null) echo '<br /><b>Ladys Dress Size: </b>'.$_POST["box5"]; ?> <?php if ($_POST["box6"]!=null) echo '<br /><b>Ladys Bottom Size: </b>'.$_POST["box6"]; ?> <?php if ($_POST["box7"]!=null) echo '<br /><b>Ladys Shoe Size: </b>'.$_POST["box7"]; ?> <?php if ($_POST["box8"]!="Specify...") echo '<br /><b>Accessory / Other: </b>'.$_POST["box8"]; ?> <?php if ($_POST["itemcolor"]!=null) echo '<br /><b>Item Color: </b>'.$_POST["itemcolor"]; $con = mysql_connect("localhost","retai13_me","password"); //Replace with your actual MySQL DB Username and Password if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("retai13_employeediscounted", $con); //Replace with your MySQL DB Name $customer = mysql_query("SELECT UserID FROM users WHERE Username = '".$username."'"); if(mysql_num_rows($customer) == 1) { $get = mysql_fetch_array($customer); $ShopperID = $get['UserID']; } if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username'])) { $sql="INSERT INTO nordstromlisting (ShopperID,itemnum,itemtype,itemsize,waistsize,lengthsize,sneakersize,ladystopsize,ladysdresssize,ladysbottomsize,ladysshoesize,other,itemcolor) VALUES ('$ShopperID','$itemnum','$itemtype','$box','$box2','$box25','$box3','$box4','$box5','$box6','$box7','$box8','$itemcolor')"; /*form_data is the name of the MySQL table where the form data will be saved. name and email are the respective table fields*/ } if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "<br />You have successfully created a listing."; mysql_close($con) ?> Once again...pretty new to this - so bare with me! Link to comment https://forums.phpfreaks.com/topic/154614-warning-unexpected-end/ Share on other sites More sharing options...
laffin Posted April 18, 2009 Share Posted April 18, 2009 Rule #1 RTFM Rule #2 Indent U cant figure out the balance of parens cuz they all over the place http://www.phpformatter.com/ This should help if yer editor dun indent for u Link to comment https://forums.phpfreaks.com/topic/154614-warning-unexpected-end/#findComment-813027 Share on other sites More sharing options...
FarhanKhalaf Posted April 18, 2009 Author Share Posted April 18, 2009 I appreciate your advice laffin, however if you can point out where the bracket is missing I will be able to figure out how to better reformat my brackets. Thanks... Link to comment https://forums.phpfreaks.com/topic/154614-warning-unexpected-end/#findComment-813046 Share on other sites More sharing options...
laffin Posted April 18, 2009 Share Posted April 18, 2009 Thats wut the link was for, the link formats yer code for u once u have it formatted, it should be pretty easy to spot where the unbalanced paren is. Link to comment https://forums.phpfreaks.com/topic/154614-warning-unexpected-end/#findComment-813048 Share on other sites More sharing options...
FarhanKhalaf Posted April 18, 2009 Author Share Posted April 18, 2009 Ugh, I tried formatting it and looked all over and I just can't figure it out. I'm usually good at spotting brackets. What's throwing me off is that everything works just fine with the following code (reference above) <?php if ($_POST["box8"]!="Specify...") echo '<br /><b>Accessory / Other: </b>'.$_POST["box8"]; ?> <?php if ($_POST["itemcolor"]!=null) echo '<br /><b>Item Color: </b>'.$_POST["itemcolor"]; //test //test } else { echo "<div id='shopperlogin'><p>Sorry, your account could not be found.<br /> Please <a href=\"login2.php\"><b>click here to try again</b></a>.</p></div>"; } } else { ?> However, when I add the exact following in between //test ---- //test I get that error. $con = mysql_connect("localhost", "retai13_db", "pw"); if (!$con) { die('Could not connect: ' . mysql_error()); } //Replace with your MySQL DB Name mysql_select_db("retai13_db", $con); $customer = mysql_query("SELECT UserID FROM users WHERE Username = '" . $username . "'"); if (mysql_num_rows($customer) == 1) { $get = mysql_fetch_array($customer); $ShopperID = $get['UserID']; } //This value has to be the same as in the HTML form file $itemnum = mysql_real_escape_string($_POST['itemnum']); $itemtype = mysql_real_escape_string($_POST['itemtype']); $box = mysql_real_escape_string($_POST['box']); $box2 = mysql_real_escape_string($_POST['box2']); $box25 = mysql_real_escape_string($_POST['box25']); $box3 = mysql_real_escape_string($_POST['box3']); $box4 = mysql_real_escape_string($_POST['box4']); $box5 = mysql_real_escape_string($_POST['box5']); $box6 = mysql_real_escape_string($_POST['box6']); $box7 = mysql_real_escape_string($_POST['box7']); $box8 = mysql_real_escape_string($_POST['box8']); $itemcolor = mysql_real_escape_string($_POST['itemcolor']); if (!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username'])) { $sql = "INSERT INTO nordstromlisting (ShopperID,itemnum,itemtype,itemsize,waistsize,lengthsize,sneakersize,ladystopsize,ladysdresssize,ladysbottomsize,ladysshoesize,other,itemcolor) VALUES ('$ShopperID','$itemnum','$itemtype','$box','$box2','$box25','$box3','$box4','$box5','$box6','$box7','$box8','$itemcolor')"; /*form_data is the name of the MySQL table where the form data will be saved. name and email are the respective table fields*/ } if (!mysql_query($sql, $con)) { die('Error: ' . mysql_error()); } echo "<br />You have successfully created a listing."; mysql_close($con) Everything seems just fine in that latter piece of code...what gives then? I'm not one to usually pester for answers. I usually look around google and find it out myself, but I'm stumped. Thanks again. Link to comment https://forums.phpfreaks.com/topic/154614-warning-unexpected-end/#findComment-813064 Share on other sites More sharing options...
mrMarcus Posted April 18, 2009 Share Posted April 18, 2009 for starters, this is a mess : if ($_SESSION["itemnum2"]!=null) echo '<b>Item Number: </b>'.$_SESSION["itemnum2"]; ?> <?php if ($_POST["itemtype"]!=null) echo '<br /><b>Item Type: </b>'.$_POST["itemtype"]; ?> <?php if ($_POST["box"]!=null) echo '<br /><b>Item Size: </b>'.$_POST["box"]; ?> you don't need to use all those <?php ?> tags, just adds so much unnecessary stuff to look at. as long as it's all PHP, you just need your opening tag at the beginning of the script, and a closing at the end. you are missing two (2) closing (end) brackets in here. if(!empty($_POST['username']) && !empty($_POST['password'])) { //no end bracket; $username = mysql_real_escape_string($_POST['username']); $password = md5(mysql_real_escape_string($_POST['password'])); $checklogin = mysql_query("SELECT * FROM users WHERE Username = '".$username."' AND Password = '".$password."'"); if(mysql_num_rows($checklogin) == 1) { //no end bracket; Link to comment https://forums.phpfreaks.com/topic/154614-warning-unexpected-end/#findComment-813112 Share on other sites More sharing options...
MasterACE14 Posted April 18, 2009 Share Posted April 18, 2009 just a note aside from your script. You may be getting Warning : Unexpected $end because the file has not completely uploaded onto your web server(unless it is tested locally). Link to comment https://forums.phpfreaks.com/topic/154614-warning-unexpected-end/#findComment-813136 Share on other sites More sharing options...
mrMarcus Posted April 18, 2009 Share Posted April 18, 2009 just a note aside from your script. You may be getting Warning : Unexpected $end because the file has not completely uploaded onto your web server(unless it is tested locally). ah yes, very true. especially if it's a large file and you're quick on the refresh button before the entire file/script has uploaded to the server. i've seen that before. Link to comment https://forums.phpfreaks.com/topic/154614-warning-unexpected-end/#findComment-813139 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.