Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Blog Comment posts not happening

3 views
Skip to first unread message

The Doctor

unread,
Sep 10, 2015, 10:28:37 PM9/10/15
to
All right another using MySQL.

Objectives

For this portion of your project, modify the script used to display your blogs (referenced as showBlog.php in the previous project). Add a form to this script into which guests can enter comments. Your form should ask for the author's name, comments, and if desired, email, link, or image URL. The PHP script should gather the form information and add it to your SQL table, using the now() function to include the entry date.

Keep in mind that you will have to obtain the postId of the blog which is currently displayed so that you can insert this along with your comment!

You should also make it so that the script will then list the comments that belong to the blog. Again, you will have to use postId to determine which comments go with which blog.

Again, be creative! When finished, hand in both PHP files.


guestentry.html reads


<html>
<head><title>This the Guest Entry</title></head>
<body>
<h1>Guest Entry!</h1>
<form action="/phpsql/lab11/obj2/guestentry.php" method="POST">

Author: <input type="text" name="author" size="100"><br>
Entry: <input type="textarea" name="comment" size="10000"><br>
Optional information:<br>
Email Address: <input type="text" name="email" size="100"><br>
link:<input type="text" name="link" size="100"><br>
image URL:<input type="text" name="imageurl" size="100"><br>
<input type="submit" value="Submit">

</form>
<?php

$command= "select blogId from blogcomments where blogcomments.blogId= blogtable.blogId" ;
}
?>
</body>
</html>

And guestentry.php is

<?php

#----------------------#
# Functions #
#----------------------#

function check_input ($form_array) {
if ($form_array['author'] && $form_array['comment'] ) {
return 1;
}


else return 0;
}



#----------------------#
# User Variables #
#----------------------#

$host = "sql.useractive.com"; //This is the server where your database resides
$user = "user"; //This should be your Sandbox login
$pw = "pw"; //This should be your Sandbox password
$database = "user"; //Your database is the same as your Sandbox login
$table_name = "blogcomments";


#----------------------#
# Main Body #
#----------------------#


if (check_input($_POST)) {


$db = new mysqli($host,$user,$pw,$database)
or die("Cannot connect to MySQL.");

$command= "select blogId from blogcomments where blogcomments.blogId= blogtable.blogId" ;
$result = $db->query($command);


$command = "insert into $table_name values('',
.$data->blogID.,
'".$db->real_escape_string($_POST['author'])."' ,
now(),
'".$db->real_escape_string($_POST['comment'])."'
); ";
$result = $db->query($command);

//$result->free();

print "Data was successfully entered.<br>";





$db->close();


}
else { print "Data was NOT entered due to errors.<br>"; }



?>

Is this not attaching to the blog entry?
--
Member - Liberal International This is doctor@@nl2k.ab.ca Ici doctor@@nl2k.ab.ca
God,Queen and country!Never Satan President Republic!Beware AntiChrist rising!
http://www.fullyfollow.me/rootnl2k Look at Psalms 14 and 53 on Atheism
Time for Stephen to move on on Oct 19 2015!!
0 new messages