SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
-
Jan 11, 2005, 22:45 #1
- Join Date
- Jan 2005
- Location
- tallahassee
- Posts
- 3
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Help with a php script from the php mysql book
Hi... I have the 'build your own database driven website with php and mysql' by kevin yank, third edition, and there is a php page in the book that i'm trying to basically copy over to mine (in order to learn it), and it is not working at all.
here is the code:
Code:[SIZE=1]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML> <HEAD> <TITLE>Joke Administration: Add New Categories</TITLE> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> </HEAD> <BODY> <H1>Add Categories</H1> <?php if (isset($_POST['name'])): // A new category has been entered // using the form below. $dbcnx = @mysql_connect('localhost', 'root', 'mypassword'); if(!$dbcnx) { exit('<p>Unable to connect to the database at this time.</p>'); } if (!@mysql_select_db('dickeysc_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 jackhandy 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(); } $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="joke_manage.php">Return to joke search</a></p> <?php else: // Allow the user to enter a new joke $authors = @mysql_query('SELECT id, name FROM author'); if (!$authors) { exit('<p>Unable to obtain author list from the database.</p>'); } $cats = @mysql_query('SELECT id, name FROM category'); if (!$cats) { exit('<p>Unable to obtain category list from the database.</p>'); } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <p>Enter the new joke:<br> <textarea name="joketext" rows="5" cols="45"> </textarea></p> <p>Author: <select name="aid" size="1"> <option selected value="">Select One</option> <option value="">---------</option> <?php while ($author = mysql_fetch_array($authors)) { $aid = $author['id']; $aname = htmlspecialchars($author['name']); echo "<option value='$aid'>$aname</option>\n"; } ?> </select></p> <p>Place in categories:<BR> <?php while ($cat = mysql_fetch_array($cats)) { $cid = $cat['id']; $cname = htmlspecialchars($cat['name']); echo "<label><input type='checkbox' name='cats[]' value='$cid'></input>$cname</label><br>\n"; } ?> </p> <input type="submit" value="SUBMIT"></INPUT> </form> <?php endif; ?> </BODY> </HTML>[/SIZE]
The closing html tag is line 114, and it keeps saying parse error line 114. And the closing tag of html is definitly not causing the error. The code is straight from the website and all... grr.. This is definitely hindering my edumacation of php. Any help at all would be greatly appreciated.
Rich
-
Jan 11, 2005, 22:48 #2
- Join Date
- Oct 2004
- Location
- Australia
- Posts
- 197
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:if (isset($_POST['joketext'])):
-
Jan 11, 2005, 23:06 #3
- Join Date
- Jan 2005
- Location
- tallahassee
- Posts
- 3
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Re:
Ok, I changed the : to a { and it gives me the same error, except it's on line 74. Here is line 74:
Code:<?php else: // Allow the user to enter a new joke
thanks again for your help...
rich
-
Jan 12, 2005, 22:19 #4
- Join Date
- Jan 2005
- Location
- tallahassee
- Posts
- 3
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Re:
Any help? anyone? pleeeeeeeease.. i guess everyone's stumped
-
Jan 12, 2005, 23:17 #5
- Join Date
- Dec 2003
- Location
- Federal Way, Washington (USA)
- Posts
- 1,524
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Here's what I would do if I were in your shoes. Keep this script as a reference and start over. Copy the book code into a new file and work with that. Change one thing at a time, copy it to your web server and see if the script will run at least without a parse error.
For example, change the database connection parameters first, copy the script to your web server and run it. If that's ok, change the next thing, copy it to the web server, etc.
Don't try to change too many things at once. When you do, it's difficult to identify where the problem is occurring.
Small changes, test, go from there. Let us know how that works for you.Music Around The World - Collecting tips, trade
and want lists, album reviews, & more
Showcase your music collection on the Web
-
Jan 13, 2005, 00:31 #6
- Join Date
- Nov 2004
- Location
- Parry Sound, ON
- Posts
- 725
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The colon was correct. it's alternate syntax
PHP Code:if(condition):
//stuff
else:
//other stuff
endif;
Bookmarks