123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|548|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Web Development -> POSTing shit...

Tue, 12 Apr 2011, 01:36
Afr0
I'm trying to POST a newsitem to a PHP script, but it keeps submitting the same thing all the time. Help?



-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Tue, 12 Apr 2011, 05:24
JL235
I don't understand what the issue is, and I fail to understand what you are trying to achieve. If you have the date and news item already server side then why are you outputting them into a form to be re-submitted?

Finally you have broken a web development cardinal sin by mixing your HTML with your DB logic.
Tue, 12 Apr 2011, 06:04
Afr0
Why do think I would want to resubmit it?
Because I want to have the capability to edit newsitems.

...

I fixed it.

From index.php:



editnews.php:



From news.php:





Edit: In case anyone's wondering... if you're trying to POST different values to a script from multiple submit buttons with the same names, look up your values in the $_REQUEST array instead of $_POST. In fact, use $_REQUEST by default altogether! Much easier!

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Tue, 12 Apr 2011, 06:09
Afr0
By the way, I was wondering... assuming one has a million newsitems in a table, how would one select only the last 10,000 newsitems and display them on the frontpage?

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Tue, 12 Apr 2011, 06:15
JL235
Afr0 Why do think I would want to resubmit it?
Because I want to have the capability to edit newsitems.

Then why are you using hidden fields?

Afr0 By the way, I was wondering... assuming one has a million newsitems in a table, how would one select only the last 10,000 newsitems and display them on the frontpage?

Stick 'LIMIT 10000' onto the end of your query, but also remember to order it.
Tue, 12 Apr 2011, 06:18
Afr0
DiablosDevil
Then why are you using hidden fields?


Because I tried using labels to show the news on the frontpage, and they required me to attach the label to a control!! I also couldn't figure out how to get a specific newsitem when POSTing from multiple buttons with the same name (which was the reason I started this thread), so I decided to slap a single button at the end of the newsitems display.
But then in editnews.php I discovered that even when fetching all the newsitems from the DB, I still needed to post an individual newsitem to the news.php script!!
Fortunately I found the $_REQUEST array...

DiablosDevil Stick 'LIMIT 10000' onto the end of your query, but also remember to order it.


Thanks!

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Tue, 12 Apr 2011, 06:21
JL235
But you can't edit hidden fields or labels (at least not without a DOM inspector)!

You should use text inputs or text areas; or I still don't understand what you are building.
Tue, 12 Apr 2011, 06:25
Afr0
See my above edit ^
Tue, 12 Apr 2011, 06:36
Afr0




This works. It isn't very practical for large tables, but it works. Now I just have to limit my query to the last 10,000 newsitems.



-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Tue, 12 Apr 2011, 07:38
JL235
The site looks much nicer now, but you should still center it and remove the single colour background.
Wed, 13 Apr 2011, 05:45
Afr0
Wtf?!

I found out I needed a form with another hidden field to indicate if I wanted to delete news (maintaining state with HTML can be kinda complex and unintuitive), but for some reason the browser (I tested it in Internet Explorer in addition to Chrome, just to make sure) displays my first hidden field!!

Why??



The field being displayed is this one:



-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Wed, 13 Apr 2011, 11:37
Stealth
You're missing an = after type.

FYI: Using $_REQUEST instead of $_POST makes you more venerable to attack. If I give you a link to a seemingly innocent page, it could be embedded with an iframe that loads a URL on your server. It could be crafted with a bunch of URL parameters to do something bad. This would load in your browser where you are already authenticated.

-=-=-
Quit posting and try Google.
Wed, 13 Apr 2011, 12:55
Afr0
Thanks Stealth!

If you have a solution for my problem that does not involve using $_REQUEST, please say so...

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Wed, 13 Apr 2011, 13:26
HoboBen
If you have a solution for my problem that does not involve using $_REQUEST, please say so...


Well, if you're posting data, like Stealth said, use $_POST:

$TxtNews = $_POST["TxtNews"];
$ID = $_POST['ID'];

(Stealth is dead right; I could post a link as an image here with the delete parameter filled in and your browser would request it!)

-=-=-
blog | work | code | more code
Wed, 13 Apr 2011, 13:56
Afr0
$_POST is out of the question, because it doesn't work when you're POSTing a value from several controls with the same name and you don't know which control was POSTed from.
$_REQUEST just works, instantly...

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Wed, 13 Apr 2011, 14:03
Stealth
$_REQUEST is a merge of $_POST and $_GET.

$_POST comes from posted form data.

$_GET comes from URL parameters.

Does that make sense?

-=-=-
Quit posting and try Google.
Wed, 13 Apr 2011, 14:17
JL235
Also again, you don't need to use echo. It's much more readable to use close the PHP tag and then write the form as pure HTML.

It also allows you to write less (which is always a good thing)!
Wed, 13 Apr 2011, 14:22
Afr0
Does that make sense?


Nope. Trust me, I tried using $_POST. It worked fine with a single form. But when getting data from multiple forms with the same control, it kept returning the same data all the time!

(See the code in the first post in this thread)

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Wed, 13 Apr 2011, 14:25
Afr0
Also again, you don't need to use echo. It's much more readable to use close the PHP tag and then write the form as pure HTML.

It also allows you to write less (which is always a good thing)!


echo allows for much more flexible code, as it allows you to conditionally send HTML to the browser.

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Wed, 13 Apr 2011, 14:46
Stealth
Heres something you can do in PHP:



-=-=-
Quit posting and try Google.
Wed, 13 Apr 2011, 14:55
JL235
You can even output HTML wrapped up within a function...


Wed, 13 Apr 2011, 15:53
steve_ancell
@Stealth & Diablo.
COOL!... And not an echo in sight, I will have to remember that one.
Sat, 16 Apr 2011, 04:12
JL235
You also don't need a closing ?> at the end of your PHP files. Like...

This is useful for writing PHP libraries, as you often want them to contain only PHP code and output no HTML at all (not even accidental whitespace).
Sat, 16 Apr 2011, 14:26
spinal
I thought it was good etiquette to close all tags, no matter what they are and upholding html compliance?

-=-=-
Check out my excellent homepage!
Sat, 16 Apr 2011, 14:30
JL235
PHP tags aren't XML, so it's in no way invalid.