0

I have two table named: Blog for displaying blogs post and comments for displaying comments section for each blog post.

The fields for these are as follows:

For Blog:

1: blog_id

2: title

3: body

4: author

5: updated

For Comments:

1: comments_id

2: username

3: email

4: comment_body

5: blog_id

Now what i want is that suppose for blog_id = "2", I am writing comment, so what would be the insert query so that when i visit index.php?blog_id=2, I get the comments for only that particular post.

I mean how to insert the comments for a particular blog_id?

I tried this query to insert:

INSERT INTO cms.comments(blog_id, name,email,comments_body)
                VALUES (
                    '".$arr['blog_id']."',
                    '".$arr['name']."',

                    '".$arr['email']."',
                    '".$arr['comments_body']."'
                ) WHERE cms.blog.blog_id = '$cms.blog.blog_id'");

I tried the foreign key concept : SELECT @last := LAST_INSERT_ID(), but coud not understand how to use this.

Edited by amityadav9314: n/a

4
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by SANJAY26
0

To insert the comment you'll have to know to which blog entry it belongs.
To insert a comment for entry with id=2, use:

INSERT INTO cms.comments(blog_id, name,email,comments_body) VALUES (2, 'theName', 'theMail', 'theComment' );

You cannot use a WHERE clause in an INSERT statement.

0

You can't use a WHERE clause with an INSERT statement. You are inserting a new row so matching on a WHERE clause makes no sense. As a blog can have many comments searching in the comments table by blog_id isn't a good idea anyway (except for SELECT of course but you wouldn't want to do that with an UPDATE).

0

But that was for just blog_id = 2, what if I want to insert blog_id as a variable?
May be something like this: $blog_id ?

0

To insert the comment you'll have to know to which blog entry it belongs.
To insert a comment for entry with id=2, use:

INSERT INTO cms.comments(blog_id, name,email,comments_body) VALUES (2, 'theName', 'theMail', 'theComment' );

You cannot use a WHERE clause in an INSERT statement.

But that was for just blog_id = 2, what if I want to insert blog_id as a variable?
May be something like this: $blog_id ?

1

Your blog_id will need to be inserted, most probably from a variable that you have stored on the page. The name you give it is up to you. We were both just saying that your SQL statement was incorrect in including a WHERE clause.

0

rivate Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click


Call ImageRetrieve()
End sub

Private Sub ImageRetrieve()
imgsave2.Update()
Dim OleDbConnection1 As New System.Data.OleDb.OleDbConnection("PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=D:\Testing\DATABASE\TESTING.MDB;PERSIST SECURITY INFO=FALSE;")
OleDbConnection1.Open()
Dim OleDbSelectCommand1 As System.Data.OleDb.OleDbCommand = New System.Data.OleDb.OleDbCommand()
Dim OleDbReader1 As System.Data.OleDb.OleDbDataReader

'Access (OleDb)
OleDbSelectCommand1.CommandText = "Select h1_img,h2_img,h3_img,h1_sign,h2_sign,h3_sign from vLOCKER WHERE lockerno = " & TextBox1.Text & ""
OleDbSelectCommand1.Connection = OleDbConnection1

' RUN THE COMMAND
OleDbReader1 = OleDbSelectCommand1.ExecuteReader()
OleDbReader1.Read()
Dim Len1 As Long = OleDbReader1.GetBytes(0, 0, Nothing, 0, 0)
Dim Array1(CInt(Len1)) As Byte
OleDbReader1.GetBytes(0, 0, Array1, 0, CInt(Len1))

OleDbConnection1.Close()

Dim MemoryStream1 As New System.IO.MemoryStream(Array1)
Dim Bitmap1 As New System.Drawing.Bitmap(MemoryStream1)
imgsave2.Image = Bitmap1
End Sub
image retrieve from access database but can"t loop in database

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.