简体   繁体   中英

can't execute php mysql query

I would like execute a query when a mysql record is deleted in order to re-order ID autoincrement.

// delete the record :

if(isset($_REQUEST['id']) && $_REQUEST['id']<>'')
  {
      $delete=mysql_query("delete from planning where id='".$_REQUEST['id']."'");

     echo "<script type=\"text/javascript\">".
        "alert('delete ok');".
        "</script>";
  }
  $msg='';
  if(isset($_REQUEST['msg']))
  {
      $msg=$_REQUEST['msg'];
  }

if(isset($_REQUEST['delete']) && $_REQUEST['delete']<>'' && $_REQUEST['delete'] == 'true')
  {
      $planning_id = $_REQUEST['id'];

      $query = "delete from planning where id = '".$planning_id."' " ; ;
      $output=mysql_query($query);
  }

And the mysql query that I can't execute but working with phpmyadmin :

ALTER TABLE `planning` DROP `id`;
ALTER TABLE `planning` AUTO_INCREMENT = 1;
ALTER TABLE `planning` ADD `id` int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;

Anyone to an idea please ?

Warmest thanks by advance !

Don't do that. It will add significant overhead to your database operations if you keep dropping the automatically incremented primary key and then reassign it especially once your dataset gets large enough.

Consider changing your primary key system .

Also, your code is vulnerable to SQL injection. Switch to prepared statements The mysql_ set of function calls is deprecated as well so even more reason to switch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM