Note that there are some explanatory texts on larger screens.

plurals
  1. POExtra blank records being added to Mysql database on insert
    primarykey
    data
    text
    <p>On submit, records are being inserted into MySQL database but 4 extra blank rows are being inserted too. The blank rows in phpmyadmin have only the "id" but the other columns in the table are empty/blank. I am attaching my code below. Your help is appreciated. </p> <pre><code>&lt;!DOCTYPE html&gt; &lt;head&gt; &lt;title&gt;Title&lt;/title&gt; &lt;link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/&gt; &lt;style type="text/css"&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt; &lt;title&gt;Page Title&lt;/title&gt; &lt;style type="text/css" charset="utf-8"/&gt; *{background:#eee;padding:2px;box-sizing:border-box; -moz-box-sizing:border-box; /* Firefox */} &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;?php $dbhost = 'host'; $dbuser = 'user'; $dbpass = 'passw'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); //test if the connection is established successfully then it will proceed in next process else it will throw an error message if (!$conn) { die('Could not connect: ' . mysql_error()); } mysql_select_db('cato'); //we specify here the Database name we are using if (isset($_POST['submit'])) { $i = 0; foreach ($_POST as $val) { $business_name = trim(mysql_real_escape_string($_POST["business_name"][$i])); $business_type = trim(mysql_real_escape_string($_POST["business_type"][$i])); $country = trim(mysql_real_escape_string($_POST["country"][$i])); $province = trim(mysql_real_escape_string($_POST["province"][$i])); $address = trim(mysql_real_escape_string($_POST["address"][$i])); $postcode = trim(mysql_real_escape_string($_POST["postcode"][$i])); $telephone1 = trim(mysql_real_escape_string($_POST["telephone1"][$i])); $telephone2 = trim(mysql_real_escape_string($_POST["telephone2"][$i])); $category = trim(mysql_real_escape_string($_POST["category"][$i])); $email = trim(mysql_real_escape_string($_POST["email"][$i])); $i++; mysql_query("SET NAMES 'utf8'"); mysql_query("INSERT INTO company_details (company_id, business_name, business_type, country, province, address, postcode, telephone1, telephone2, category, email) VALUES ('','$business_name', '$business_type', '$country', '$province', '$address', '$postcode', '$telephone1', '$telephone2', '$category', '$email')"); } } ?&gt; &lt;script type="text/javascript"&gt; alert("Successs!! records have been added to database"); window.location = "index.php?db=cato"; &lt;/script&gt; &lt;?php //close of connection mysql_close($conn); ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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