Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6772809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:35:33+00:00 2026-05-26T15:35:33+00:00

in the following code, i would like to get the row result for column

  • 0

in the following code, i would like to get the row result for column “id” as a result for $selectedmovieid. The ‘commenid’ is the primary key attribute. Sorry for not knowing how to use mysql_fetch_assoc properly.

<?php
require ("connect-comment.php");
$deleteid=$_GET['commentid'];
$query1=mysql_query("SELECT id FROM comment WHERE commentid='$deleteid'");
$selectedmovieid= mysql_fetch_assoc($query1);
$query2=mysql_query("DELETE FROM comment WHERE commentid='$deleteid'");
header("Location: reload.php?id=$selectedmovieid");
?>

EDIT 1: I will do up the security injection much later, just need to get the syntax right and get the right result. So this is what i have done so far:

<?php
require ("connect-comment.php");
$deleteid=$_GET['commentid'];
$query1=mysql_query("SELECT id FROM comment WHERE commentid='$deleteid'");
while ($selectedmovieid= mysql_fetch_assoc($query1))
{echo $selectedmovieid['id'];};
$query2=mysql_query("DELETE FROM comment WHERE commentid='$deleteid'");
header("Location: reload.php?id=$selectedmovieid");
?>

Now this doesn’t make much sense to me cos i am not parsing the correct $selectedmovieid value into the reload.php?id=

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:35:33+00:00Added an answer on May 26, 2026 at 3:35 pm

    Try changing

    $deleteid=$_GET['commentid'];
    // ...
    header("Location: reload.php?id=$selectedmovieid");
    

    to

    $deleteid = mysql_real_escape_string($_GET['commentid']);
    // ...
    header("Location: reload.php?id={$selectedmovieid['id']}");
    

    Also, as Pekka rightly suggests, try reading the manual page for mysql_fetch_assoc() and reading up on SQL injection.

    As a side note, you should not use relative paths for Location: header redirects. RFC’s specify that this field should contain a full URL and, while many browsers will correctly interpret relative paths, this behaviour should not be relied upon. In other words, Location: reload.php?id=... should be Location: http://mysite.tld/reload.php?id=

    EDIT Try this complete version of your sample code:

    <?php
    
      require ("connect-comment.php");
      $deleteid = mysql_real_escape_string($_GET['commentid']);
    
      // Added LIMIT 1 to the query, because you are only using one result
      if (!$query1 = mysql_query("SELECT `id` FROM `comment` WHERE `commentid` = '$deleteid' LIMIT 1")) {
        // Do NOT show the output of mysql_error() to the user in a production environment!
        exit("Something went wrong with query 1: ".mysql_error());
      } else if (mysql_num_rows($query1) < 1) {
        exit("No results from query 1");
      }
      $selectedmovieid = mysql_fetch_assoc($query1);
      $selectedmovieid = $selectedmovieid['id']; // $selectedmovieid now contains the id you want
    
      if (!$query2 = mysql_query("DELETE FROM `comment` WHERE `commentid` = '$deleteid'")) {
        // Do NOT show the output of mysql_error() to the user in a production environment!
        exit("Something went wrong with query 2: ".mysql_error());
      }
    
      // If we get this far, everything should be fine
      // You still need a full URL here though, not a relative path...
      header("Location: reload.php?id=$selectedmovieid");
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the following code I would like the div with 'y' to match the
I have the following code, which works as I expect. What I would like
I have the following html code: <h3 id=headerid><span onclick=expandCollapse('headerid')>&uArr;</span>Header title</h3> I would like to
I have the following snippet where I would like to extract code between the
I would like to do something like the following: def add(a, b): #some code
I have code, similar to the following, that I would like to modify: Sub
I am confused as to why the following code snippet would not exit when
I have the following code and where if 1 row is found I would
I'm curious if following code would be considered safe? using (SqlConnection cn = new
Given the Following Code how Would i Change/Set my Silverlight WCF Service URI in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.