Double Entry in Database when inserting from form using PHP & MySQL -


i trying create web application. new php & mysql. when insert data table using php, double records of entry made table. using xampp. please me fix this. attached screenshot of double entry.

my database dump: -- phpmyadmin sql dump -- version 3.5.2.2 -- http://www.phpmyadmin.net -- -- host: 127.0.0.1 -- generation time: may 18,   2013 @ 11:58 pm  -- server version: 5.5.27  -- php version: 5.4.7  set sql_mode="no_auto_value_on_zero"; set time_zone =    "+00:00";   /*!40101 set @old_character_set_client=@@character_set_client */; /*!40101 set   @old_character_set_results=@@character_set_results */; /*!40101 set @old_collation_connection=@@collation_connection */; /*!40101 set names utf8 */;  -- -- database: `gccdb` --  -- --------------------------------------------------------  -- --   table structure table `tbl_rol` --  create table if not exists `tbl_rol` (  `id` int(11) not null auto_increment,    `rol_cd` varchar(10) not null,  `rol_desc` varchar(25) not null,  `rol_shrt` varchar(15) not null,   primary key (`id`)  )    engine=innodb default charset=utf8 auto_increment=1 ;  /*!40101 set character_set_client=@old_character_set_client */; /*!40101 set character_set_results=@old_character_set_results */; /*!40101 set   collation_connection=@old_collation_connection */;  ![enter image description here][1]  given below php code. <?php  if ($_server['request_method'] == "post") { if ($_post["rol_new_save"]) {     $sql = "insert tbl_rol(id, rol_cd, rol_desc, rol_shrt) values (null, '$_post[rol_new_rlcode]',          '$_post[rol_new_rldesc]', '$_post[rol_new_rlshrt]')";     $con = mysqli_connect("localhost","root","");         if(!$con) {             exit('connect error (' . mysqli_connect_errno() . ') ' .  mysql_connect_error());             }         mysqli_select_db($con,"master01");     mysqli_query($con,$sql);     if (!mysqli_query($con, $sql)){         die('error:'.  mysqli_errno($con). mysqli_error($con));     }     mysqli_close($con);     header('location:rol_new.php');     exit;  }  if ($_post["rol_new_exit"]) {     header('location:sa_main.php');     exit;  }  }  ?>  <!doctype html public "-//w3c//dtd xhtml 1.0 strict//en"  "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd">  <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">  <head>     <meta http-equiv="content-type" content="text/html; charset=utf-8"/>     <title></title>  </head>  <body>     <form name="form1" action="" method="post" enctype="multipart/form-data">         <div>             <p>                 <label for="rol_new_rlcode">role code:</label>                 <input id="rol_new_rlcode" name="rol_new_rlcode" class="" type="text"   value=""/>             </p>         </div>         <div>             <p>                 <label for="rol_new_rldesc">role description:</label>                 <input id="rol_new_rldesc" name="rol_new_rldesc" class="" type="text" value=""/>             </p>         </div>         <div>             <p>                 <label for="rol_new_rlshrt">role name:</label>                 <input id="rol_new_rlshrt" name="rol_new_rlshrt" class="" type="text" value=""/>             </p>         </div>         <div id="hline"></div>         <div>             <p>                 <input id="rol_new_save" name="rol_new_save" class="" type="submit" value="save"/>             </p>         </div>         <div>             <p>                 <input id="rol_new_exit" name="rol_new_exit" class="" type="submit" value="exit"/>             </p>         </div>     </form>     </body> </html> 

you're executing twice. take line out;

mysqli_query($con,$sql); 

your if statment executes when evaluating it, don't need call seperately.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -