Jump to content

[SOLVED] Update database with all post data from previous page?


SicKn3sS

Recommended Posts

Hey, how can I make a loop to input all this POST data into my database?

 

Content-Length: 677
ID=2&Units+in+Canada=10&Instrument=H-7000&Category=TEM&Filament=777-0179&Filament+Cartridge=&LAB-6+or+Consumable+Emitter=747-0466%2F747-0299&Fixed+Condenser+Aperture=533-1101+%281000u%29&EDX+Objective+Movable+Aperture=&Condenser+Movable+Aperture=747-1565+%28300-200-50-20u%29&Objective+Movable+Aperture=747-1732+%28160-80-40-20u%29&Beam+Monitor+Aperture=&DPA+or+OBJ+Fixed+Aperture=&Selected+Area+Movable+Aperture=747-1567+%28400-200-100-50u%29&Viewing+Screen=747-0326&Spot+Viewing+Screen=&PMT=J386012+%28R268%29&STEM+Scintillator=533-0286&BSE+Detector=&Track+Ball=&Outer+Viewing+Screen=747-0246&Wehnelt+Assembly=&Whenelt+Contact+Spring=542-1106&Wehnelt+for+Cartridge=

Link to comment
Share on other sites

You could, hence the above post.  If you're only submitting certain fields each time then there needs to be an allowance for this in the database, and you'll also either need to make sure the columns in the database are the same as the fields in the form, or alternatively (and more secure) do some mapping between fields.

 

Regards

Huggie

Link to comment
Share on other sites

 

Very helpful!

 

firstly, who are you addressing, secondly, how about offering something constructive?

 

Regards

Huggie

 

Since I didn't quote you, you know I meant to address topic creator.

 

I would suggest something constructive if the man had a constructive purpose.  Why would you want to dump a bunch of un-validate, un-checked, un-used, un-processed, and probably un-wanted data into database?

 

Link to comment
Share on other sites

Why would you want to dump a bunch of un-validate, un-checked, un-used, un-processed, and probably un-wanted data into database?

 

You probably wouldn't but as the OP has only made 6 posts in total, they're probably new to PHP hence the hand holding initially.  It's a gradual process.

 

Write the code to put the data into the database.

Realise that you get errors and someone's submitted a string in a number field.

Write the code to correct the above (validate).

Realise the code inserts but that someone's spamming you.

Write the code to prevent automated submission.

 

When you're new to PHP you don't automatically think about these things.  All I'm saying is that even if you're not going to offer any help yourself, a link to a post that might help would certianly be more appreciated.

 

Regards

Huggie

Link to comment
Share on other sites

You probably wouldn't but as the OP has only made 6 posts in total, they're probably new to PHP hence the hand holding initially.  It's a gradual process.

 

Write the code to put the data into the database.

Realise that you get errors and someone's submitted a string in a number field.

Write the code to correct the above (validate).

Realise the code inserts but that someone's spamming you.

Write the code to prevent automated submission.

 

When you're new to PHP you don't automatically think about these things.  All I'm saying is that even if you're not going to offer any help yourself, a link to a post that might help would certianly be more appreciated.

 

Regards

Huggie

 

word! :)

Link to comment
Share on other sites

 

Very helpful!

 

firstly, who are you addressing, secondly, how about offering something constructive?

 

Regards

Huggie

 

Since I didn't quote you, you know I meant to address topic creator.

 

I would suggest something constructive if the man had a constructive purpose.  Why would you want to dump a bunch of un-validate, un-checked, un-used, un-processed, and probably un-wanted data into database?

 

 

Only the admin account is able to access the page and he knows what he is doing.

 

I suppose you could use a foreach loop on the $_POST array to build the query string.

 

That's what I want to do but I can't figure out how. Can someone tell me?

Link to comment
Share on other sites

Okay I figured it out myself:

 

while($row = mysql_fetch_assoc($result))
{
    foreach($row as $field => $value)
    {
	$updateValue=$_POST[$field];
	// replace value in db with update value
    }
}

 

Not exactly how I wanted it, but it works. I'm just posting the solution encase people find this post on google or search :)

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.