Newjoke.php [resolved] - Mistake?

Pages: 1, 2
free web hosting

Latest Entry: (Post #15) by rvalkass on Mar 18 2008, 05:15 PM. (Line Breaks Removed)
Topic is resolved. Please PM any moderator to continue this discussion. Until then, this topic is closed.
Express your Opinion! Contribute Knowledge.

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Newjoke.php [resolved] - Mistake?

alex1985
Hi, do you know what is the mistake in the following PHP code:

It does give me the following message:

QUOTE
Parse error: syntax error, unexpected $end in /home/alex1985/public_html/mulhim/library_project/test_dir/newjoke.php on line 68


CODE
<?php
$dbcnx = @mysql_connect('localhost', 'root', 'mypasswd');
if (!$dbcnx) {
exit('<p>Unable to connect to the ' .
'database server at this time.</p>');
}
if (!@mysql_select_db('ijdb')) {
exit('<p>Unable to locate the joke ' .
'database at this time.</p>');
}
if (isset($_POST['joketext'])):
// A new joke has been entered
// using the form.
$aid = $_POST['aid'];
$joketext = $_POST['joketext'];
if ($aid == '') {
exit('<p>You must choose an author for this joke. Click ' .
'"Back" and try again.</p>');
}
$sql = "INSERT INTO joke SET
joketext='$joketext',
jokedate=CURDATE(),
authorid='$aid'";
if (@mysql_query($sql)) {
echo '<p>New joke added</p>';
} else {
exit('<p>Error adding new joke: ' . mysql_error() . '</p>');
}
$jid = mysql_insert_id();
if (isset($_POST['cats'])) {
$cats = $_POST['cats'];
} else {
$cats = array();
}
$i = 0; // First index
while ($i < count($cats)) { // While we're not at the end
// process $cats[$i]
++$i; // Increment to the next index
}
$i = 0; // First index
while (isset($cats[$i])) { // While we're not at the end
// process $cats[$i]
++$i; // Increment to the next index
}
for ($i = 0; isset($cats[$i]); ++$i) {
// process $cats[$i]
}
foreach ($cats as $catID) {
// Process $catID
}
$numCats = 0;
foreach ($cats as $catID) {
$sql = "INSERT IGNORE INTO jokecategory
SET jokeid=$jid, categoryid=$catID";
$ok = @mysql_query($sql);
if ($ok) {
$numCats = $numCats + 1;
} else {
echo "<p>Error inserting joke into category $catID: " .
mysql_error() . '</p>';
}
}
?>
<p>Joke was added to <?php echo $numCats; ?> categories.</p>
<p><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Add another
joke</a></p>
<p><a href="jokes.php">Return to joke search</a></p>
<?php

 

 

 


Reply

alex1985
Oh, I forgot to number the lines. The 68th line is at the end of the code which is: "<?php". Need feedback as soon as possible. Please!!!

Reply

Kubi
I believe the proper way to end that code would be ?>, maybe a second opinion would be in order.

Reply

kobra500
Yeah it's ?> don't worry I am new to PHP as well to be honest I only started learning it today lol
incedently do i have to mysql_connect every time I want to connect to mysql or just @ the beggining?
I hope the latter! yeah i c now sorry i was only looking at the last line so didn't notice the html

Reply

rvalkass
The last line in your code seems to re-start a block of PHP with no real purpose. At that point, on the last line, you are in HTML mode - all PHP blocks have been closed. Unless there is some PHP code after that last line which you have not shown us, remove that last line and you should be OK.

QUOTE(kobra500 @ Mar 11 2008, 04:17 PM) *
incedently do i have to mysql_connect every time I want to connect to mysql or just @ the beggining?


You'd never want to connect to MySQL more than once. You should open the connection at the beginning of the file, run your various SQL commands, then close the connection at the end of the file.

Reply

alex1985
Oh, thanks! I think, that will work fine, if I close the PHP code tag properly. I let you know, if-not!

Reply

flashy
Lol - thing about PHP, most text editors, and all WhatYouSeeIsWhatYouGet web editors dont tell you whats wrong or what you are missing. So the only way to figure out whats going on is to look at the error message.

Reply

alex1985
Well, it does still give me the same message?!

Reply

alex1985
Guys, if do not know or do not want to do it because it does bother you, please reply something.

Reply

rvalkass
Your problem could be this line:

CODE
if (isset($_POST['joketext'])):


If you look through your code, you have no endif; at all. To finish that if statement you will need endif; placed somewhere. This is why it complains the script ends early. It hits the end of the code and is still waiting for that endif; to appear.

Reply

Latest Entries

rvalkass
Topic is resolved.

Please PM any moderator to continue this discussion. Until then, this topic is closed.

Reply

alex1985
The problem is resolved. Thank you for your cooperation!!!

Reply

alex1985
So, anyone, please put it all together?! And if you can do it, please right the steps.

Reply

galexcd
Most of those excerpts (numbers 8 through 10) do the same thing just written in different ways, and they are not completed. It looks like they want you to replace the comment "// process $cats[$i]" with something.

Reply

rvalkass
Well, the first problem with the code you have put in your last post is line 2. The code is started with an else: statement, yet there is no if statement before it. For an else statement to get called, an if statement directly before it must have returned false. As you have no if statement before the else statement, it makes no sense.

Double check the book and make sure you haven't missed a section of code before part 1.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Pages: 1, 2
Similar Topics

Keywords : newjoke php resolved mistake

  1. Sql Query - Mistake? (19)



Looking for newjoke, php, mistake,

Searching Video's for newjoke, php, mistake,
advertisement



Newjoke.php [resolved] - Mistake?



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE