angelssin Posted April 5, 2007 Share Posted April 5, 2007 hi there, im fairly new to PHP and mysql. I'm doing web computing at university so i have learned a little bit about it, though mostly all we had to do was search queries for our assignment and they didnt really teach us how to add information to a database using forms or anything. Basically my situation is that i want to make a blog-like section for my website, so that i can access a page and write reviews and click submit and then the review appears very nicely on the review page in a descending order. I completely understand the theory behind all of this but i think theres a tiny bit of my display code that needs tweaking for it to work. Heres my code. <?php $dbServer=mysql_connect("localhost","myusername","mypassword"); if (!$dbServer) {echo "Failed to connect to MySQL"; exit; } mysql_select_db("my_reviews",$dbServer); $qResult = mysql_query ("SELECT * FROM reviews ORDER BY id DESC"); if ($_POST["comment"]=="") { echo "you did not type anything"; exit; $qResult=mysql_query; if (mysql_error()) { echo "Problem with Query<BR>"; echo "The following error message was returned from MySQL:<BR>"; echo mysql_error(); exit; } if (mysql_num_rows($qResult)==0) { echo "No entries found."; exit; } $nRows = mysql_num_rows($qResult); for ($i=0; $i< $nRows; $i++){ $row = mysql_fetch_array($qResult); echo "Number:".$i."=".$row['id']."<BR>"; echo "<H2>Title</H2>".$i."=".$row['title']."<BR>"; echo "Date:".$i."=".$row['date']."<HR>"; echo "Review:<BR><BR>".$i."=".$row['comment']."<HR>"; } } ?> now...i put in entries to my database to test this out for just the display, so what im thinking is that maybe my code is in the wrong order or something because all that displays is "you did not type anything" which means its doing that part of the code before it gets chance to echo the rows in my database...i would just like to know if thats the problem and where to move the echo part to, if that is even the problem. all help is deeply appreciated, this has been doing my head in for hours now. Link to comment https://forums.phpfreaks.com/topic/45657-php-blog-problem/ Share on other sites More sharing options...
AndyB Posted April 5, 2007 Share Posted April 5, 2007 if ($_POST["comment"]=="") { echo "you did not type anything"; exit; Is entirely redundant when displaying information. It looks like a left-over from a script where you were allowing input to the database and checking for valid data. Just remove it. Link to comment https://forums.phpfreaks.com/topic/45657-php-blog-problem/#findComment-221725 Share on other sites More sharing options...
angelssin Posted April 5, 2007 Author Share Posted April 5, 2007 it definitly did something...now im getting this error message Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/myusername/public_html/testblog1.php on line 19 No entries found. Link to comment https://forums.phpfreaks.com/topic/45657-php-blog-problem/#findComment-221727 Share on other sites More sharing options...
AndyB Posted April 5, 2007 Share Posted April 5, 2007 looks again .... $qResult=mysql_query; ... delete that line as well, you've already executed the real query a few lines earlier. Link to comment https://forums.phpfreaks.com/topic/45657-php-blog-problem/#findComment-221730 Share on other sites More sharing options...
angelssin Posted April 5, 2007 Author Share Posted April 5, 2007 you're a star...it definitly looks sort of how i want it to look now (without the pretty finishing touches of course)...i think i can fix the little things left myself...thanks a million for the help! Link to comment https://forums.phpfreaks.com/topic/45657-php-blog-problem/#findComment-221735 Share on other sites More sharing options...
angelssin Posted April 5, 2007 Author Share Posted April 5, 2007 hey there, i got everything working on my blog system now...except for the date. Basically i want to store the date of the post into my date field in my mysql database, however...whenever i post anything it just keeps coming up with the default Date: 0000-00-00 00:00:00 I'll post my code for it below...however, i understand that there may be something wrong with my date field in my database so could you please tell me which settings to use for that field. <? $dbServer=mysql_connect("localhost","username","password"); if (!$dbServer) {echo "Failed to connect to MySQL"; exit; } mysql_select_db("username_reviews",$dbServer); $date="SELECT CURRENT_TIMESTAMP"; $sql="INSERT INTO reviews (id, title, comment, date) VALUES ('$_POST[id]','$_POST[title]','$_POST[commentsBox]','$date')"; if (!mysql_query($sql,$dbServer)) { die('Error: ' . mysql_error()); } echo "your comment has been posted"; mysql_close($dbServer) ?> thanks a lot...again any help at all is really appreciated. Link to comment https://forums.phpfreaks.com/topic/45657-php-blog-problem/#findComment-221960 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.