Jump to content

[SOLVED] Not Updating


php?

Recommended Posts

Okay so according to the code below when I press accept it should update the field "Active" to 1 and then send it to a different table and delete it from the old table. Well it won't update the value of active to 1. It sends and everything, but the Active stays to 0. No errors are given.

 

   foreach($_POST['row_s'] as $key => $val){
         $info = mysql_fetch_array(mysql_query("SELECT * FROM pending WHERE ID='".$key."'"));
            if($val == 1) {
                  echo "{$info['Username']} is being accepted...";
                  [b]$update = mysql_query("UPDATE pending SET Active=1 WHERE ID='".$key."'") or die(mysql_error());[/b]
mysql_query("INSERT INTO accepted SET 
                  Username='".$info['Username']."',
                  Password='".$info['Password']."',
                  Email='".$info['Email']."'"); // Moves user to new table
                  echo "done <br>\n";

Link to comment
Share on other sites

mhm

 

Heres my set up...

 

CREATE TABLE `pending` (
  `ID` int(11) NOT NULL auto_increment,
  `Username` varchar(255) NOT NULL,
  `Password` varchar(255) NOT NULL,
`Email` varchar(255) NOT NULL,
`Active` int(11) NOT NULL default '0',
`Level_access` int(11) NOT NULL default '2',
PRIMARY KEY  (`ID`),
  UNIQUE KEY `Username` (`Username`),
  UNIQUE KEY `Email` (`Email`)
) ENGINE=MyISAM;

Link to comment
Share on other sites

Thorpe this doesn't really have anything to do with the seperation of the tables. Yes I could do what you suggested before but it wouldn't solve this. In fact I would have to do almost the same thing.

 

 

And every topic that ive posted have been solved and were different issues. I'm just adding different parts into the script.

Link to comment
Share on other sites

this doesn't really have anything to do with the seperation of the tables. Yes I could do what you suggested before but it wouldn't solve this

 

Maybe not, but it would be a better design.

 

And every topic that ive posted have been solved and were different issues. I'm just adding different parts into the script.

 

Just a word of caution. Alot of your topics have been so closely related that they could all go within the same thread. Obviously your solutions have not been sufficient thus far.

Link to comment
Share on other sites

Last time I posted a lot combined someone said I should seperate them so people don't get bored... just following suggestions.

 

Besides it's not very appealing to read through many old comments to find out that that particular problem was solved.

Link to comment
Share on other sites

the code below when I press accept it should update the field "Active" to 1 and then send it to a different table and delete it from the old table

 

What is the point in updating Active to 1 in the pending table if you are planning on removing it all together? I just don't follow your logic at all.

Link to comment
Share on other sites

heres what you should do to debug..

 

first echo something inside that condition to know if the statement inside that condition is being read

echo your query and run it manually in your db

 

create an update statement in you DB(phpmysql if you use that) and copy the working code to see where you went wrong..

Link to comment
Share on other sites

Criticism;

 

Your table layout is attrocious. Follow the simple principles of Relational Database Design

 

2.) Do you have any error output?

 

3.) What happens when you issue the query (queries?) directly?

 

4.) Some cleaner code for you:

 

foreach($_POST['row_s'] as $key => $val){
	$res = mysql_query("SELECT Username, Password, Email FROM pending WHERE ID = '{$key}'")
        $info = mysql_fetch_array($res);
            if($val == 1) {
                  echo "{$info['Username']} is being accepted...";
                  mysql_query("UPDATE pending SET Active = 1 WHERE ID = '{$key}'") or die(mysql_error());
mysql_query("INSERT INTO accepted SET 
                  Username='{$info['Username']}',
                  Password='{$info['Password']}',
                  Email='{$info['Email']}'"); // Moves user to new table
                  echo "done <br />\n";

 

Using a second table to 'activate' users is just.. well. Dumb design. And a total, pointless waste of time. You're updating a table, then copying the data to a, most likely match, table with only 1 field modified (Active). Fix your logic and people may be more willing to help. Bad logic dictates bad code (check out thedailywtf.com for good examples of what NOT to do).

Link to comment
Share on other sites

Im about to shut down my pc and go home but this tread is going no where..

 

TO php? i understand his felling frustration about the work...  when you fell like your mind stop functioning you need help not critics..

he cant solved the prob everybody is saying that his logic is wrong but maybe php? doesnt want to edit his code simply because he doesnt want to encounter another problem..

 

this message by php? should be understandable by yopu guys IM NOT native english bu i do UNDERSTAND THIS

Could someone who actually wants to help and not criticize read this?

 

for those who said that his coding and logic is wrong then you should correct it.. i was  actually planning to rewrite this but i have go home office time is over..

 

 

 

Link to comment
Share on other sites

Note that I did, in fact, throw some pointers his way.

 

Without understand the logic (???) of this application, there is really no way anyone can help him.

 

I cleaned up his code a bit (readability for the win). But that's about all I can actually do without seeing:

 

Table layout.

More code.

Understanding of the 'logic' behind this.

 

You don't become a better developer by avoiding criticism. You become a better developer by getting criticism, accepting it and adjusting your model accordingly.

 

I'll always criticize code, especially if they tell me not to. That's a giant, flashing red light right there.

 

Avoiding problems by creating more is the worst thing that can be done. Fix the problems before they present themselves and life is much, much easier. Maintaining a broken codebase and bad logic is hard. I've been there and done that.

 

I asked him for error output, what happens when he tries it at the console (or via phpMyAdmin), etc.

 

He was told how to correct his logic. He isn't paying me to write his code, but I'm willing to help him make it work well and be easy to maintain in the future. Even with his boo-hoo tirade, I'm still willing to help if he's willing to provide more information.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.