SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Update statement with querystring

    Hey,

    I have the code below where i want to update fields in my database. Now i know the insert statement does work because i have tested it with test data.

    But when i do the following:-

    $update_thread = "UPDATE threads SET thread_message = '".$_POST['txt_subject']."' WHERE thread_id =" .$_GET['thread_id'];
    $add_member = mysql_query($update_thread);

    $update_post = "UPDATE posts SET post_message = '".$_POST['txt_subject']."' WHERE thread_id =". $_GET['thread_id'];
    $add_member = mysql_query($update_post);

    header("Location: http://www.listentotheconstituents.com/posts.php?post_id=" .$_GET['post_id']. "&thread_id=" .$_GET['thread_id']);
    It does not pick up ANY of the lines that have this .. $_GET['thread_id']

    Why is this?

    Thanks

  2. #2
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What do you mean by saying "it does not pick up"?

    Try outputting the variables ($output_thread and $update_post) and see what it gives.

    Also, use [php][/php] tags for PHP code — it will be much more legible.

    And read about SQL injection because your code is prone to it.

  3. #3
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    I have tried to output the querystring like so:-

    PHP Code:
    echo $_GET['thread_id']; //This code works fine    
    echo $_GET['post_id']; //This code works fine    
                    
    $thread_id $_GET['thread_id']; //This does not seem to GET the thread_id                
    $post_id $_GET['post_id']; //This does not seem to GET the post_id 
    When i 'echo' out the querystring it works fine...

    Why does the code not work when i use variables to get the id's in the querystring? This prevents my update statement from working..

    Regards

  4. #4
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can someone please help me figure this out because i dont understand why it does not work

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The code you posted does work.
    PHP Code:
    echo $_GET['thread_id']; //This code works fine    
    echo $_GET['post_id']; //This code works fine    
                    
    $thread_id $_GET['thread_id']; //This does not seem to GET the thread_id                
    $post_id $_GET['post_id']; //This does not seem to GET the post_id

    echo $thread_id;
    echo 
    $post_id
    Now, this doesn't mean that $thread_id and $post_id will contain a value in all parts of your script, but they sure contain the value there. Are you using includes, or user defined functions?

  6. #6
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    Thanks for your reply. now i have just tried echoing out the variables and they do work, therefore that means that this code should work..?

    I am using an include file for the database connection..

    PHP Code:
                    if (isset($_POST['button_update']))
                    {     
                    include(
    "conn.php");
                              
                    
    $thread_id $_GET["thread_id"]; //This does not seem to GET the thread_id                
                    
    $post_id $_GET["post_id"]; //This does not seem to GET the post_id
                                
                    //check for blank fields
                    
    if ($_POST['txt_subject'] == "")
                    {    
                       echo 
    "<p style=margin-left:5px;width:660px;font-size:12px;border:1px solid blue><img src=images/warning_48.png width=20px> You did not complete all of the required fields.</p>";
                    }
                                                                 
                    else 
                    {
                    include(
    "conn.php"); 

                    
    $update_thread "UPDATE threads SET thread_message = '".$_POST['txt_subject']."' WHERE thread_id =" $thread_id
                    
    $add_member mysql_query($update_thread);
                    
                    
    $update_post "UPDATE posts SET post_message = '".$_POST['txt_subject']."' WHERE thread_id =" $thread_id;
                    
    $add_member mysql_query($update_post);

                    
    header("Location: http://www.listentotheconstituents.com/posts.php?post_id=" .$post_id"&thread_id=" $thread_id);
                    }
                    } 
    this code does not work, it does not do the UPDATE statement becuase it does not recosginze $post_id and $thread_id.. This is drving me nuts ive been tryging to get it working but have had no luck

  7. #7
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are using $_POST and $_GET interchangeably. Is this intended?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •