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 7511903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:42:12+00:00 2026-05-29T23:42:12+00:00

Sorry, I’m not sure how to really word my question. Here it goes. If

  • 0

Sorry, I’m not sure how to really word my question. Here it goes.

If you go to my page http://www.eveo.org/stack/view.php you will notice on the right hand side there are links that read “restore” and “delete”. If it says restore, the value for the “deleted” table in the database is “y”.

The problem: When I click on a link, all of them change, not just the one. What I need to do is when I click on “delete” or “restore” on any of them, only that row will delete and restore and only will that rows link update, with all the others staying the same. The value in the database has to change from “y” to “n” or vice versa depending on the link.

The code that currently changes my link for all of them is:

echo "<td><a href='view.php?'>";

    $y="$row[deleted]";
    $x="$row[id]";

    if ($y == 'n'){
        mysql_query("UPDATE inventory SET deleted = 'y' WHERE id='$row[id]'");
        echo "delete";
    }
    else if ($y == 'y'){
        mysql_query("UPDATE inventory SET deleted = 'n' WHERE id='$row[id]'");
        echo "restore";
    }

echo"</a></td>";

I’ve been trying to solve this for hours, and it’s not working.

Requirements: It has to use URL rewriting, so I can’t do this change thing with javascript or something, personally I would have, but these are my professors requirements.

Source code:

VIEW.PHP

<?php { ?>
    <table border="0" cellpadding="0" cellspacing="0" id="table">
        <thead>
            <tr>
                <th>ID</th>
                <th>NAME</th>
                <th>MANUFACTURER</th>
                <th>MODEL</th>
                <th>DESCRIPTION</th>
                <th>ON HAND</th>
                <th>REORDER</th>
                <th>COST</th>
                <th>PRICE</th>
                <th>SALE</th>
                <th>DISCOUNT</th>
                <th>DELETE</th>
            </tr>
        </thead>
        <tbody>
            <?php } ?>
                <?php

                    // while($r = mysql_fetch_array($resultDeleted)) 
                    // {
                        // echo $r[0];
                    // }

                ?>
                <?php while($row = mysql_fetch_array($result)) {

                    echo "<tr>";
                    echo "<td>$row[id]</td>";
                    echo "<td>$row[name]</td>";
                    echo "<td>$row[manufac]</td>";
                    echo "<td>$row[model]</td>";
                    echo "<td>$row[descrip]</td>";
                    echo "<td>$row[onhand]</td>";
                    echo "<td>$row[reorder]</td>";
                    echo "<td>$row[cost]</td>";
                    echo "<td>$row[price]</td>";
                    echo "<td>$row[sale]</td>";
                    echo "<td>$row[discont]</td>";
                    echo "<td><a href='view.php?'>";

                        $y=$row[deleted];
                        $x=$row[id];

                        if ($y == 'n'){
                            mysql_query("UPDATE inventory SET deleted = 'y' WHERE id='$row[id]'");
                            echo "delete";
                        }
                        else if ($y == 'y'){
                            mysql_query("UPDATE inventory SET deleted = 'n' WHERE id='$row[id]'");
                            echo "restore";
                        }

                    echo"</a></td>";
                    echo "</tr>";
                } ?>
            <?php { ?>
        </tbody>
    </table>
<?php } ?>
  • 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-29T23:42:14+00:00Added an answer on May 29, 2026 at 11:42 pm

    It looks like you are trying to get a $_GET variable using the code:

    $y="$row[deleted]";
    $x="$row[id]";
    

    This is never going to work. First of all you don’t need to add double quotes around your variables. Second the correct syntax for getting the $_GET variables is:

    $delete = $_GET['delete'];
    $id = $_GET['id'];
    

    As you can see I have given your variable names better descriptive names.

    Second, when you are just adding those variables to a query you will have a huge SQL injection hole in your application:

    mysql_query("UPDATE inventory SET deleted = 'y' WHERE id='$id'");
    

    What if I was a hacker I would add an id of: 1' or 1=1, which would result in the following query:

    UPDATE inventory SET deleted = 'y' WHERE id='1' OR 1=1
    

    And suddenly I set the deleted status of all records in the table. I could even get into others tables using this attack in do whatever I want.

    So you should always use mysql_real_escape_string():

    $id = mysql_real_escape_string($_GET['id']);
    
    mysql_query("UPDATE inventory SET deleted = 'y' WHERE id='$id'");
    

    So what you will get is the following:

    $delete = mysql_real_escape_string($_GET['delete']);
    $id = mysql_real_escape_string($_GET['id']);
    
    mysql_query("UPDATE inventory SET deleted = '$delete' WHERE id='$id'");
    

    Another thing is that you don’t need to keep opening and closing the PHP tags. Only if you want to add some HTML.

    Next:

    instead of echoing all that stuff simply use HEREDOC:

    So instead of doing:

                    echo "<tr>";
                    echo "<td>$row[id]</td>";
                    echo "<td>$row[name]</td>";
                    echo "<td>$row[manufac]</td>";
                    echo "<td>$row[model]</td>";
                    echo "<td>$row[descrip]</td>";
                    echo "<td>$row[onhand]</td>";
                    echo "<td>$row[reorder]</td>";
                    echo "<td>$row[cost]</td>";
                    echo "<td>$row[price]</td>";
                    echo "<td>$row[sale]</td>";
                    echo "<td>$row[discont]</td>";
                    echo "<td><a href='view.php?'>";
    

    You can simply do:

    echo <<<HTML
    <tr>
    <td>{$row['id']}</td>
    <td>{$row['name']}</td>
    etc
    FOOBAR;
    

    As you can see it need quotes to get an array element.

    After that you should build your links:

    $delete = 'n';
    if ($row['deleted'] == 'n') {
        $delete = 'y';
    }
    echo '<a href="view.php?id=' . $row['id'] . '&delete=' . $delete . '">delete</a>';
    

    As a general note:

    ALWAYS ENABLE FULL ERROR REPORTING ON DEV ENVIRONMENT so you can see what the f*&k is going on / wrong. So place this at the top of your scripts:

    error_reporting(E_ALL | E_STRICT);
    ini_set('display_errors', 1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry but I am not sure how to ask this question but I am
sorry if the title is worded oddly, not really sure how to say it.
sorry for lamer question, but I really could not found subject. I have a
Sorry about the title to this question, it's not very clear but wasn't sure
Sorry I could not find this. $('div#loader').slideDown(fast).delay(1.5); Does not word as expected, I want
Sorry for real stupid question. But it does not work either way. <html> <head>
Sorry I'm new here and my code will probably not be properly displayed... how
Sorry, I'm sure this is a stupid question. I have successfully installed python 2.6
Sorry for this not being a real question, but Sometime back i remember seeing
Sorry for the second newbie question, I'm a developer not a sysadmin so this

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.