confused about the update

General discussions related to php

Moderators: macek, egami, gesf

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

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

         ///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;";
         ////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>
  top: 62px;

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

what this mean and how to solve that!


New php-forum User
New php-forum User
Posts: 42
Joined: Tue Aug 02, 2011 2:52 am

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'");

Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 4 guests