Jump to content

What is wrong with this ?


nimzrocks

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

Guest
This topic is now 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.