NameSilo

PHP Help

Spaceship Spaceship
Watch
Impact
12
Hi can someone help me in adding a page id to the database in this php comment system tutorial

tutorial: http://tutorialzine.com/2010/06/simple-ajax-commenting-system/

I have added a extra field in the database table called "page_id"

on the demo.php page i have added:

PHP:
$id=$_GET['id'];

and also included a extra hidden field:
PHP:
 <label for="page_id"></label>
            <input type="text" id="page_id" name="page_id" value="<?php echo $id;?>" />

and then in the submit.php file my insert looks like

PHP:
	mysql_query("	INSERT INTO comments(name,url,email,body,page_id)
					VALUES (
						'".$arr['name']."',
						'".$arr['url']."',
						'".$arr['email']."',
						'".$arr['body']."','
						'".$arr['page_id']."','
					)");
	$arr['dt'] = date('r',time());
	$arr['id'] = mysql_insert_id();

for some reason its not working, if someone can help it will be much appreciated!

Thanks!
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Try changing $_GET to $_POST or $_REQUEST
 
0
•••
I changed $id=$_GET['id']; to POST, however it doesnt work. it does grab the ID on that page so I dont think I need to edit that on the submit.php page. The problem I think is on submit.php page as it doesnt grab the id :s
 
0
•••
Are you saying that the id doesn't get posted into the database? Can you post everything from the submit page?
 
0
•••
PHP:
<?php
// Error reporting:
error_reporting(E_ALL^E_NOTICE);

include "connect.php";
include "comment.class.php";

/*
/	This array is going to be populated with either
/	the data that was sent to the script, or the
/	error messages.
/*/

$arr = array();
$validates = Comment::validate($arr);

if($validates)
{
	/* Everything is OK, insert to database: */
	
	mysql_query("	INSERT INTO comments(name,url,email,body,page_id)
					VALUES (
						'".$arr['name']."',
						'".$arr['url']."',
						'".$arr['email']."',
						'".$arr['body']."','
						'".$arr['page_id']."',
					)");
	$arr['dt'] = date('r',time());
	$arr['id'] = mysql_insert_id();
	
	/*
	/	The data in $arr is escaped for the mysql query,
	/	but we need the unescaped variables, so we apply,
	/	stripslashes to all the elements in the array:
	/*/
	
	$arr = array_map('stripslashes',$arr);
	
	$insertedComment = new Comment($arr);

	/* Outputting the markup of the just-inserted comment: */

	echo json_encode(array('status'=>1,'html'=>$insertedComment->markup()));

}
else
{
	/* Outputtng the error messages */
	echo '{"status":0,"errors":'.json_encode($arr).'}';
}

?>
 
0
•••
The id comes from the page url. Then gets pull to the form. And then goes from the form to submit.php, correct? And you said it correctly gets inserted into the hidden field of the form....Hmm.

It looks like you are using the class provided by them, correct? I think there is something in that class that doesn't exactly know what to do with your page_id addition. Did you check if something needed to be added there?

It appears to be something with the $data portion of comment.class.php

// If the data is valid, sanitize all the data and copy it to $arr:
foreach($data as $k=>$v){
$arr[$k] = mysql_real_escape_string($v);
}

page_id might not be copied back into $arr somewhere along the line.
 
0
•••
umm.. thanks I'll see what I can come up with
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back