mostafa581 Posted November 30, 2011 Share Posted November 30, 2011 Friends this is a very strange problem i,m facing i made a form by which you can enter comments to a topic i get the comment title and comment topic and date and the name and e mail of the one who insert a comment according to these variables $id1=$row2['id']; echo "$id1"; //Comment poster,s name $name =strip_tags(@$_POST['coname']); //Comment title $title =strip_tags(@$_POST['comtitle']); //ment poster,s email $mail =strip_tags(@$_POST['comemail']); //comment $com =strip_tags(@$_POST['limitedtextarea']); //comment,s date $d= date("Y-m-d"); notice that i,m printing the topic id and i used the variable $id1 to get it inorder to use it to show the comments for this topic later and it shows the right id for the shown topic then i used this code to insert these variable into the database if(isset($_POST['add']) and $_POST['add']=='comm'){ $insertcomm =mysql_query("INSERT INTO comments (com_name,com_title,com_mail,comment,com_date,tid) VALUES ('$name','$title','$mail','$com','$d','$id1')") or die("comments were not inserted"); if(isset($insertcomm)){ echo "comment inserted ";} } Quote Link to comment https://forums.phpfreaks.com/topic/252082-strange-problem-with-php-insert-code/ Share on other sites More sharing options...
MasterACE14 Posted November 30, 2011 Share Posted November 30, 2011 what exactly is the problem you are having? Quote Link to comment https://forums.phpfreaks.com/topic/252082-strange-problem-with-php-insert-code/#findComment-1292445 Share on other sites More sharing options...
mostafa581 Posted December 1, 2011 Author Share Posted December 1, 2011 the problem is i,m building a site that shows news and allow visitors to comment for every news in that page that shows the news you can insert your comment on this news you,re watching you must get the shown news id and insert it with the comment inorder to show all comments related to this news i got this id by the following variable $id1=$row2['id']; echo "$id1"; and when i printed it (for testing if it is working ) it was working properly and show the right id for the shown topic the next step i need to insert it into the database of comments and use it to select all comments related to any topic i used the insert query $insertcomm =mysql_query("INSERT INTO comments (com_name,com_title,com_mail,comment,com_date,tid) VALUES ('$name','$title','$mail','$com','$d','$id1')") or die("comments were not inserted"); the problem is when inserting any test comment and serching the database for it i find it already inserted except that variable $id1 it always shows a( 0 ) inside the database in the field tid although it shows the right id printed on the page i replaced the place of this variable to insert it,s value in any other field for example (in the title of the email ) it also gave the value of 0 Quote Link to comment https://forums.phpfreaks.com/topic/252082-strange-problem-with-php-insert-code/#findComment-1293284 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.