phpnubb Posted May 6, 2014 Share Posted May 6, 2014 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. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted May 6, 2014 Share Posted May 6, 2014 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. Quote Link to comment Share on other sites More sharing options...
phpnubb Posted May 6, 2014 Author Share Posted May 6, 2014 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. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted May 6, 2014 Share Posted May 6, 2014 Maybe I'm looking at your code wrong. Can you post line 91 here? Quote Link to comment Share on other sites More sharing options...
phpnubb Posted May 6, 2014 Author Share Posted May 6, 2014 http://imgur.com/a/lhijs go there to see image captures of whats happening Quote Link to comment Share on other sites More sharing options...
ginerjm Posted May 6, 2014 Share Posted May 6, 2014 I'd rather see line 91 Quote Link to comment Share on other sites More sharing options...
phpnubb Posted May 6, 2014 Author Share Posted May 6, 2014 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>'; } ?> Quote Link to comment Share on other sites More sharing options...
ginerjm Posted May 6, 2014 Share Posted May 6, 2014 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. Quote Link to comment Share on other sites More sharing options...
phpnubb Posted May 6, 2014 Author Share Posted May 6, 2014 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. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted May 6, 2014 Share Posted May 6, 2014 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. Quote Link to comment Share on other sites More sharing options...
phpnubb Posted May 6, 2014 Author Share Posted May 6, 2014 if i post previous pages form where it is submitting the services can you please help to convert it to a session variable and resolve my issues? i cant figure this out Quote Link to comment Share on other sites More sharing options...
ginerjm Posted May 6, 2014 Share Posted May 6, 2014 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.