Jump to content

PHP blog problem


angelssin

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.