Jump to content

Php problem


razorsese

Recommended Posts

The problem is whit the var $threadid .

It dosent work here(it dosen't display the data from database):  $dbh = "SELECT *FROM comments WHERE threadid = '".$threadid."' ";

But if I assign a value before the that code the html page show correctly.

 

 

include("config.php");

$name = $_POST['name'];
$comment = $_POST['comment'];
$threadid = $_POST['threadid'];

if($name & $comment)
{
	$dbh="INSERT INTO comments (name,comment,threadid) VALUES ('$name','$comment','$threadid') ";
	mysql_query($dbh);


}



  
    
    $dbh = "SELECT *FROM comments WHERE threadid = '".$threadid."' ";
    $req = mysql_query($dbh);
    while($row=mysql_fetch_array($req))
    {
         echo "<li>";
        echo "<br>"."<b>".$row['name']."</b></br>"."<br>".$row['comment']."</br>";
	echo "</li>";
    }

 

$('.submit').click(function(){
		  location.reload();
		var name = $("#name").val();
            var comment = $("#comment").val();


	var threadid  = $("#v").val();

		var dat = 'name='+name+'&comment='+comment+'&threadid='+threadid;

            $.ajax({
			type:"post",
		    url:"comment.php",
			data:dat,
			success:function(){ 
			console.log("dat"); 
			 }
	      });
              
		 return false;

	 });

Link to comment
https://forums.phpfreaks.com/topic/259821-php-problem/
Share on other sites

Well when i submit a comment in the html page the PHP code insert correctly in the database but fails at SELECT * FROM

And also if i manually assign a value to $threadid right before the second query for example 2 in the html page the value from database appear correctly:

 

Without assigned value (Not displaying correctly): http://s17.postimage.org/c1ldbk6gf/example1.png

With assigned value(Displaying correctly):http://s17.postimage.org/8knwmbwrz/example2.png

Link to comment
https://forums.phpfreaks.com/topic/259821-php-problem/#findComment-1331997
Share on other sites

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.