PHP/SQL feedback forum

Soldato
Joined
1 Dec 2004
Posts
23,079
Location
S.Wales
Im building a feedback forum from scratch, i was doing fine until i started implementing a time-stamp feature to stamp the posts, i was using the current_date function in SQL but someone advised me to use the now() function instead, which im implementing, See the below code:


Form:
Code:
<form action='action.php' method='post'>

Name: <input type='text' name='name' size='20'><br>

Comment:<br>

<textarea name='comment' rows='5' cols='40'></textarea><br>

<input type='submit' name='submit' value='submit'></form>


Action:
Code:
<?php

include "connect.php";

if(isset($_POST['submit']))

{

   $date=$_POST['date'];

   $name=$_POST['name'];

   $comment=$_POST['comment'];

   
   if(strlen($name)<1)


   {
	 print "You did not enter a name.";

   }

   else if(strlen($comment)<1)

   {

      print "You did not enter a comment.";

   }

   else

   {

	  $insert="Insert into visitordata (name,COMMENT,DATE) values('$name','$comment',now())";

      mysql_query($insert) or die("Could not insert comment");

      print "Comment added. <A href='display.php'>Click here</a> to see all comments.";

     }

  }

?>


Display:
Code:
<?php

include "connect.php";

$getdata="SELECT * from visitordata order by entryid desc";

$getdata2=mysql_query($getdata) or die("Could not get data");

while($getdata3=mysql_fetch_array($getdata2))

{

  $getdata3[name]=strip_tags($getdata3[NAME]);

  $getdata3[comment]=strip_tags($getdata3[COMMENT]);
  print "-------------------------------------------------------------";
  print "<br>";
  print "Date/Time: $getdata3[DATE]";
  
  print "Name: $getdata3[NAME]<br>";
  
  print "$getdata3[COMMENT]<br>";

 
  

  }

but as you can see, if you goto www.dmoranda.co.uk/form.php i get the message "Did not enter a name" when i did..

anyone else spot an obvious mistake?
 
I have to say now my PHP/SQL is basic, and i do not know what your going on about when you say SQL Injection :p

Sorry, and yes errors are enabled, but i do not get any errors my end?
 
Got it working thanks..

Bit im abit confused about, even after reading that link you gave me is the correct formatting for the output of the date. I want to use for example:

Monday 23rd April 2007

which in my eyes needs the following code added

Code:
date('l, F j, Y')

as the string variable, then down the bottom somewhere i just output now()

it this the correct procedure?
 
Code:
<?php

include "connect.php";

if(isset($_POST['submit']))

{

   date('l jS F Y'); 

   $name=$_POST['name'];

   $comment=$_POST['comment'];

   
   if(strlen($name)<1)


   {
	 print "You did not enter a name.";

   }

   else if(strlen($comment)<1)

   {

      print "You did not enter a comment.";

   }

   else

   {

	  $insert="Insert into visitordata (NAME,COMMENT,DATE) values('$name','$comment',now())";

      mysql_query($insert) or die("Could not insert comment");

      print "Comment added. <A href='display.php'>Click here</a> to see all comments.";

     }

  }

?>

like so?
 
Back
Top Bottom