PHP Help

Discussion in 'PHP' started by bulldogjjb4, Oct 29, 2010.

  1. #1
    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:

    $id=$_GET['id'];
    PHP:
    and also included a extra hidden field:
     <label for="page_id"></label>
                <input type="text" id="page_id" name="page_id" value="<?php echo $id;?>" />
    PHP:
    and then in the submit.php file my insert looks like

    	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();
    PHP:
    for some reason its not working, if someone can help it will be much appreciated!

    Thanks!
     
    bulldogjjb4, Oct 29, 2010 IP
  2. KingOle

    KingOle Peon

    Messages:
    69
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    replace $arr['page_id'] with $id?

    Also make sure $id=$_GET['id']; is validated appropiately from SQL injections; mysql_real_escape_string and is_numeric(); (assuming the value is a number)
     
    KingOle, Oct 29, 2010 IP
  3. S1M

    S1M Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Are the other values being inserted? Or is the whole query failing?
     
    S1M, Oct 30, 2010 IP
  4. Gediminas

    Gediminas Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Add or die(mysql_error()); after mysql_query(), should output wheres the problem, if the problem is in your query
     
    Gediminas, Nov 2, 2010 IP