How to delete MySql database row with PHP button -


i have backend website setup displays users on site in organised table, should able edit , delete users php page. cannot delete function work, here code.

data_display.php

<?php     include('session.php'); ?> <?php include ("db.php"); ?> <?php     $sql = "select * username order usernameid desc";      $query = mysql_query($sql) or die(mysql_error());      if (isset($_get['usernameid'])) {          $id = mysql_real_escape_string($_get['usernameid']);         $sql_delete = "delete users id = '{$usernameid}'";         mysql_query($sql_delete) or die(mysql_error());          header("location: data_display.php");         exit();      }  ?> <!doctype html> <html lang="en">  <head>     <link rel="icon" type="image/ico" href="favicon.ico">     <title>network tv - records</title>     <meta charset="utf-8" />     <link rel="stylesheet" type="text/css" href="style.css"> </head>  <body >     <div class="container">         <div class="content">             <h1>network tv users , user control panel</h1>             <br>             <div class="toolbar">                 <a href="form_display.php">add new person</a>                 <a href="\1\index.php">home</a>             </div>             <br>         </div>     </div>     <div class="container">              <div class="content">             <?php if (mysql_num_rows($query)) { ?>                 <?php while ($rows = mysql_fetch_assoc($query)) { ?>             <div class="separator"></div>             <h2><b>user reference:</b> <?php echo $rows['usernameid']; ?></h2>             <h2><b>name:</b><?php echo $rows['name']; ?></h2>             <h2><b>email address:</b> <?php echo $rows['email']; ?></h2>             <h2><b>gender:</b> <?php echo $rows['sex']; ?></h2>             <h2><b>profile picture:</b> <?php echo $rows['imagelink']; ?></h2>             <div class="toolbar">                 <a href="form_edit_display.php?id=<?php echo urlencode($rows['usernameid']); ?>">edit</a>                 <a href="javascript:void(0);" onclick="confirmdelete('are sure want delete record #<?php echo $rows['usernameid']; ?>? operation cannot undone.', 'data_display.php?recordid=<?php echo urlencode($rows['usernameid']); ?>');">delete</a>             </div>             <?php } /* end loop */ ?>             <div class="separator"></div>             <?php } else { ?>             <div class="separator"></div>             <h2>there no records display</h2>             <div class="separator"></div>             <?php } /* end rows checking */?>         </div>     </div>     <div class="container">         <br>         <br>         <br>         <br>         <br>     </div>     <script>         function confirmdelete ( message, url )          {             var confirmation = confirm ( message );              if ( confirmation == true ) {                 window.location = url;             } else {                 return false;             }         }     </script> </body>  </html> 

session.php

<?php // establishing connection server passing server_name, user_id , password parameter $connection = mysql_connect("localhost", "root", "oliver"); // selecting database $db = mysql_select_db("users", $connection); if(!isset($_session)){session_start();} // storing session $user_check=$_session['login_user']; // sql query fetch complete information of user $ses_sql=mysql_query("select username username username='$user_check'", $connection); $row = mysql_fetch_assoc($ses_sql); $login_session =$row['username']; if(!isset($login_session)){     mysql_close($connection); // closing connection     header('location: home.php'); // redirecting home page } ?> 

db.php

<?php     $connection = mysql_connect('localhost', 'root', 'oliver');     mysql_select_db('users', $connection) or die(mysql_error()); ?> 

information when click delete button in data_display.php, receive javascript alert confirm want delete user database, nothing happens.

if (isset($_get['recordid'])) {     $id = mysql_real_escape_string($_get['recordid']);     $sql_delete = "delete users id = '{$id}'";     mysql_query($sql_delete) or die(mysql_error());      header("location: data_display.php");     exit();  } 

you sending recordid parameter.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -