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 9081903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:25:41+00:00 2026-06-16T20:25:41+00:00

I had this working then when I added the new category Quantity it now

  • 0

I had this working then when I added the new category Quantity it now produces this error.

Undefined offset: 0 in (the form values)

I cannot see where the undefined offset is. Any help would be appreciated.

I also know mysql is depreciated but want it working before changing.

As a note, all the data is recalled to the edit form it is when you process it, it produces that error

Also the query has been validated and runs.

Edit Function

function edit_product($id, $name, $description, $price, $quantity, $picture, $category) {

      $id           = (int) $id;  
      $category     = (int) $category;
      $name         = mysql_real_escape_string($name);
      $description  = mysql_real_escape_string($description);
      $price        = mysql_real_escape_string($price);
      $quantity     = (int) $quantity;
      $picture      = mysql_real_escape_string($picture);



      mysql_query("UPDATE `shop` SET 

      `prod_id`         = {$category},
      `name`            = '{$name}',
      `description`     = '{$description}',
      `price`           = '{$price}',
      `quantity`        = '{$quantity}',
      `picture`         = '{$picture}'
      WHERE `id`        = {$id}");

    echo mysql_error();
    }

Edit page

    $post = get_posts($_GET['id']);

    if ( isset($_POST['name'], $_POST['description'], $_POST['price'], $_POST['quantity'], $_POST['picture'], $_POST['category']) ) {
    $errors = array();

        $name           = trim($_POST['name']);
        $description    = trim($_POST['description']);
        $price          = trim($_POST['price']);
        $quantity       = trim($_POST['quantity']);
        $picture        = trim($_POST['picture']);


        if ( empty($name) ) {
            $errors[] = 'You need to supply a title';
        }   else if ( strlen($name) > 255 ) {
        $errors[] = 'Title cannot be longer than 255 characters';
        }

        if ( empty($description) ) {
        $errors[] = 'You need to supply text';
        }

        if ( empty($price) ) {
        $errors[] = 'You need to supply text';
        }

        if ( empty($quantity) ) {
        $errors[] = 'You need to supply text';
        }

        if ( empty($picture) ) {
        $errors[] = 'You need to supply text';
        }

        if (! category_exists('id', $_POST['category']) ) {
        $errors[] = 'Category does not exist';

        }

        if ( empty($errors) ) {
        edit_product($_GET['id'], $name, $description, $price, $quantity, $picture, $_POST['category']);
        header("Location: ../admin/edit_products.php?id={$post[0]['post_id']}");
        die();
        }
    }
    ?>

.....

<label for="name">Title</label>
<input type="text" name="name" value="<?php echo $post[0]['name']; ?>"><br/>
<label for="price">price</label>
<input type="text" name="price" value="<?php echo $post[0]['price']; ?>"><br/>

<label for="sale">Quantity</label>
<input type="text" name="quantity" value="<?php echo $post[0]['quantity']; ?>"><br/>
<label for="picture">Picture</label>
<input type="text" name="picture" value="<?php echo $post[0]['picture']; ?>"><br/>


<label for="description">Description</label>
<textarea  name="description" rows="15" cols="50"><?php echo $post[0]['description']; ?></textarea><br/>


<label for="prod_id">Category</label>
<select name="category">
<?php
foreach ( get_categories() as $category ) {
$selected = ( $category['name'] == $post[0]['name'] ) ? " selected" : '';
?>

<option value="<?php echo $category['id']; ?>" <?php echo $selected; ?>> <?php echo $category['name']; ?></option>


--------------

Get Post function – As requested.

function get_posts($id = null, $cat_id = null) {
    $posts = array();

    $query ="SELECT  `shop`.`id` AS  `post_id` ,  `products_cat`.`id` AS  `category_id` , `shop`.`name` ,  `description` ,  `price` ,  `quantity` ,  `picture` 
FROM  `shop` 
INNER JOIN  `products_cat` ON  `shop`.`prod_id` =  `products_cat`.`id` ";

    if ( isset($id) ) {
    $id = (int) $id;
    $query .= " WHERE `shop`.`id` = {$id}";
    }

    if ( isset($cat_id) ) {
        $cat_id = (int) $cat_id;
        $query .= " WHERE `products_cat`.`id` = {$cat_id}";
}

    $query .= " ORDER BY `shop`.`price` DESC";

    $query = mysql_query($query);
    echo mysql_error();
    while ( $row = mysql_fetch_assoc($query) ) {
        $posts[] = $row;
        }

    return $posts;
}
  • 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-06-16T20:25:42+00:00Added an answer on June 16, 2026 at 8:25 pm

    First thing please dont use mysql_ and go for mysqli_

    For a while , In above code

    Undefined offset: 0 error is cooming from lines as you said 
    
    <input type="text" name="price" value="<?php echo $post[0]['price']; ?>">
    

    This is because the value at that index $post[0][‘price’] has not been set yet.

    Just replace it with

     <?php echo isset($post[0]['price'])?$post[0]['price']:''; ?> 
    

    in the value attribute.

    Hope it will help you!

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

Sidebar

Related Questions

Had this working; at one stage. The problem is the following text is now
So, thought I had this working last night, couldve sworn it. Now it no
I had this, which was working fine: public static Integer[] photos = new Integer[]
I had this working at some point, as I had a question about this
I had this working in an old code that I didn’t end up using...
Strangely I had this working before but I reinstalled my system, upgraded to w7
I had this sqlcmd snippet working in batch but when I converted to powershell,
Has anyone else had this issue and found a working solution? I've enabled the
So I'm working on a CakePHP app, and had this line in one of
I've been working at this for two days and have not had much luck.

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.