How to pass multiple parameter via PHP header? - php

Can I use header to pass multiple parameters or just one?
I am trying to implement this but its not working, It doesn't navigate:
$selected_company = $_POST['company_name'];
$company_type = $_POST['company_type'];
$url_param = "comp_id=$selected_company&comp_type=$company_type";
header("location: ./create_user.php?$url_param");
Whats wrong with the code I am using?
If I want to pass only want parameter I can do it like this and it works:
header("location: ./create_user.php?$selected_company");
P.S. it is so strange that I was not able to find one single working solution to this, I assumed this is a very common issue.

Try out this and it worked for me:
<?php
$selected_company = $_POST['company_name'];
$company_type = $_POST['company_type'];
$url_param = "comp_id=$selected_company&comp_type=$company_type";
header("location: ./create_user.php?".$url_param);
?>
Also checkout the value coming from POST parameters;

Related

Using $_GET instead of $_SESSION

How do you set a $GET variable?
Hi i have done this before, but my method is a bit hit and miss so i was wondering what is the correct way to do this.
My url is:
Franchise-Details.php?Franchise=Enfield/status=Driver
And i want to set the Franchise name and staff status as a variable as i will be using them continuously throughout my webpage.
This is what i have done:
$admin_status = mysqli_real_escape_string($dbc,$_GET['status']);
$fr_Area = mysqli_real_escape_string($dbc, $_GET['Franchise']);
But it does not work. No error messages, just shows nothing if i try to apply it, for example echo $fr_area;. If i change the get to session it works. But i want to use get.
I have also tried:
if (isset($_GET['status'])){
$admin_status = mysqli_real_escape_string($dbc,$_GET['status']);
}
if (isset($_GET['Franchise'])){
$admin_status = mysqli_real_escape_string($dbc,$_GET['Franchise']);
}
How can i improve this

Using $.get [AJAX] to pass a JS variable to PHP not working

I am trying to pass a variable from javascript to PHP using a an AJAX request [$.get] but am getting nothing through the $_GET method. I am wondering why the variable email won't pass even though there is a value within it.
fetch.js
email = resp.emails[i].value;
$url = 'login.php'; //this file is on the same directory as fetch.js
//AJAX
$.get($url, {name: email});
login.php
$googleid = $_GET['name'];
echo $googleid; //nothing showing
If you need any more details please don't hesitate to ask.
EDIT I know I am going to get flamed for this but this was a typo. In my script I didn't make this mistake.
$googleid = $_GET['email'];
should be
$googleid = $_GET['name'];
Because your GET variable was name and email was value that assign to name (eg, name = test#example.com). So you should access it by $_GET['name']
It should be
$_GET['name'];
What is the line email = resp.emails[i].value;? Has that a value?
Since in JS you send GET variable named name then in PHP you have to access it by $_GET['name'], not $_GET['email']:
$googleid = $_GET['name'];
You have to use $_POST for a parameter request.
For get the parameter would be visible in the url what you probably dont want like login.php?email=my_email#domain.tld

PHP ECHO to pass two Var's via URL

echo "<li><a href=\"#\" onclick='load_page_device(\"mg-device.php?device=device_name&sensor=$p1_url\")'>".$row['p1_name']."</a></li>";
Alright I simply trying to pass two variables in a url via a php echo statement. It's simply not working.
I am then using
$device_name = $_GET['device'];
$sensor_name = $_GET['sensor'];
I have tried also to use & instead of & only. The first variable always seems to get passed but the second one never does. Any help is greatly appreciated I have been trying to get this to work for hours now. Thanks!
try
echo '<li>'.$row['p1_name'].'</li>';
you need to first check that $_GET['device'] , $_GET['sensor'] is set
try
if(isset($_GET['device']) && isset($_GET['sensor'])){
//stuff
}else{
//other stuff
}

redirect dosen't works in codelgniter

I am using codelgniter and i want to pass the below 3 parameters to site_url().But this take only the method name not the parameters.... How can i pass these parameters. Please help me
function report_del() {
$island = $this->tables($this->input->post('island'));
$prefix = $this->tables($this->input->post('prefix'));
$date = $this->tables($this->input->post('date'));
redirect(site_url('admin/admin/dateandprefix/').$date.'/'.$prefix.'/'.$island);
//$segments = array('admin/admin/dateandprefix/',$date,$prefix,$island);
//redirect(site_url($segments));
}
If the code is copy pasted, there is an error in the single quote
redirect(site_url('admin/admin/dateandprefix/').$date.'/'.$prefix.'/'.$island);
you are making a mistake . use site url like this .
redirect(site_url('admin/admin/dateandprefix/'.$date.'/'.$prefix.'/'.$island));
for more details you can view this link
user guide
Hope this help.
Try this :
redirect('admin/admin/dateandprefix/'.$date.'/'.$prefix.''.$island.'','refresh');
If you are using CI4
Then use in base use and/public after that
http://localhost/foldername/public
then it work fine

Post variable not being caught in php sent from dynamically generated html

Im having a really simple issue but iv looked around and cant debug it for some reason, can someone point me in the right direction??
I have a php script which dynamically generates a link
<?php
$id = 1;
echo "<a href='http://www.example.com/page.php?id='$id'>click link</a>"
?>
On example.php I have...
$userId = $_POST['id'];
then I insert $userId query...
?>
For some reason the Post vairable is not being cause by the example.php script I can see it in the URL at the top of the page but they wont make sweet passionate php love. Any thoughts? I will mention I am doing this from within an IFRAME however I tried it simply and got the same result :(
I think you mean, on page.php you have...
If that is the case, you are sending the id parameter in a GET, not a POST. To access it in your other page you need to use:
$userId = $_GET['id'];
your variable is in $userId = $_GET['id'];.
another problem is a mess with ' symbols: should be
echo "<a href='http://www.example.com/page.php?id=$id'>click link</a>"
Sorry, but you ar sending data via GET NOT POST
access it via $_GET['id'];

Categories