Jump to content

Recommended Posts

I need help please! I am learning php and mysql and am successful at pulling data from my database and placing it in a (editable) 5 column, 4-row table, but cannot figure out how to correctly do the reverse and update the database upon "submit". I do a "loop" to populate the table and am guessing I need a "reverse" loop to pull the data out and submit it, but do not know how to do this and I cannot figure it out. I would greatly appreciate some help! code below....

 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/245612-mysql-database-loop-problem/
Share on other sites

Yeah, you're not too clear on this one.  Is it right to say that: You are rinning a SELECT on a table, displaying the results in a tabled form. Now you want to have the form data update the table that you have SELECTed from when the form submit button is clicked?  Is that about right?

This is the classic CRUD (Create, Read, Update, Delete) assignment that is given to programming students to see if THEY can research and figure out how to define and write the code to perform each of those steps.

 

The OP has some code to Read the data and display it in a form (which is incomplete and won't submit any data, let alone sets of data that are related back to the correct id/type of each row in the database table.)

 

I recommend that you get the form working correctly before you attempt to try to process the data it submits. Your form input fields are missing name="..." attributes (no data will be submitted to your .php script without them), you will need to use arrays for those names so that you can have multiple/separate sets of data in the form (see this link - http://us.php.net/manual/en/faq.html.php#faq.html.arrays ), and you need to specifically set the array indexes (instead of using empty [], use ['some_identifying_value']) to identify and associate each row of data in the form back to the id/type it is in the database table.

 

Based on the information in your existing code, you could use form field names like -

 

name="slice['.$row['type'].']"

name="small['.$row['type'].']"

name="large['.$row['type'].']"

name="sheet['.$row['type'].']"

 

To see what data your form is submitting, add the following line of code -

 

echo '<pre>',print_r($_POST,true),'</pre>';

 

Once you get the form to submit the expected data, you can move onto the next step of processing it.

I apologise for "lack of following the forum rules". As you can see it was my "post#1" so please do not crucify me. I will try my best to follow all rules in the future. Muddy and PFMaBiSmAd, you two guys understand exactly what I am trying to do. In a nutshell, as you can see, I am just trying to display a simple "Pizza" menu on a webpage" and allow the client to edit prices, and then upload his changes.  That's all. I appreciate you taking the time to understand. I understand how you emphasize that step 1 should be to focus on getting my form to submit correctly(with field names. I will follow your suggestions and will work on it tonight and tommow and keep you posted. Thank you very much again. Buffmin

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.