Jump to content

Problems with comment script


rjcfan4ever

Recommended Posts

I got an comment script of internet and created a mysql database but if someone sumbit a message it just works.. But if a second person want to sumbit an message he doesn't work D:

 

Script:

$host = "localhost"; 
$user = "username"; 
$pass = "password"; 
$db = "database"; 

mysql_connect($host, $user, $pass) OR die ("Could not connect to the server."); 
mysql_select_db($db) OR die("Could not connect to the database."); 
       
$name = stripslashes($_POST['txtName']); 
$message = stripslashes($_POST['txtMessage']); 

if (!isset($_POST['txtName'])) { 

    $query = "SELECT id, name, message, DATE_FORMAT(date, '%D %M, %Y @ %H:%i') as newdate FROM guests ORDER BY id DESC"; 
    $result = mysql_query($query); 
     
    while ($row = mysql_fetch_object($result)) { 

?> 

<p><strong><?php echo $row->message; ?></strong> 
<br />Posted by <?php echo $row->name; ?> on <?php echo $row->newdate; ?></p> 

<?php 
         
    } 
     
?> 

 

Live view: http://theelephantcrew.awardspace.info/thehappytutorials.php

Link to comment
https://forums.phpfreaks.com/topic/243095-problems-with-comment-script/
Share on other sites

You must insert data at mysql

 

$host = "localhost"; 
$user = "username"; 
$pass = "password"; 
$db = "database"; 

mysql_connect($host, $user, $pass) OR die ("Could not connect to the server."); 
mysql_select_db($db) OR die("Could not connect to the database."); 
       
$name = stripslashes($_POST['txtName']); 
$message = stripslashes($_POST['txtMessage']); 

if (isset($_POST['txtName'])) { 
     $query = "INSERT INTO guests  (name, message,date) values ('".mysql_real_escape_string($name)."','".mysql_real_escape_string($message)."','".date('Y-m-d H:i:s')."')";; 
    $result = mysql_query($query); 
}

    $query = "SELECT id, name, message, DATE_FORMAT(date, '%D %M, %Y @ %H:%i') as newdate FROM guests ORDER BY id DESC"; 
    $result = mysql_query($query); 
     
    while ($row = mysql_fetch_object($result)) { 

?> 

<p><strong><?php echo $row->message; ?></strong> 
<br />Posted by <?php echo $row->name; ?> on <?php echo $row->newdate; ?></p> 

Read through your original code that you posted in your question.

 

At no point in this code do you have either an INSERT or UPDATE statement.  How can you expect to transfer information to a DB without actually having the commands in your script that will do this for you????????

 

That's like me thinking of a number and then asking you what it is.  You won't know, because I've not transferred that information from my brain to yours via my mouth!!!!!

Read the post by kikesv.  He has already shown how to do this.

 

What's the point of posting on here if you don't read, digest and try to understand what people are doing to help?

 

You may want to do a bit of Googling about basic MySQL databases and the fundamental statements and interactions that php has with it.

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.