nimzrocks Posted February 15, 2010 Share Posted February 15, 2010 Can you please tell me what is wrong with this comment script ? it is not showing anything. Just a blank page This is comment.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php $id = $_REQUEST["id"]; include('write_comment.php'); $result = mysql_query ("SELECT * FROM commenttable WHERE postid='$id' ORDER BY id desc") or exit (mysql_error()); while($row = mysql_fetch_array($result)) { echo $row['name']; echo $row['mail']; echo $row['comment']; echo $row['timestamp']; } ?> <form action="index.php?id=<? echo $id;?>" method="post"/> Name:<input name="name" type="text" ><br /> Mail:<input name="mail" type="text" ><br /> Kommentar: <textarea name="comment" cols="50" rows="6"></textarea><br /> <input name="submit" type="submit" class="submit" value="Send"/> </form > </body> </html> This is write_comment.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("databasename", $con); if(isset($_POST['submit'])) { $name = $_REQUEST['name']; $mail = $_REQUEST['mail']; $commen = $_REQUEST['comment']; $postid = $_REQUEST['id']; if( (!empty($name)) && (!empty($mail)) && (!empty($comment)) ) { $sql = "INSERT INTO prototype (name, mail, comment, postid) VALUES('$name', '$mail', '$comment', '$postid')"; mysql_query($sql) or die(mysql_error()); } } ?> </body> </html> Please someone help me....... Thank you Link to comment https://forums.phpfreaks.com/topic/192130-what-is-wrong-with-this/ Share on other sites More sharing options...
Deoctor Posted February 15, 2010 Share Posted February 15, 2010 echo the value of $id and see whether u are getting any results into that.. first check this documentation regarding the $_request http://www.alternateinterior.com/2007/01/what-is-_request.html Link to comment https://forums.phpfreaks.com/topic/192130-what-is-wrong-with-this/#findComment-1012533 Share on other sites More sharing options...
bugcoder Posted February 15, 2010 Share Posted February 15, 2010 cant get exactly what can be the issue but will like to know that what you will get after adding following line on both pages. error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/192130-what-is-wrong-with-this/#findComment-1012534 Share on other sites More sharing options...
nblackwood Posted February 15, 2010 Share Posted February 15, 2010 try this code: <?php require_once('write-comment.php'); $id = $_REQUEST["id"]; $result = mysql_query ("SELECT * FROM commenttable WHERE postid='$id' ORDER BY id desc") or exit (mysql_error()); while($row = mysql_fetch_array($result)); { echo $row['name']; echo $row['mail']; echo $row['comment']; echo $row['timestamp']; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action=""> Name: <input name="name" type="text" /> <br /> Mail: <input name="mail" type="text" /> <br /> Kommentar: <textarea type="text" name="comment" cols="50" rows="6"></textarea> <br /> <input name="submit" type="submit" class="submit" value="Send"/> </form> </body> </html> </body> </html> Link to comment https://forums.phpfreaks.com/topic/192130-what-is-wrong-with-this/#findComment-1012536 Share on other sites More sharing options...
nblackwood Posted February 15, 2010 Share Posted February 15, 2010 I forgot one thing... make this change to the code i provided: <form id="form1" name="form1" method="post" action="write_comment.php"> Link to comment https://forums.phpfreaks.com/topic/192130-what-is-wrong-with-this/#findComment-1012548 Share on other sites More sharing options...
nimzrocks Posted February 15, 2010 Author Share Posted February 15, 2010 Thank you nblackwood but I'm new to php. I do not see a code to connect to my sql data base can you tell me how to put that code also ? Thank you Link to comment https://forums.phpfreaks.com/topic/192130-what-is-wrong-with-this/#findComment-1012582 Share on other sites More sharing options...
bugcoder Posted February 15, 2010 Share Posted February 15, 2010 $con = mysql_connect("localhost","username","password"); instead of it give the username and password of your localhost database username password by default it should be like $con = mysql_connect("localhost","root",""); Link to comment https://forums.phpfreaks.com/topic/192130-what-is-wrong-with-this/#findComment-1012587 Share on other sites More sharing options...
nimzrocks Posted February 15, 2010 Author Share Posted February 15, 2010 My problem is I cant see anything when I go to comment.php I do not see my form there is anyone has a script ? Please give me. I'm really sick of this now. I typed a lot to get help every where but no one is helping me properly It is two weeks now still could not make this http://www.phpfreaks.com/forums/index.php/topic,287535.msg1363149.html#msg1363149 you can see someone was helping me but he did not finish it Is anyone can complete it ? please help me Link to comment https://forums.phpfreaks.com/topic/192130-what-is-wrong-with-this/#findComment-1012602 Share on other sites More sharing options...
wildteen88 Posted February 15, 2010 Share Posted February 15, 2010 My problem is I cant see anything when I go to comment.php I do not see my form there If you're getting a blank screen then it is more than likely there is an error in your code. In order to see the error you need to enable a PHP setting call display_errors and set error_reporting to E_ALL within your php.ini. If your host doesn't allow access to the php.ini then add the following two lines at the top of your php script (on the line after the opening PHP tag <?php) error_reporting(E_ALL); ini_set('display_errors', 1); Post the errors you're getting here. Link to comment https://forums.phpfreaks.com/topic/192130-what-is-wrong-with-this/#findComment-1012663 Share on other sites More sharing options...
nimzrocks Posted February 15, 2010 Author Share Posted February 15, 2010 Thank you very much. These are my errors Warning: require_once(write-comment.php) [function.require-once]: failed to open stream: No such file or directory in /home/vol11/0fees.net/fees0_4383963/mywebsite.com/htdocs/script1/comment.php on line 15 Fatal error: require_once() [function.require]: Failed opening required 'write-comment.php' (include_path='.') in /home/vol11/0fees.net/fees0_4383963/mywebsite.com/htdocs/script1/comment.php on line 15 and I found out a what is the error so I just renamed write_comment.php to write-comment.php and now I'm getting this error now Notice: Undefined index: id in /home/vol11/0fees.net/fees0_4383963/mywebsite.com/htdocs/script1/comment.php on line 17 No database selected What is the problem ? Link to comment https://forums.phpfreaks.com/topic/192130-what-is-wrong-with-this/#findComment-1012674 Share on other sites More sharing options...
wildteen88 Posted February 15, 2010 Share Posted February 15, 2010 The main problem is this error No database selected For some reason your code is not connecting to your database. Try the following code, I have merged comment.php with write-comment.php. Place the following code in comment.php <?php $con = mysql_connect("localhost","username","password"); if (!$con) die('Could not connect: ' . mysql_error()); mysql_select_db("databasename", $con); if(isset($_POST['submit'])) { $name = mysql_real_escape_sting($_POST['name']); $mail = mysql_real_escape_sting($_POST['mail']); $commen = mysql_real_escape_sting($_POST['comment']); $postid = (int) $_POST['id']; if( (!empty($name)) && (!empty($mail)) && (!empty($comment)) ) { $sql = "INSERT INTO prototype (name, mail, comment, postid) VALUES('$name', '$mail', '$comment', '$postid')"; mysql_query($sql) or die('Unable to insert comment: '. mysql_error()); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php if(isset($_REQUEST["id"]) && is_numeric($_REQUEST["id"])) { $id = (int) $_REQUEST["id"]; $result = mysql_query ("SELECT * FROM commenttable WHERE postid='$id' ORDER BY id desc") or die ('Unable to grab comments: '.mysql_error()); while($row = mysql_fetch_array($result)); { echo $row['name']; echo $row['mail']; echo $row['comment']; echo $row['timestamp']; } } ?> <form id="form1" name="form1" method="post" action=""> Name: <input name="name" type="text" /> <br /> Mail: <input name="mail" type="text" /> <br /> Kommentar: <textarea type="text" name="comment" cols="50" rows="6"></textarea> <br /> <input name="submit" type="submit" class="submit" value="Send"/> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/192130-what-is-wrong-with-this/#findComment-1012680 Share on other sites More sharing options...
nimzrocks Posted February 15, 2010 Author Share Posted February 15, 2010 ok now I can see the form and I can fill it but when i clickes on submit I'm getting this error now. Fatal error: Call to undefined function mysql_real_escape_sting() in /home/vol11/0fees.net/fees0_4383963/mywebsite.com/htdocs/script1/comment2.php on line 14 what can be the error now ? Link to comment https://forums.phpfreaks.com/topic/192130-what-is-wrong-with-this/#findComment-1012696 Share on other sites More sharing options...
wildteen88 Posted February 15, 2010 Share Posted February 15, 2010 Ops. All instances of mysql_real_escape_sting should be mysql_real_escape_string I mistype the function name. Link to comment https://forums.phpfreaks.com/topic/192130-what-is-wrong-with-this/#findComment-1012700 Share on other sites More sharing options...
nimzrocks Posted February 15, 2010 Author Share Posted February 15, 2010 ok thank you I corrected other two sting to string but now I'm getting this error Notice: Undefined index: id in /home/vol11/0fees.net/fees0_4383963/mywebsite.com/htdocs/script1/comment2.php on line 17 what is this time ? Link to comment https://forums.phpfreaks.com/topic/192130-what-is-wrong-with-this/#findComment-1012706 Share on other sites More sharing options...
nimzrocks Posted February 15, 2010 Author Share Posted February 15, 2010 Seems got stuck again Link to comment https://forums.phpfreaks.com/topic/192130-what-is-wrong-with-this/#findComment-1012730 Share on other sites More sharing options...
wildteen88 Posted February 15, 2010 Share Posted February 15, 2010 Change <form id="form1" name="form1" method="post" action=""> To <form id="form1" name="form1" method="post" action="comment2.php?id=<?php echo $id; ?>"> Now change if(isset($_POST['submit'])) to if(isset($_POST['submit'], $_GET['id']) && is_numeric($_GET['id'])) Also change $postid = (int) $_POST['id']; to $postid = (int) $_GET['id']; Link to comment https://forums.phpfreaks.com/topic/192130-what-is-wrong-with-this/#findComment-1012741 Share on other sites More sharing options...
nimzrocks Posted February 16, 2010 Author Share Posted February 16, 2010 No errors. I'm getting a new form back and data base is not getting any data This is is script <?php error_reporting(E_ALL); ini_set('display_errors', 1); $con = mysql_connect("...","....","..."); if (!$con) die('Could not connect: ' . mysql_error()); mysql_select_db("fees0_4383963_test", $con); if(isset($_POST['submit'], $_GET['id']) && is_numeric($_GET['id'])) { $name = mysql_real_escape_string($_POST['name']); $mail = mysql_real_escape_string($_POST['mail']); $commen = mysql_real_escape_string($_POST['comment']); $postid = (int) $_GET['id']; if( (!empty($name)) && (!empty($mail)) && (!empty($comment)) ) { $sql = "INSERT INTO prototype (name, mail, comment, postid) VALUES('$name', '$mail', '$comment', '$postid')"; mysql_query($sql) or die('Unable to insert comment: '. mysql_error()); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php if(isset($_REQUEST["id"]) && is_numeric($_REQUEST["id"])) { $id = (int) $_REQUEST["id"]; $result = mysql_query ("SELECT * FROM prototype WHERE postid='$id' ORDER BY id desc") or die ('Unable to grab comments: '.mysql_error()); while($row = mysql_fetch_array($result)); { echo $row['name']; echo $row['mail']; echo $row['comment']; echo $row['timestamp']; } } ?> <form id="form1" name="form1" method="post" action="comment2.php?id=<?php echo $id; ?>"> Name: <input name="name" type="text" /> <br /> Mail: <input name="mail" type="text" /> <br /> Kommentar: <textarea type="text" name="comment" cols="50" rows="6"></textarea> <br /> <input name="submit" type="submit" class="submit" value="Send"/> </form> </body> </html> This is table CREATE TABLE `databasename`.`prototype` ( `name` VARCHAR( 50 ) NOT NULL , `mail` VARCHAR( 50 ) NOT NULL , `comment` VARCHAR( 500 ) NOT NULL , `postid` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ) ENGINE = MYISAM What should I do now ? Please help Link to comment https://forums.phpfreaks.com/topic/192130-what-is-wrong-with-this/#findComment-1013000 Share on other sites More sharing options...
jl5501 Posted February 16, 2010 Share Posted February 16, 2010 $commen = mysql_real_escape_string($_POST['comment']); is that meant to be $comment ? Link to comment https://forums.phpfreaks.com/topic/192130-what-is-wrong-with-this/#findComment-1013004 Share on other sites More sharing options...
nimzrocks Posted February 16, 2010 Author Share Posted February 16, 2010 Yes you are right it is comment but nothing happened even i corrected it any help ? Link to comment https://forums.phpfreaks.com/topic/192130-what-is-wrong-with-this/#findComment-1013013 Share on other sites More sharing options...
gizmola Posted February 16, 2010 Share Posted February 16, 2010 This is kind of a mess. Let's start with your database. What is the table structure that these comments are going to be related to? Please don't say postid, because you have defined that column to be the primary key, and auto_increment. Link to comment https://forums.phpfreaks.com/topic/192130-what-is-wrong-with-this/#findComment-1013030 Share on other sites More sharing options...
freakstyle Posted February 17, 2010 Share Posted February 17, 2010 The error is saying that you are not passing the variable "id" along with the form. Looking back through your posts it is unclear as to why you would want a user to set the id of the post, if that's the use you intended it to have, then you simply need to add a new text input field with the name "id" and allow users to enter the id for that post. Typically the post id would be set incrementally in your database table. I don't see your table schema anywhere so we can't help with that side of it. The script below will output the contents of the posted data from your form, in case you aren't sure how to do that. echo '<pre>'; print_r($_POST); echo '</pre>'; Good luck. Link to comment https://forums.phpfreaks.com/topic/192130-what-is-wrong-with-this/#findComment-1013475 Share on other sites More sharing options...
gizmola Posted February 18, 2010 Share Posted February 18, 2010 There's another thread by the OP that covers the same ground. I'm locking this one so nobody else wastes their time. Link to comment https://forums.phpfreaks.com/topic/192130-what-is-wrong-with-this/#findComment-1014119 Share on other sites More sharing options...
Recommended Posts