~n[EO]n~ Posted November 22, 2007 Share Posted November 22, 2007 To view the working version (online) go here http://shankhadharshakwa.org/joke.php and add some jokes I will be checking it Quote Link to comment Share on other sites More sharing options...
maxiscool1994 Posted November 22, 2007 Author Share Posted November 22, 2007 Thanks so much! I will continue to work through this book, and I will report back here when I am done. Hopefully I will have some more knowledge... You have been most helpful! Quote Link to comment Share on other sites More sharing options...
maxiscool1994 Posted November 22, 2007 Author Share Posted November 22, 2007 I've got a new issue: I am trying again to connect to my jokes database, this time with a few added things: an author name and e-mail address. The PHP is connecting to my database, but none of my jokes are showing up... Here is the code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Our List of Jokes</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <head> <body> <?php // Connect to the database server $dbcnx = @mysql_connect('localhost', 'root', 'new password'); if (!$dbcnx) { exit('<p>Unable to connect to the ' . 'database server at this time.</p>'); } // Select the jokes database if (!@mysql_select_db('ijdb')) { exit('<p>Unable to locate the joke ' . 'database at this time.</p>'); } ?> <p>Here are all the jokes in our database:</p> <blockquote> <?php $jokelist = @mysql_query( 'SELECT joketext, name, email FROM joke, author WHERE authorid=author.id'); if (!$jokelist) { exit('<p>Error performing query: ' . mysql_error() . '</p>'); } while ($joke = mysql_fetch_array($jokelist)) { $joketext = $joke['joketext']; $name = $joke['name']; $email = $joke['email']; // Display the joke with author information echo "<p>$joketext<br />" . "(by <a href='mailto:$email'>$name</a>)</p>"; } ?> </blockquote> </body> </html> Quote Link to comment Share on other sites More sharing options...
helraizer Posted November 22, 2007 Share Posted November 22, 2007 I get this error now: Parse error: syntax error, unexpected '}' in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\jokes1.php on line 53\ Here is the code with the different connection method: $result = @mysql_query('SELECT joketext FROM joke'); if (!$result) { exit('<p>Error performing query '. mysql_error() . '</p>' } The reason the '}' is unexpected is because you have no ');' on the end of line 52. It should be $result = @mysql_query('SELECT joketext FROM joke'); if (!$result) { exit('<p>Error performing query '. mysql_error() . '</p>'); } Sorry if I'm behind on times and you've already fixed it Quote Link to comment Share on other sites More sharing options...
helraizer Posted November 22, 2007 Share Posted November 22, 2007 Sorry for the double post; i couldn't edit my last post.. <?php $jokelist = @mysql_query( 'SELECT joketext, name, email FROM joke, author WHERE authorid=author.id'); if (!$jokelist) { exit('<p>Error performing query: ' . mysql_error() . '</p>'); } while ($joke = mysql_fetch_array($jokelist)) { $joketext = $joke['joketext']; $name = $joke['name']; $email = $joke['email']; // Display the joke with author information echo "<p>$joketext<br />" . "(by <a href='mailto:$email'>$name</a>)</p>"; /* you need to break the string eachtime to add the variable otherwise it won't parse. it's possibly better to use div as well; that may be a personal preference, though. */ } ?> Would probably work a lot better as: <?php $sql = 'SELECT `joketext`, `name`, `email` FROM `joke`, `author` WHERE `authorid`= author.id'; //What is 'author.id'? $jokelist = mysql_query($sql) or die(mysql_error()); while ($joke = mysql_fetch_array($jokelist)) { $joketext = $joke['joketext']; $name = $joke['name']; $email = $joke['email']; // Display the joke with author information echo "<div>".$joketext."<br />"; echo "(by <a href='mailto:".$email."'>".$name."</a>)</div>"; } ?> If you try it I think that will work! Although... how are you actually inserting data into your database? On that page there is no INSERT INTO statement. Or is that on another page? Sam Quote Link to comment Share on other sites More sharing options...
maxiscool1994 Posted November 23, 2007 Author Share Posted November 23, 2007 That is another page... It seems that this book is contradictory to a lot of things people on this forum are saying. None of the stuff in it works.. Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 23, 2007 Share Posted November 23, 2007 Hmmm again some stuff which i don't understand $jokelist = mysql_query( 'SELECT joketext, name, email FROM joke, author WHERE authorid=author.id'); Have you made 2 tables joke and author ??? I now doubt if you are following the example properly Quote Link to comment Share on other sites More sharing options...
maxiscool1994 Posted November 23, 2007 Author Share Posted November 23, 2007 n~ link=topic=168706.msg744857#msg744857 date=1195792405] Hmmm again some stuff which i don't understand $jokelist = mysql_query( 'SELECT joketext, name, email FROM joke, author WHERE authorid=author.id'); Have you made 2 tables joke and author ??? I now doubt if you are following the example properly Yes, I have, as it told me to do in the book. It is moving on into relational database design, and it said that it is easy to display info from more than one table with a join...This book seems to be pointing me in a bad direction. None of the code works...I think I will drop by the book store and pick up Sam's or something... Quote Link to comment Share on other sites More sharing options...
wsantos Posted November 23, 2007 Share Posted November 23, 2007 Im a little confused on this thread...can you try this sequence then paste the results #mysql mysql>use ijdb; mysql>show tables; mysql>show columns from joke; mysql>show columns from author; Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 23, 2007 Share Posted November 23, 2007 Paste both the table structures here , i am going to follow your way and Upload it. I still don't think that book you are using is a bad one. If you got the CD in that book try running the examples from it and see the difference in your code and in the CD. Quote Link to comment Share on other sites More sharing options...
maxiscool1994 Posted November 23, 2007 Author Share Posted November 23, 2007 n~ link=topic=168706.msg744935#msg744935 date=1195801747] Paste both the table structures here , i am going to follow your way and Upload it. I still don't think that book you are using is a bad one. If you got the CD in that book try running the examples from it and see the difference in your code and in the CD. I have been, and none of the stuff works... Here are the structures: Joke: mysql> show columns from joke; +----------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------+-------------+------+-----+---------+----------------+ | jokeid | int(9) | NO | PRI | NULL | auto_increment | | joketext | blob | NO | | | | | jokedate | varchar(50) | NO | | | | | authorid | int(11) | YES | | NULL | | +----------+-------------+------+-----+---------+----------------+ 4 rows in set (0.02 sec) Author: mysql> show columns from author; +-------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | name | varchar(255) | YES | | NULL | | | email | varchar(255) | YES | | NULL | | +-------+--------------+------+-----+---------+----------------+ 3 rows in set (0.01 sec) Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 23, 2007 Share Posted November 23, 2007 I just found error in your SQL query, replace this part $jokelist = mysql_query( 'SELECT joketext, name, email FROM joke, author WHERE joke.authorid=author.id'); To see online with your code go here http://shankhadharshakwa.org/check.php Quote Link to comment Share on other sites More sharing options...
wsantos Posted November 23, 2007 Share Posted November 23, 2007 Try this mysql>SELECT joketext, name, email FROM joke, author WHERE authorid=author.id; versus this mysql> SELECT j.joketext,a.name,a.email FROM joke j JOIN author a ON j.authorid=a.id; post the results for each Quote Link to comment Share on other sites More sharing options...
maxiscool1994 Posted November 23, 2007 Author Share Posted November 23, 2007 @Neon: That code didn't change anything. It still doesn't display any jokes... @wsantos: Here is the result for the first query: mysql> SELECT joketext, name, email FROM joke, author WHERE authorid=author.id; Empty set (0.00 sec) The second...: mysql> SELECT j.joketext, a.name, a.email FROM joke j JOIN author a ON j.authori d=a.id; Empty set (0.00 sec) Quote Link to comment Share on other sites More sharing options...
wsantos Posted November 23, 2007 Share Posted November 23, 2007 mysql>select id from author; mysql>select authorid from joke; Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 23, 2007 Share Posted November 23, 2007 See there is no jokes in your tables so it returned empty results.... see here http://shankhadharshakwa.org/check.php i added manually (5) and it is displaying with your code... Quote Link to comment Share on other sites More sharing options...
maxiscool1994 Posted November 23, 2007 Author Share Posted November 23, 2007 n~ link=topic=168706.msg744959#msg744959 date=1195804596] See there is no jokes in your tables so it returned empty results.... see here http://shankhadharshakwa.org/check.php i added manually (5) and it is displaying with your code... Wow...I'm freaking retarded...There used to be a ton of jokes in there...what happened to them? Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 23, 2007 Share Posted November 23, 2007 EDIT: To view and submit here http://shankhadharshakwa.org/joke.php and to check with your current code http://shankhadharshakwa.org/check.php And sorry to tell ya, I am out of this too p.s : these files will stay there for 3-4 days, then they will die Quote Link to comment Share on other sites More sharing options...
wsantos Posted November 23, 2007 Share Posted November 23, 2007 Lol...your script should work now. please click topic solved Quote Link to comment Share on other sites More sharing options...
helraizer Posted November 23, 2007 Share Posted November 23, 2007 You should probably condsider a link to clear the page of jokes too. At the moment you can view them but then have to change the URL in order to clear them again. Which isn't very user friendly ; also the layout could be better, though I understand that you're still just making the code for it rather than layout. The code /works/ now. Quote Link to comment Share on other sites More sharing options...
maxiscool1994 Posted November 23, 2007 Author Share Posted November 23, 2007 Helraizer, please realize that I am doing this as an example out of a book, so as long as I can work through it, its good.... Does anyone have any good books on learning PHP/MySQL they'd recommend? Quote Link to comment Share on other sites More sharing options...
wsantos Posted November 23, 2007 Share Posted November 23, 2007 What you are using ain't bad. Consider Sams' also...but nevertheless, it all boils down to lots of practice Quote Link to comment Share on other sites More sharing options...
revraz Posted November 23, 2007 Share Posted November 23, 2007 I have two I like, one is How to do everything with PHP & MYSQL, and is a great starter book, and I found it on Amazon for like $5.00 Helraizer, please realize that I am doing this as an example out of a book, so as long as I can work through it, its good.... Does anyone have any good books on learning PHP/MySQL they'd recommend? Quote Link to comment Share on other sites More sharing options...
helraizer Posted November 23, 2007 Share Posted November 23, 2007 Helraizer, please realize that I am doing this as an example out of a book, so as long as I can work through it, its good.... Does anyone have any good books on learning PHP/MySQL they'd recommend? I know, and that is fair enough. I was meaning if you were to take it further. Depends on how you learn but are a number of good books out there; or if needs be, Google it and there are a lot of PDFs you can download which fit your purpose. Quote Link to comment Share on other sites More sharing options...
maxiscool1994 Posted November 23, 2007 Author Share Posted November 23, 2007 What you are using ain't bad. Consider Sams' also...but nevertheless, it all boils down to lots of practice Would you recommend getting Sam's after I finish this book, or get it now and forget about the one I am using? Quote Link to comment 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.