Yojance Posted June 8, 2006 Share Posted June 8, 2006 I recently bought 2 books from Site Point and there is a bit of code that I do not understand, since the books doesn't explain it. I'm hoping one of you smart php guys can explain it to me.The part of the code I do not understand the very next line after the form, this line:[code]<?php else: // Default page display[/code]Why is there a ([b]:[/b]) instead of a { .And why is it that at the end, we must end it if an [b]endif;[/b] I never seen that one neither.Another thing I find stupid is that everytime I hit refreshed, the last joke it's added again to the database, which makes no sense to me. How could I eliminate that from happeing over and over.Would any of you care to explain to me in plain english why it has to be done like that?Thanks for your help in advance.[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Welcome to Jokes DB!</title></head><body><?php if(isset($_GET['addjoke'])): //User wants to add a joke ?><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"><label>Type your joke here:<br/><textarea name="joketext" rows="10" cols="40"></textarea></label><br/><input type="submit" value="SUBMIT" /></form><?php else: // Default page display// Connect to the database server$dbcnx = @mysql_connect('localhost', 'user', 'pass');if (!$dbcnx) { exit('<p> Unable to connect to the database server at this time.</p>');}// Select your jokes databaseif (!@mysql_select_db('joke')) {exit('<p>Unable to locate the joke database at this time.</p>');}// If a joke has been submited, add it to the databaseif (isset($_POST['joketext'])) {$joketext = $_POST['joketext'];$sql ="INSERT INTO ijdb SET joketext='$joketext', jokedate=CURDATE()"; if (@mysql_query($sql)) { echo '<p>Your joke has been added</p>'; } else { echo '<p>Error adding submitted joke: '.mysql_error(). '</p>'; }}echo '<p>Here are all the jokes in our database';//Request the text of all jokes$result = @mysql_query('SELECT joketext FROM ijdb');if(!$result) { exit('<p>Error performing the query: ' .mysql_error(). '</p>');}//Display the text of each joke in a paragraphwhile ($row = mysql_fetch_array($result)) {echo '<p>'.$row['joketext']. '</p>';echo '<em>'.$row['jokedate']. '</em>';}/// When clicked , this link will load this page within the joke submission form displayed.echo '<p><a href="' .$_SERVER['PHP_SELF']. '?addjoke=true">Add a Joke!</a></p>';endif;?></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11516-need-help-understaing-this-script/ Share on other sites More sharing options...
kenrbnsn Posted June 8, 2006 Share Posted June 8, 2006 In answer to your first question, using the ":" is an alternative syntax for control structures. See [a href=\"http://us3.php.net/manual/en/control-structures.alternative-syntax.php\" target=\"_blank\"]this[/a] page in the fine manual.Ken Quote Link to comment https://forums.phpfreaks.com/topic/11516-need-help-understaing-this-script/#findComment-43348 Share on other sites More sharing options...
Yojance Posted June 8, 2006 Author Share Posted June 8, 2006 Hey Ken, thanks for your link, I read and I still find it confusing. Im going to keep looking at it hoping I can get something out of it. If someone else has can explain it to me, I would really appreacite that. Quote Link to comment https://forums.phpfreaks.com/topic/11516-need-help-understaing-this-script/#findComment-43356 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.