0

I have a problem with my php code. It seems that the update syntax doesn't update the table. I have tried everything, i even set the values manually, you know writting the name and the group and it doesn't update anyway. I can't figure out what the problem might be, i'm getting no error nothing, it works exactly how i wrote just that it doesn't update the mysql table. I've checked to see if there are "reserved names" for phpmyadmin but nothing. I'm staring at this code for 2 hours now.

The $action == remove_member is just a thing so when i press an link it shows me this script and html code, nothing too fancy, but something that works, i tried without this thing too, and same result.

Thank's if you can help me.

EDIT: Problem solved, i misstyped the variable $account_name in the syntax.

    <?php if($action == "remove_member") { ?>
            <!-- Remove member by $_GET method -->
            <div class="col-md-6">
                <div class="panel panel-forum">
                  <div class="panel-heading"><i class="fa fa-minus"></i> Remove member</div>
                  <form method="post">
                  <?php 
                  $account_name = stripslashes(mysql_real_escape_string($_GET['account_name']));
                  $group_name = stripslashes(mysql_real_escape_string($_GET['group_name']));

                  if(isset($_POST['remove_member']))
                  {
                    $account_group = "Users";
                    if(mysql_query("UPDATE wb_accounts SET account_group='Users' WHERE account_name='".$acount_name."'"))
                    {
                        header('Location: group_manager.php');
                    }
                    else
                    {
                        header('Location: group_manager.php?action=remove_member&err=Error while trying removing the member !');
                    }
                  }

                  ?>
                  <div class="panel-body">
                    <p><?php echo htmlentities($_GET['err']); ?></p>
                    <p>You're about to remove the next user: </p>
                    <p><i class="fa fa-user"></i> Account name: <b> <?php echo htmlentities($account_name); ?> </b><br>
                    <i class="fa fa-users"></i> Current group: <b> <?php echo htmlentities($group_name); ?></b>
                    </p>
                    <p>Once deleted, default group 'Users' will be apply on the account.</p>
                    <br><p><i> Are you sure you want to delete him anyway? </i></p>

                    <p><input type="submit" name="remove_member" class="btn btn-md btn-primary" value="Yes"/> <a href="group_manager.php" class="btn btn-md btn-primary"> No</a></p>
                    </form>
                </div>
                </div>
            </div>
            <?php } ?>
  • the query sintax seems correct so could be is value in $acount_name that don't match the row .. – ScaisEdge Jun 26 '16 at 18:37
  • 1
    `stripslashes(mysql_real_escape_string($_GET['account_name']));` — Why are you escaping your data immediately after escaping it? – Quentin Jun 26 '16 at 18:38
  • $account_name should be the value i get in the $_GET url. $account_group was i try of mine to get it work, but i haven't used it anyway. – Gabryel Valentin Năstase Jun 26 '16 at 18:38
  • 1
    **Danger**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) that has been [removed](http://php.net/manual/en/mysql.php) from PHP. You should select a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Jun 26 '16 at 18:39
  • @Quentin this is something that i learned from a man who teached me some basic php / mysql stuff. – Gabryel Valentin Năstase Jun 26 '16 at 18:39
  • @GabryelValentinNăstase — He taught you very poorly then. – Quentin Jun 26 '16 at 18:40
  • See also: http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php – Quentin Jun 26 '16 at 18:40
  • @Quentin, problem fixed, i misstyped the word $account_name in the syntax. Thank's for the advices, i tried to learn PDO but is too hard to understand how it actually works. Thank's for your help ! – Gabryel Valentin Năstase Jun 26 '16 at 18:45

0 Answers0