Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4243284
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:33:29+00:00 2026-05-21T03:33:29+00:00

When I try input new value OR change value OR delete value(nothing) to products

  • 0

When I try input new value OR change value OR delete value(nothing) to products 1 or products 2

I don’t wanna insert NULL value into DB.

products TABLE

+-------------+--------------+---------------+
| products_id | categories_id| products_name |
+-------------+--------------+---------------+
| 1           | 1            | product 1     |
| 2           | 1            | product 2     |
+-------------+--------------+---------------+

products_extra_fields TABLE

+--------------------------+---------------------------+
| products_extra_fields_id | products_extra_fields_name| 
+--------------------------+---------------------------+
| 1                        | sugar                     |
| 2                        | cocoa                     |
| 3                        | butter                    |
| 4                        | milk                      |
+--------------------------+---------------------------+

products_to_products_extra_fields TABLE

+-------------+---------------------------+-----------------------------+
| products_id | products_extra_fields_id  | products_extra_fields_value |
+-------------+---------------------------+-----------------------------+
| 1           | 1                         | 20%                         |
| 1           | 2                         | 45%                         |
| 1           | 3                         | 27%                         |
| 2           | 1                         | 12%                         |
+-------------+---------------------------+-----------------------------+

phpscript

<?php

require ('mysql/mysql_connect2.php'); // Connect to the database.
if (isset ($_POST['submit'])) {

    $products_id = $_POST['products_id'];

    echo "products_id = ".$products_id;
    echo "<br/><br/>";

    for($i = 0; $i<count($_POST['products_extra_fields_value']); $i++){

        $products_extra_fields_id = $_POST['products_extra_fields_id'][$i];
        $products_extra_fields_value = $_POST['products_extra_fields_value'][$i];

        if($products_extra_fields_value != ''){
        echo "products_extra_fields_id = ".$products_extra_fields_id;
        echo "<br/>";
        echo "products_extra_fields_value = ".$products_extra_fields_value;
        echo "<br/><br/>";
    }else{

    }

$query = "INSERT into products_to_products_extra_fields 
    set 
    products_id = '$products_id', 
    products_extra_fields_id = '$products_extra_fields_id', 
    products_extra_fields_value = '$products_extra_fields_value'

    ON DUPLICATE KEY UPDATE 

    products_extra_fields_value = '$products_extra_fields_value'

    "; 
    $result = mysql_query ($query); // Execute the query.
}
if ($result) {

header("refresh: 2; url='products.php?action=gopro_cat&categories_id={$_POST['products_id']}'");
        }else{
        print "<p>Could update the entry because: <b>" . mysql_error() . "</b><BR/><BR/>The query was: $query</p>";
    }   
mysql_close();

}else{
$products_id = $_GET['products_id'];
$categories_id = $_GET['categories_id'];

    // Check for a valid entry ID in the URL.
    if (is_numeric ($products_id) ) {

// Define the query.
$query = "SELECT   products_extra_fields.products_extra_fields_id, 
products_name,  
products_extra_fields_name,  
products_extra_fields_value FROM 

products, 
products_extra_fields LEFT JOIN products_to_products_extra_fields ON 
products_to_products_extra_fields.products_extra_fields_id = 
products_extra_fields.products_extra_fields_id AND 

products_to_products_extra_fields.products_id='$products_id' 

GROUP BY products_extra_fields.products_extra_fields_id";

if ($result = mysql_query ($query)) {

$query2 = "SELECT products_name FROM products, categories WHERE 
products.products_id='$products_id' AND 
categories.categories_id = '$categories_id'";

if ($result2 = mysql_query ($query2)) {
$row2 = mysql_fetch_array ($result2);
$products_name = $row2['products_name'];
?>

<form action='products_edit2.php' enctype='multipart/form-data' method='POST'>
<table width="50%" border="0" cellpadding="2" cellspacing="2">
<tr>
<td width="20%" align="right">PRODUCTS NAME:</td>
<td><input type="text" name="products_name" size="80" value="<?php echo $products_name; ?>" /></td>
</tr>
<?php 
}
/***** ***** *****/

while ($row = mysql_fetch_array ($result)) {
$products_extra_fields_name = $row['products_extra_fields_name'];
$products_extra_fields_value = $row['products_extra_fields_value'];
$products_extra_fields_id = $row['products_extra_fields_id'];
?>
<tr>
<td width="20%" align="right">
<input type="text" name="products_extra_fields_id[]" size="5" value="<?php echo $products_extra_fields_id; ?>" />

<?php echo $products_extra_fields_id .'-'. $products_extra_fields_name; ?></td>
<td><input type="text" name="products_extra_fields_value[]" size="80" value="<?php echo $products_extra_fields_value; ?>" /></td>
</tr>

<?php }

/***** ***** END *****/
?>
<input type="ÔÅ×Ô" name="products_id" size="10" value="<?php echo $products_id; ?>" />

<tr>
<td width="100%" colspan="2" align="right"><input type="submit" name="submit" value="SAVE"/></td>
</tr>
</table>
</form>

<?php
} else { // Couldn't get the information.
print "<p>Could retrieve the entry because: <b>" . mysql_error() . "</b><br/><br/>. The query was $query.</p>";
}
}else{ // No ID set.
print '<p><b>You must have made a mistake in using this page.</b></p>';
}
}
?>

===========================================================================================

for($i = 0; $i<count($_POST['products_extra_fields_value']); $i++){

        $_POST['products_extra_fields_id'][$i];
        $_POST['products_extra_fields_value'][$i];

        if($_POST['products_extra_fields_value'][$i] != ''){
        echo "products_extra_fields_id = ".$products_extra_fields_id = $_POST['products_extra_fields_id'][$i];
        echo "<br/>";
        echo "products_extra_fields_value = ".$products_extra_fields_value = $_POST['products_extra_fields_value'][$i];
        echo "<br/><br/>";

        echo "if".$products_extra_fields_value;
        echo "<br/><br/>";
    }else{
        echo "else".$products_extra_fields_value;
        echo "<br/><br/>";
    }
}

With the above CODE you can only insert new value (or change).

The problem is you can’t delete any values if you want to.

Is there any solution for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T03:33:30+00:00Added an answer on May 21, 2026 at 3:33 am

    If you don’t want to insert NULL values into the database, modify your table schemas to not allow NULL. You can do this within MySQL Query Browser, or Workbench.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my botton: <form> <input type=hidden id=id value='.$row['order_id'].'> <input type=button value=Delete onclick=ajaxFunction()> </form>
I always try to do the following: <label><input type=checkbox /> Some text</label> or <label
How do I get an NSString from console input, and then try to cast
I try to write KSH script for processing a file consisting of name-value pairs,
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
try { ... } catch (SQLException sqle) { String theError = (sqle).getSQLState(); ... }
I try to fetch a Wikipedia article with Python's urllib: f = urllib.urlopen(http://en.wikipedia.org/w/index.php?title=Albert_Einstein&printable=yes) s
I try to define a schema for XML documents I receive. The documents look
I try to add an addons system to my Windows.Net application using Reflection; but
We try to convert from string to Byte[] using the following Java code: String

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.