Jump to content

strange problem with php insert code


mostafa581

Recommended Posts

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 ";}

}

Link to comment
Share on other sites

 

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.