rjcfan4ever Posted July 28, 2011 Share Posted July 28, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/243095-problems-with-comment-script/ Share on other sites More sharing options...
kikesv Posted July 28, 2011 Share Posted July 28, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/243095-problems-with-comment-script/#findComment-1248475 Share on other sites More sharing options...
rjcfan4ever Posted July 28, 2011 Author Share Posted July 28, 2011 I did Quote Link to comment https://forums.phpfreaks.com/topic/243095-problems-with-comment-script/#findComment-1248476 Share on other sites More sharing options...
Nodral Posted July 28, 2011 Share Posted July 28, 2011 Check your original code. There is no INSERT statement, so how are you writing to your DB? Quote Link to comment https://forums.phpfreaks.com/topic/243095-problems-with-comment-script/#findComment-1248490 Share on other sites More sharing options...
rjcfan4ever Posted July 28, 2011 Author Share Posted July 28, 2011 Sorry don't get it Quote Link to comment https://forums.phpfreaks.com/topic/243095-problems-with-comment-script/#findComment-1248492 Share on other sites More sharing options...
Nodral Posted July 28, 2011 Share Posted July 28, 2011 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!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/243095-problems-with-comment-script/#findComment-1248496 Share on other sites More sharing options...
rjcfan4ever Posted July 28, 2011 Author Share Posted July 28, 2011 Okey but can you explain how to adjust this? Quote Link to comment https://forums.phpfreaks.com/topic/243095-problems-with-comment-script/#findComment-1248507 Share on other sites More sharing options...
Nodral Posted July 28, 2011 Share Posted July 28, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/243095-problems-with-comment-script/#findComment-1248515 Share on other sites More sharing options...
rjcfan4ever Posted July 28, 2011 Author Share Posted July 28, 2011 I fill in the database information and that's not the problem Quote Link to comment https://forums.phpfreaks.com/topic/243095-problems-with-comment-script/#findComment-1248519 Share on other sites More sharing options...
Nodral Posted July 28, 2011 Share Posted July 28, 2011 How do you fill in the database information without using either an INSERT statement or UPDATE statement? Show me the bit of your code which interacts with your DB and writes into it. Quote Link to comment https://forums.phpfreaks.com/topic/243095-problems-with-comment-script/#findComment-1248520 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.