Jump to content

completely lost


phpnubb

Recommended Posts

Trying to create a page that displays a form thats already populated from previous page. Now im trying to add an additional element into the already populated form, a coupon code. When I do this i lose all services and half my website disappears. 

Notice: Undefined index: service in /home/ on Line 91

 

line 91 is how i generated my services from previous page. 

 

here is my code: http://pastebin.com/NEeqpgxT

 

 

what i want to figure out currently is why my page is disappearing and why its losing services.

Link to comment
Share on other sites

Half you site disappears?  Or half of your current page?

 

Line 91 is telling you that you have no input element named 'service' in the form that you submitted.

half the current page goes away....

line 91 reads the posted services array from previous page. its not posting when page is reloaded to apply coupon code.

Link to comment
Share on other sites

Maybe I'm looking at your code wrong.  Can you post line 91 here?

this is line 88-112

Line 91 is  $aService = $_POST['service'];

<?PHP
 
 
 $aService = $_POST['service'];
 
              $N = count($aService);
 
      
         for($i=0; $i < $N; $i++)
         {
     $services=MYSQLI_QUERY($con, "SELECT * FROM `Service` WHERE Service_ID = '$aService[$i]'")or die(mysqli_error($con));
     $getservices = mysqli_fetch_array($services);
      $serviceid = $getservices['Service_ID'];
      $servicedesc = $getservices['Service_Type'];
 
      $serviceprice = $getservices['Service_Cost'];
 
    
      echo'<tr>
<td><input type="text" name="service" value="'. $servicedesc. '"></td>
<td><input type="text" name="price" id="price'.$i.'" value="'. $serviceprice. '"></td>
<td><input type="text" class="qty" value="'. $serviceprice. '"></td>
 
  </tr>';
    } ?>
Link to comment
Share on other sites

As I surmised from my look at the code - your form doesn't have an element named service in it.  Look at your entire form's html and be sure that you have that element to solve this error.  I see an element in your last post named service, but it is not an array as you seem to expect since you use the count() function on it.

Link to comment
Share on other sites

As I surmised from my look at the code - your form doesn't have an element named service in it.  Look at your entire form's html and be sure that you have that element to solve this error.  I see an element in your last post named service, but it is not an array as you seem to expect since you use the count() function on it.

 

as i stated, service was generated from previous pages form. its a posted variable from previous page.

Link to comment
Share on other sites

Unless an element exists on the form that triggered THIS script on submit, you will not have an element named 'service' in your post array.  Perhaps you want to save the data from that previous page in a session array rather than a post array.

Link to comment
Share on other sites

The $_POST array is created when you submit a form whose method is set to POST.  The script mentioned by the same form's action attribute gets control and receives the elements of that form in the POST array.  Your script is doing something with that data and then you want to save some subset of that data I presume so that you can use it later after another form is sent out and returns with new POST data.

 

In order to save data you can :

1 - save fields as type='hidden' on the second form so that you will receive them again

2 - save the data from the POST fields in a session var.  You can save them individually or as items within an array

 

To save vars as session vars you simply say "$_SESSION['varname'] = (whatever var/value you have to save)".  If the var you want to save is an array then the SESSION var will be an array.  Session vars will last as long as the current session lasts.  If you are not yet using sessions, you should read up on them in the manual, but simply put - if you start each script with "session_start()" you will open the session and have access to whatever you have previously saved in that session.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.