Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

confused about the update

General discussions related to php

Moderators: macek, egami, gesf

confused about the update

Postby Alidad » Sat Dec 28, 2013 7:42 am

hi, i'm trying to set database field to empty which is set to NULL when press button, but i'm getting error message said

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE product_id=''' at line 1 Error perform query!


my code here is ..

Code: Select all
<?php
         ////////////////////////////////////////////
         ///category drop list //////////////////////
         ////////////////////////////////////////////
         if (isset($_POST['submit_index_2'])){
         define('HOST', 'localhost');
         define('USER', 'root');
         define('PASS', '');
         define('DBNAME', 'shopone');
         $product_id = $row["product_id"];
         $db = new mysqli(HOST, USER, PASS, DBNAME);

         if ($db->connect_errno) {
         echo "Failed to connect to MySQL: (" . $db->connect_errno . ") "
         . $db->connect_error;
         } else {
         $sql = ("UPDATE product SET images_2= 'NULL', WHERE product_id='$product_id'");
         $result_db = $db->query($sql);
         if (!$result_db) {
         echo $db->error . ' Error perform query!';
         } else {
         echo "$images_2;";
         }
         }
         $db->close();
         }
         //////////////////////////////
         ////End of list category /////
         //////////////////////////////
         ?>



there is column called "image_2" which is put image file name, but i want to remove that by input "null" and here is html code...

Code: Select all
  <?php echo '<img id="imgAvatar" class="none-image" src="' . GW_UPLOADPATH . '/' .  $images_2 .'" width="170" height="auto"  />'?> </div>
  <input
  type="file"
  name="file"
  style="opacity:0;
  cursor:pointer;
  top: 62px;
  width:200px;
  height:180px;
  background-color:#963;
  z-index:1;"
 onchange="readURL_2(this);"
  />

  <div
 
  <?php echo $images_2; ?>
<input name="submit_index_2" type="submit" />
</div>
</div>


what this mean and how to solve that!

AM
Alidad
New php-forum User
New php-forum User
 
Posts: 4
Joined: Fri Feb 18, 2011 12:44 pm

Re: confused about the update

Postby MarioParty » Sat Dec 28, 2013 2:16 pm

Code: Select all
$sql = ("UPDATE product SET images_2= 'NULL', WHERE product_id='$product_id'");

should be
Code: Select all
$sql = ("UPDATE product SET images_2= 'NULL' WHERE product_id='$product_id'");
MarioParty
New php-forum User
New php-forum User
 
Posts: 42
Joined: Tue Aug 02, 2011 2:52 am


Return to PHP General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.