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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:46:02+00:00 2026-06-17T13:46:02+00:00

I’ve pretty much never coded in PHP and MySQL before, so you’ll have to

  • 0

I’ve pretty much never coded in PHP and MySQL before, so you’ll have to excuse my god awful code.

I have a 3 columns in my database. ID, Class, and Need.

Tables

Basically, I’m trying to find the easiest way for me to code a page in order to allow users to change the "Need" value of each row from 0 to 1, or 1 to 0.

Currently I have it working where I have 2 buttons that run 2 separate but almost identical scripts whose only purpose is to change a specific row’s "Need" value to 1 or 0 (shown below)

<?php
mysql_connect("localhost", "muffins", "sugarcookies") or die(mysql_error());
mysql_select_db("crackers_cheese") or die(mysql_error());

mysql_query("UPDATE recruitment SET Need=1
WHERE ID='1'");

mysql_close($con);

header("location: /admin.html"); 
?>

The inverse .php file is identical except for "SET Need=0"

So, what can I do instead of having 22 individual .php files whos only purpose is setting each specific row to 0 or 1.

Thanks!

  • 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-06-17T13:46:03+00:00Added an answer on June 17, 2026 at 1:46 pm

    Have one of your buttons send an HTTP parameter to indicate whether the field should be 0 or 1. Also, look at using the PDO class instead of mysql_* functions.

    Here’s an example of how it can be done using PDO functions:

    PHP code

    <?php
    
    if(!isset($_POST['need'])) {
        die('Missing need parameter');
    } elseif($_POST['need'] !== '0' && $_POST['need'] !== '1') {
        die('Invalid need values');
    }
    
    if(!isset($_POST['id']) || !is_numeric($_POST['id'])) {
        die('Missing ID');
    }
    
    $db = new \PDO('mysql:dbname=crackers_cheese;host=localhost', 'muffins', 'sugarcookies');
    $statement = $db->prepare("UPDATE `recruitment` SET `Need` = :need WHERE `ID`= :id");
    
    $statement->bindValue(':need', $_POST['need'], \PDO::PARAM_INT);
    $statement->bindValue(':id', $_POST['id'], \PDO::PARAM_INT);
    
    $statement->execute();
    
    header("location: /admin.html"); 
    ?>
    

    Note that since you are using a prepared statement here, the data does not need to be escaped using real_escape_string or anything like that, thus mitigating SQL injection attacks.

    It is good practice to use parameter binding instead of concatenating a query to prevent SQL injection attacks. For more information, see: Are PDO prepared statements sufficient to prevent SQL injection?

    HTML form

    <form method='POST' action='update.php'>
        <label for='id'>ID:</label>
        <input type='number' name='id' id='id'>
    
        <input type='radio' name='need' value='0' id='needfalse'> <label for='needfalse'>Need = 0</label>
        <input type='radio' name='need' value='1' id='needtrue'> <label for='needtrue'>Need = 1</label>
    
    <button type='submit'>Submit</button>
    

    This isn’t the best form designed. I’ve used radio buttons here, it would be slightly more complex to do it with actual buttons, but this should be sufficient to get you started.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a reasonable size flat file database of text documents mostly saved in
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.