razorsese Posted March 27, 2012 Share Posted March 27, 2012 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; }); Quote Link to comment https://forums.phpfreaks.com/topic/259821-php-problem/ Share on other sites More sharing options...
smerny Posted March 27, 2012 Share Posted March 27, 2012 try putting a space between * and FROM also, you can do this to see the error in the query... $req = mysql_query($dbh) or die("MySQL Error: ". mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/259821-php-problem/#findComment-1331608 Share on other sites More sharing options...
litebearer Posted March 27, 2012 Share Posted March 27, 2012 Also seriously need to validate/sanitize your post values BEFORE you attempt to use them Quote Link to comment https://forums.phpfreaks.com/topic/259821-php-problem/#findComment-1331612 Share on other sites More sharing options...
razorsese Posted March 28, 2012 Author Share Posted March 28, 2012 Still the same problem and mysql_error()) don't report anything Quote Link to comment https://forums.phpfreaks.com/topic/259821-php-problem/#findComment-1331980 Share on other sites More sharing options...
smerny Posted March 28, 2012 Share Posted March 28, 2012 what exactly is it doing? are you getting empty list items? or nothing at all that is within the mysql loop? if you aren't even getting the empty list items sent to the browser, then it would appear that nothing in the comments database matches the threadid you are supplying? Quote Link to comment https://forums.phpfreaks.com/topic/259821-php-problem/#findComment-1331989 Share on other sites More sharing options...
razorsese Posted March 28, 2012 Author Share Posted March 28, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/259821-php-problem/#findComment-1331997 Share on other sites More sharing options...
Vel Posted March 28, 2012 Share Posted March 28, 2012 if($name & $comment) Should be if($name && $comment) And as others have pointed out, validate/sanitize your code before putting them anywhere near an SQL statement. Quote Link to comment https://forums.phpfreaks.com/topic/259821-php-problem/#findComment-1331999 Share on other sites More sharing options...
razorsese Posted March 28, 2012 Author Share Posted March 28, 2012 After I inspected whit FireBug in console log the values appear correctly but for some reason don't appear in the html page Quote Link to comment https://forums.phpfreaks.com/topic/259821-php-problem/#findComment-1332012 Share on other sites More sharing options...
Vel Posted March 28, 2012 Share Posted March 28, 2012 I just noticed your Ajax statment, you're not telling the HTML to update. You need to adjust you success statement to: success: function(data) { console.log("dat"); $('.classofdivtobeupdated').html(data); } Quote Link to comment https://forums.phpfreaks.com/topic/259821-php-problem/#findComment-1332014 Share on other sites More sharing options...
razorsese Posted March 28, 2012 Author Share Posted March 28, 2012 Yep.I saw that before entering the forum Quote Link to comment https://forums.phpfreaks.com/topic/259821-php-problem/#findComment-1332020 Share on other sites More sharing options...
Vel Posted March 28, 2012 Share Posted March 28, 2012 Yep.I saw that before entering the forum If you've fixed that, and any other potential mistakes, then you should post your latest code here for us. If you add alert(data); to the success function what do you get? Quote Link to comment https://forums.phpfreaks.com/topic/259821-php-problem/#findComment-1332021 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.