Note that there are some explanatory texts on larger screens.

plurals
  1. PODouble Entry in Database when inserting from form using PHP & MySQL
    text
    copied!<p>I am trying to create a web application. I am new to PHP &amp; MySQL. When I insert data into my table using PHP, double records of the entry are made into the table. I am using XAMPP. Please help me fix this. Also attached is the Screenshot of the Double Entry.</p> <pre><code>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 at 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 for 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 is the PHP code. &lt;?php if ($_SERVER['REQUEST_METHOD'] == "POST") { if ($_POST["rol_new_save"]) { $sql = "INSERT INTO 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; } } ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form name="form1" action="" method="POST" enctype="multipart/form-data"&gt; &lt;div&gt; &lt;p&gt; &lt;label for="rol_new_rlcode"&gt;Role Code:&lt;/label&gt; &lt;input id="rol_new_rlcode" name="rol_new_rlcode" class="" type="text" value=""/&gt; &lt;/p&gt; &lt;/div&gt; &lt;div&gt; &lt;p&gt; &lt;label for="rol_new_rldesc"&gt;Role Description:&lt;/label&gt; &lt;input id="rol_new_rldesc" name="rol_new_rldesc" class="" type="text" value=""/&gt; &lt;/p&gt; &lt;/div&gt; &lt;div&gt; &lt;p&gt; &lt;label for="rol_new_rlshrt"&gt;Role Name:&lt;/label&gt; &lt;input id="rol_new_rlshrt" name="rol_new_rlshrt" class="" type="text" value=""/&gt; &lt;/p&gt; &lt;/div&gt; &lt;div id="hline"&gt;&lt;/div&gt; &lt;div&gt; &lt;p&gt; &lt;input id="rol_new_save" name="rol_new_save" class="" type="submit" value="Save"/&gt; &lt;/p&gt; &lt;/div&gt; &lt;div&gt; &lt;p&gt; &lt;input id="rol_new_exit" name="rol_new_exit" class="" type="submit" value="Exit"/&gt; &lt;/p&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload