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
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> 

Link to comment
Share on other sites

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!!!!!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.