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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:42:14+00:00 2026-05-11T17:42:14+00:00

Hey all, I want to change a value in a table (in a mysql

  • 0

Hey all, I want to change a value in a table (in a mysql database) via PHP code. I have a row in the table called ‘approved’ and there are two options it can be set to, “0” (not approved) and “1” (approved). I am creating a script that will change an individual approved from “0” to “1”.

For example, there is a different value called ‘position’ and ‘approved’ sets the ‘position’ as approved or not approved (where approved is set to 1 or 0). If that is worded wrong, I will try to make it more clear.

I guess my question is can I make an individual ‘position’ value have its ‘approved’ data be switched from 0 to 1 and vice versa.

Thanks!

EDIT/UPDATE:

here’s the info from the dump for this specific table:

 CREATE TABLE `positions` (
  `posID` int(10) unsigned NOT NULL auto_increment,
  `postitle` varchar(500) NOT NULL default '',
  `addtitletext` varchar(35) default NULL,
  `description` text NOT NULL,
  `print_website` enum('1','2') NOT NULL default '1',
  `userID` tinyint(4) unsigned NOT NULL default '0',
  `submitted_on` datetime NOT NULL default '0000-00-00 00:00:00',
  `approved_date` date NOT NULL default '0000-00-00',
  `approved` enum('0','1') NOT NULL default '0',
  PRIMARY KEY  (`posID`)
) ENGINE=MyISAM AUTO_INCREMENT=464 DEFAULT CHARSET=latin1;

LOCK TABLES `positions` WRITE;
/*!40000 ALTER TABLE `positions` DISABLE KEYS */;
INSERT INTO `positions` (`posID`,`postitle`,`addtitletext`,`description`,`print_website`,`userID`,`submitted_on`,`approved_date`,`approved`)
VALUES

and I was trying to edit this code here to make it change from not approved to approved (or vice versa)

    <? 
include('secure.php');
include('config.php'); 

if (isset($_POST['submitted'])) { 
foreach($_POST AS $key => $value) { $_POST[$key] = mysql_real_escape_string($value); } 
$sql = "UPDATE `positions` SET `approved` =  '{$_POST['approved']}'"; 
mysql_query($sql) or die(mysql_error()); 
echo (mysql_affected_rows()) ? "Edited row.<br />" : "Nothing changed. <br />"; 
echo "<a href='list.php'>Back To Listing</a>"; 
} 
$row = mysql_fetch_array ( mysql_query("SELECT * FROM `positions` WHERE `posID` = '$posID' ")); 




?>

<form action='' method='POST'> 
<p><b>Approved:</b><br /><input type='text' name='approved' value='<?= stripslashes($row['approved']) ?>' /> 
<p><input type='submit' value='Edit Row' /><input type='hidden' value='1' name='submitted' /> 
</form> 

If it helps, awesome, but sorry if it is more confusing haha.

EDIT: Here’s what I have, but getting a blank page (errors I know)

<? 
include('secure.php');
include('config.php'); 
if (isset($_GET['posID']) ) { 
$posID = (int) $_GET['posID']; 
if (isset($_POST['submitted'])) { 
foreach($_POST AS $key => $value) { $_POST[$key] = mysql_real_escape_string($value); } 
$sql = "UPDATE `positions` SET `approved` =  '{$_POST['approved']}'  WHERE `posID` = '$posID'"; 
mysql_query($sql) or die(mysql_error()); 
echo (mysql_affected_rows()) ? "Edited row.<br />" : "Nothing changed. <br />"; 
echo "<a href='list.php'>Back To Listing</a>"; 
} 

<form action='' method='POST'> 
<p><b>Approved:</b><br /><input type='text' name='approved' value='<?= stripslashes($row['approved']) ?>' /> 
<p><input type='submit' value='Edit Row' /><input type='hidden' value='1' name='submitted' /> 
</form> 
<? } ?> 
  • 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-11T17:42:14+00:00Added an answer on May 11, 2026 at 5:42 pm

    I’m not entirely sure what you are trying to do, because it sounds like approved is a column, not a row, in the table. If you wanted to do something like the following:

    function toggle_approved($position_id) {
    $query = "UPDATE positions SET approved = !approved WHERE posID = '$position_id'";
    // execute the query here with your mysql_query() call
    }
    

    I am assuming you have some method of executing mysql queries, if not see this link. Also make sure you use your table name and position field names.

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

Sidebar

Related Questions

Hey all. Here is the scenario. I have the below code, and I'm needing
hey all i want a code the replace whitespaces by a + sign in
Hey all, I have a winforms virtualized Listview that i want to be able
Hey all i just want to make sure i am adding the value correctly
Hey All I currently have a problem with my insert php file I have
Hey all i am in need of some help getting my code working correctly
Hey all. Basically I have a page full of text input fields with default
Hey I have a menu(with JQuery) in a div on the left, with all
Hey all I want to reseed my IDENTITY COLUMN values starting from 1 I
Hey all, i want to use a regular expression to match a word with

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.