Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have grep all of your <code>INSERT</code> statement as follows</p> <pre><code>1: $query = "INSERT INTO admincamera (product, price, prevprice, details, image1)"."VALUES('$addproduct', '$addprice', '$addprevprice', '$adddetails', '$addimage1')"; 2: $query = "INSERT INTO admincamera (product, price, prevprice, details )"."VALUES('$addproduct', '$addprice', '$addprevprice', '$adddetails')"; 3: $query = "INSERT INTO admincamera (product, price, prevprice, details, image2)"."VALUES('$addproduct', '$addprice', '$addprevprice', '$adddetails', '$addimage2')"; 4: $query = "INSERT INTO admincamera (product, price, prevprice, details )"."VALUES('$addproduct', '$addprice', '$addprevprice', '$adddetails')"; 5: $query = "INSERT INTO admincamera (product, price, prevprice, details, image3)"."VALUES('$addproduct', '$addprice', '$addprevprice', '$adddetails' '$addimage3')"; } 6: $query = "INSERT INTO admincamera (product, price, prevprice, details )"."VALUES('$addproduct', '$addprice', '$addprevprice', '$adddetails')"; </code></pre> <p><strong>You have missed comma</strong> on 5th INSERT....</p> <pre><code>"VALUES('$addproduct', '$addprice', '$addprevprice', '$adddetails' '$addimage3')"; ^------- Here </code></pre> <h2>TEST</h2> <p>It is interesting. <code>'string1' 'string2'</code> is converted into <code>'string1string2'</code></p> <pre><code>mysql&gt; insert into test2 (a, b) values('1', '2'); Query OK, 1 row affected (0.00 sec) mysql&gt; insert into test2 (a, b) values('1' '2'); ERROR 1136 (21S01): Column count doesn't match value count at row 1 mysql&gt; insert into test2 (a, b) values('1' '2', '3'); Query OK, 1 row affected (0.00 sec) mysql&gt; SELECT * FROM test2; +------+------+ | a | b | +------+------+ | 1 | 2 | | 12 | 3 | +------+------+ 2 rows in set (0.00 sec) </code></pre> <h2>Improve code</h2> <ul> <li>make function repeated code</li> <li>do not use <code>mysql_xxx()</code>, use <code>mysqli</code> or <code>PDO</code></li> <li>use prepared statement for SQL Injecttion</li> </ul> <p><strong>function style</strong></p> <p>Not tested but following code looks better than yours.</p> <pre><code>&lt;? include('../connect.php'); $inserted = insert($_FILES['addimage1'], 'image1'); $inserted = insert($_FILES['addimage2'], 'image2'); $inserted = insert($_FILES['addimage3'], 'image3'); function insert($file, $image_col_name) { $addid= $_POST['addrow']; $addproduct= mysql_real_escape_string(htmlentities($_POST['addproduct'])); $addprice= mysql_real_escape_string(htmlentities($_POST['addprice'])); $addprevprice= mysql_real_escape_string(htmlentities($_POST['addprevprice'])); $adddetails= mysql_real_escape_string(htmlentities($_POST['adddetails'])); $addimage = mysql_real_escape_string($file['name']); $addimagetemp = mysql_real_escape_string($file['tmp_name']); $addimagetype = mysql_real_escape_string($file['type']); $addimagesize = mysql_real_escape_string($file['size']); if (!empty($addimage)) { if (($addimagetype == 'image/gif' || $addimagetype == 'image/jpg' || $addimagetype == 'image/jpeg') &amp;&amp; ($addimagesize &gt; 0 &amp;&amp; $addimagesize &lt; 2000000)) { move_uploaded_file($addimagetemp,"../img/camera/$addimage"); $query = "INSERT INTO admincamera (product, price, prevprice, details, $image_col_name)"."VALUES('$addproduct', '$addprice', '$addprevprice', '$adddetails', '$addimage')"; } else { echo "&lt;p&gt;file needs to be a jpg/gif or file size too big.&lt;/p&gt;"; die(); } } else { $query = "INSERT INTO admincamera (product, price, prevprice, details)"."VALUES('$addproduct', '$addprice', '$addprevprice', '$adddetails')"; } mysql_query($query) or die(mysql_error()); return true; } ?&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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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