Cannot send data using form from index.php - php

I've run in to a small problem and I hope someone can help me out.
I made a form and it works fine:
http://www.volunteeringnews.com/formorg.php
If I hit send it returns a message saying User has been created.
So that works but if I go to http://www.volunteeringnews.com/ and under "Organisations" I click Submit it doens't work. And the Submit button is justa link to formorg.php.
I tried adding this to index.php but that was no success.
$action = isset($_POST['action']) ? $_POST['action'] : "";
//include database connection
include 'mysqli.php';
Can someone have a look?
Thanks!

The $_POST variable will be filled with the form data passed to it.
So on your form you'll have something like this:
<form action="http://www.volunteeringnews.com/formorg.php" method="post">
<input type='text' id='firstname' name='firstname'>
<input type='submit'>
Then when you submit that form, formorg.php will have the $_POST array populated with the names you gave the form fields. So, for example, to access whatever value the user filled out for the firstname field you'd access $_POST['firstname']

The first thing I can see is that the Action is not correct.
Normaly you should set the Action to the Script you were wanting the Post data to be:
<form action="http://www.volunteeringnews.com/formorg.php" method="post" border="0">
Otherwise you are going to direct the Post to the index.php were you are not getting the Request Values.

Related

form type="url" POST to PHP

So I have a form that requires a user to submit their website to a form. Here is the html line:
<input type='url' name='link'>
And I'm using <input type="submit" value="submit" formmethod="post"> to submit the form to a php
And I'm trying to retrieve the values in my php file with:
$link = $_POST['link'];
Why isn't this working? At first I thought it was because I had htmlspecialchars() but it's not coming through without it either. I can't find anything in any google search that even mentions anything related to this kind of problem (with a type="url" form)
What do I need to do to process form data with type of "url" in PHP with a $_POST?
Get your form method to be set to post e.g
<form method=post>,
if you submit the form and in the url in your browser u can see some more inf then be sure 2 check your form method
I think this is wrong,
method="post"
Its only method, not formmethod
Also make sure, you dont have one more for element name with link.

$_POST and $_GET not working on var_dump but working on loggued requests

I have a very simple form like I've done dozens, but this one isn't working for a reason that eludes me.
When var_dumping the $_POST variable after submit it's empty but it's working on the request_maker from chrome.
here is where it is submited:
echo " <form method='POST'>
<input type='button' class='button' style='height:50px' name='manage' value='export' onclick='submit()'/>
</form>";
var_dump($_POST);
the var_dump returns an empty array.
From other subjects I've seen they talk about php.ini wich was unchanged since a long time on my side, no updates were made, and others post requests on different pages are working
The problem is that you are not POSTing the form when you press the button. You are performing the onclick event.
Remove the onclick attribute (or make sure that the submit() function is POSTing).
var_dump($_POST)
Only works when you submit form. so change code as mention below you will able to dump data
if(isset($_POST)){
var_dump($_POST);
}
also put action in form Tag
action="<?php echo $_SERVER['PHP_SELF']; ?>"
Other Thing try put Input field to get clear idea
<input type="text" name="name"><br>

GET and POST is submitting on same time

I have html page and I have taken one form in it and other link outside the form .Form is Submitted by POST method,when I submitting form first time its ok and when I click link it pass data by GET method and when I again submit form then it send both GET and POST variable i.e form data and link data both.so what is the reason for that and how can I solve it.My html page is below
<html>
<body>
<form method='post'>
<input type=input name='name'/>
<input type=submit name='submit' value='submit'/>
</form>
<a href='check_global.php?page_number=6'>Page Number</a>
</body>
</html>
Because the form hasn't the action attribute, so it simply reload the page. When you submit it the first time it's all fine, but when you do it after clicking the link, the url is 'dirty' due to the data of the link, so you have both GET and POST values.
You can check wether the POST attribute is set ( if(isset($_POST['name'])) with php), in this case it has been submitted with the form
When you submit the form the second time you see the form parameters + the url parameter of the page (remember you clicked the link with the relative URL 'check_global.php?page_number=6').
To verify the above try this:
<?php
echo 'GET param ' . $_GET["page_number"];
echo 'POST param ' . $_POST["name"];
?>
As you can see you can access both types of parameters during a POST request.
Hope that helps.
Just to make the point, the OP did not indicate that the form was supposed to submit to anywhere but the current page. So just for funsies, here is the same basic idea, but with an action attribute value:
<form method="post" action="">
<input type="text" name="name"/>
<input type="submit" name="submit" value="submit"/>
</form>
Page Number
Notice that I've set it up so that, for whatever reason, the link points back to this same page and so does the form. The result:
First Load: form submit makes request with POST data to blah.php
Second Load: link follow makes request with GET (thanks to the query string) to blah.php?page_number=6
Third Load: form submit, using blank action to indicate that current page is where to post, makes request with POST form data to blah.php?page_number=6, thus having both POST form data and GET URL data.
So your options are to either set the action attribute value to blah.php so that it does not include the query string, or to accept that if you want to avoid the various ways of doing this in favor of having a more modular form (drop it in any page and you know it will post to that address), then to simply have the PHP backend check if $_POST['submit'] is set and if so, handle it like a form post and don't use any of the $_GET logic that might be screwing things up.
The link is never sending the form data as POST, and the POST data is not part of the GET array, so you know that when there is no POST, it's just get and if there is POST, it was a form submit, even if there is a GET array.
Or just use separate scripts so you don't get mixed up.

How to redirect page using $_SERVER['REQUEST_URI']

I'm building a page that has a form that's submitting to my database. The form needs to post to the current page to process, but since I'm using this same form on many pages, I would like a way to tell the form to use the user's current page to submit to. I know the code below can get this information, it's what I'm using to send url data to my database for another use.
$_SERVER['REQUEST_URI']
I'm just not sure how to use that within the code that loads the page. I suppose I could write something that will pull out the submitted url info that was just submitted to my database and then plug it in, but is there a way to just use the above code to do it? That seems easier, but when I tried plugging it in, it fails and just gives me a "404 not found" error, so I know I'm not doing it correctly.
It just needs to go in the simple form post action code below:
<form action="comment_box.php" method="post">
I've looked up similar questions, but I couldn't find anything that worked with what I needed, I just got more 404 errors. Any advice would be great, thanks!
If your posting to the same page the user is on you can do
<form action="" method="post">
Leaving the form action blank it will post to what ever the page the form is on.
Not sure what language your using but I assume php you then use
<?php
if($_SERVER['REQUEST_METHOD'] == "POST") {
// form submit button was pressed your php code here
} else {
// no form submit button was press do nothing maybe show form html code here
}
?>
or what your trying to achieve
$url = $_SERVER['REQUEST_URI'];
Then in PHP
<form action="<?php echo $url; ?>/comment_box.php" method="post">
for example you have a following code
<input type="submit" name="click_me" value="Login">
then in the php, you have to check like
<?php
if(isset($_POST,$_POST['click_me']) && $_POST['click_me']="Login"){
//do your stuff
}
?>

Retrieve user ID displayed in the URL using PHP

I have a page where the admin can see all the members who are registered, that means their information are stored in the database. It is in tabular form with Update links displayed beside each name which redirects to my update.php page with forms. After I click the Update link, I am redirected to my update.php and the URL displays the user id which I need to update :clinic/update.php?res_id=3
Now, I have a form in my update.php and I need to get that res_id=3 displayed in the URL to also be included in my MySQL INSERT STATEMENT in my action script which is add_assessment.php. I have tried using $ID=$_GET['res_id'] and $ID=$_POST['res_id'] but none of which is working. Can anybody please tell me what line of code do I have to use? Thanks
Without having any of your code to go by, I can only suggest stepping through your workflow and using var_dump on both $_GET and $_POST and making sure that the res_id is being passed from page to page.
You are not passing the value to the form so the $_POST or $_GET values on update.php will not be available to add_assessment.php.
In clinic/update.php?res_id=3 output $_GET['res_id'] as the value in a hidden form field like so:
<input type='hidden' name='res_id' value='<?php echo htmlspecialshars($_GET['res_id']); ?>' />
Then access it in add_assessment.php with $_POST['res_id']
OR
Append it to the action='add_assessment.php' in the form like so:
<form action='add_assessment.php?res_id=<?php echo htmlspecialshars($_GET['res_id']); ?>' method='post'>
Then access it in add_assessment.php with $_GET['res_id']

Categories