lost and confused

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

lost and confused

Post by danwguy »

So I am making a form so that someone can edit a "blog" that they have already posted and I have stored in a mysqldb my problem is the following script keeps giving me an error and when I view the error logs it says "PHP Parse error: syntax error, unexpected $end in /update.form.php on line 27" can anyone please tell me what it wants there, because I can't see why it's an unexpected $end. Thank you all in advance.

Code: Select all

<html>
<body>
<p align="center">Make your edits and press submit when done.<br />
<?php
$edit1 = $_POST['name'];

$con = mysql_connect("localhost", "blocked", "hidden");
		if(!$con) {
			die("Could not connect to database:" . mysql_error());
		@mysql_select_db("blogs") or die("Could not select database:" . mysql_error());
		$result = mysql_query("SELECT blogID from blogs where blogID = '$edit1'") or die("SELECT error: " . mysql_error());
			while($row = mysql_fetch_array($result)) {
				$title = $row['title'];
				$blurb = $row['blurb'];
				$blog = $row['content'];
				};
?>
<form id="update" action="update.php" method="post">
<input type="hidden" name="number" value="<?php echo $edit1; ?>" />
<input type="text" name="title" value="<?php echo $title; ?>" />
<input type="text" name="blurb" value="<?php echo $blurb; ?>" />
<textarea rows="6" cols="40" name="blog"><?php echo $blog; ?></textarea>
<input type="submit" />
</form>
</p>
</body>
</html>
and yes I changed the login information to fake info before posting.
This is after I let them select which "blog" they want to edit from a form that just connects to the DB and echo's the titles of each blog with a radio button next to them, they select the radion button of the blog they want to edit and press submit, then it goes to the above form that errors out. Thank you again for the help.
anantha
Forum Commoner
Posts: 59
Joined: Thu Dec 23, 2010 7:38 pm

Re: lost and confused

Post by anantha »

This error mostly comes because you may have missed closing bracket some where..if i am right if(!$con) { and where are you closing with" }".
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: lost and confused

Post by danwguy »

Wow, you are awesome, I didn't even see that. I closed the "if(!con) { with a ) instead of a }. Thank you soooo much you have no idea how crazy that was making me. sometimes it helps to have another set of eyes look at it and show you the stupid thing you did. Thank you again man, saved my ass... and brain.
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: lost and confused

Post by danwguy »

Ok sorry, one more question. in the form above why are my fields blank? I also tried adding

Code: Select all

<?php echo $file; ?>
, and

Code: Select all

<?php echo "the title of the blog you are editing is: <br />"; echo $title; ?>
right after teh </form> in that and it won't echo those variables, any idea?
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: lost and confused

Post by danwguy »

ok, loosing my mind again. can't get those fields to populate with the data. i tried this... any one, I realize it's rediculous coding but it should work and I am resorting to horrible ugly code to find the problem, the only error I get is "PHP Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';' in /update.form.php on line 25" Please, please help me. I think my brain has actually done the impossible and turned into Jell-O on this one. here's the code... again, yes it's ugly, but it should work.

Code: Select all

<html>
<body>
<p align="center">Make your edits and press submit when done.<br />
<?php
$edit1 = $_POST['name'];

$con = mysql_connect("we all know what goes here");
				if(!$con) {
									die("Could not Connect: " .mysql_error());
									}
										@mysql_select_db("blog_db") or die("Unable to select database " .mysql_error());		$result = mysql_query("SELECT blogID from blogs where blogID = '$edit1'") or die("SELECT error: " . mysql_error());
			while($row = mysql_fetch_array($result)) {
				$title = $row['title'];
				$blurb = $row['blurb'];
				$blog = $row['content'];
				
echo "<form id=\"update\" action=\"update.php\" method=\"post\">" or die("nope: " .mysql_error());
echo "<input type=\"hidden\" name=\"number\" value=\"$edit1\" />" or die("maybe: " .mysql_error());
echo "<input type=\"text\" name=\"title\" value=\"$title\" />" or die("probably not: " .mysql_error());
echo "<input type=\"text\" name=\"blurb\" value=\"$blurb\" />" or die("not here: " .mysql_error());
echo "<textarea rows=\"6\" cols=\"40\" name=\"blog\">" . $blog . "</textarea>" or die("yes: " .mysql_error());
echo "<input type=\"submit\" />" or die("doubtfull: " .mysql_error());
echo "</form>" or die("not a chance: " .mysql_error());
echo $title
echo "the title of the blog you are editing is: <br />";
echo $title;
}
?>
</p>
</body>
</html>
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: lost and confused

Post by califdon »

"PHP Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';' in /update.form.php on line 25"
What that error is telling you is that you have a syntax error and PHP cannot parse what you wrote. The error was discovered on line 25 of your script update.form.php. The "echo" was unexpected because it came without a ',' or a ';' before it. Now look at the line just before line 25 and I'm sure you will see what's wrong.

Learning to understand error messages is absolutely essential to learning programming.
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: lost and confused

Post by danwguy »

That's what I don't understand, all line endings have a ; at the end, yet it still says it was expecting one. I can't put another one there, it won't work, so what did I do wrong?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: lost and confused

Post by califdon »

danwguy wrote:That's what I don't understand, all line endings have a ; at the end, yet it still says it was expecting one. I can't put another one there, it won't work, so what did I do wrong?
You don't see the line where it's missing the ';'? It's the line immediately above where the error was detected.

Are you using an editor that highlights PHP syntax? You should. It would show such errors in a different color while you are editing the file. I use PSPad, which you can download free.
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: lost and confused

Post by danwguy »

I was using notepad to do the script, so I counted out the 25 lines and everything before it was fine. Wsitched over to alleycode and it popped right out at me, sorry, and thank you so much for putting up with my dumb a%%. but still a problem, I fixed the error, I am no longer getting that when trying to run the script but for some reason it's not showing the form that I am echo-ing. any idea why that would be?

Edit: Never mind, I got it all figured out, I was SELECTing only the blogID not the whole freaking form. Man seriously I think my brain is fried from this. Thank you all for your help.
Post Reply