I tried this in my php site <a href=?command=value>click here</a>
And this to get the value :
if(isset($_POST['command'])){
$command=strip_tags($_GET['command']);
Does not seem to work.. Ps. The url have one this value also: ?lang=en_US
Use $_GET instead of $_POST. And also put double quotes around the value of href attribute.
Try this....this will work...
'click here'
this is to get the value from site:
<?php
if(isset($_REQUEST['command'])){
$command=($_GET['command']);
echo $command;
}
?>
the output: value
Note:Both the codes(php and html) are written in same page(company.php)
we can also write the php code in seperate page. Difference is,the 'isset' function is not needed there.And URL should change.
code will be the following.
'click here'
next_php_page.php code:
<?php
if($_REQUEST['command']){
$command=($_GET['command']);
echo $command;
}
?>
Related
I'm trying to retrieve the "custom Phone" value from a form where the variables are being passed through a URL and then retrieved using the PHP Get method.
Here is the URL with the pass through variables:
http://domain.com/redirect.php?custom%20phone=555-555-5555&email=jk%40blackdiamondacademy%2ecom&from=jk%40blackdiamondacademy%2ecom&listname=fgxpressusa&meta_adtracking=&meta_message=1&meta_required=name%2cemail%2ccustom%20Phone&name=Jordan&submit=Submit&submit.x=121&submit.y=27
Here is the code on my landing page that has the Get PHP code:
<script type="text/javascript">
var sale = PostAffTracker.createAction('lead');
sale.setOrderID('<?php echo $_GET['meta_message']; ?>');
sale.setProductID('<?php echo $_GET['unit']; ?>');
sale.setData1('<?php echo $_GET['name']; ?>');
sale.setData2('<?php echo $_GET['email']; ?>');
sale.setData3('<?php echo $_GET['custom%20phone']; ?>');
PostAffTracker.register();
</script>
The code retrieves the "name", and "email" but not the "custom%20phone". I tried putting 'custom phone' as the get value as well as 'custom+phone' and still it doesn't retrieve it.
The issue seems to be the space in the value from my web form ("custom Phone") that is being passed through the URL as "custom%20phone".
Any help would be greatly appreciated!
I just found the answer to my own question through trial and error.
The PHP GET method translates %20 as an underscore so I put:
<?php echo $_GET['custom_phone']; ?>
Works perfect!
problem
i have two button "YES" and "NO". if user click YES then text input will appear with value set ex: value="$check['sum'];" but when user click No then text input will appear without value ex: value ="".
here is my code
<input id="test<?php echo $row['br_loc'];?>" value="<?php echo $value;?>" name="test" type="text" class="test" style="width:70px;display:none">
and jquery
$(document).ready(function(){
$("#Yes<?php echo $row['br_loc'];?>").click(function(){
$("#test<?php echo $row['br_loc'];?>").show(1000);
});
$("#No<?php echo $row['br_loc'];?>").click(function(){
$("#test<?php echo $row['br_loc'];?>").hide(1000);
});
thanks you
Try using the disabled attribute:
$("#test<?php echo $row['br_loc'];?>").attr('disabled','disabled');
and
$("#test<?php echo $row['br_loc'];?>").removeAttr('disabled');
Try this:
$(document).ready(function(){
$("#YES").click(function(){
$("#test").show(); //value of input as set before. so, just show
}
$("#NO").click(function(){
$("#test").attr('value','').show(); //set value = '' , and show
}
});
Use binding function so that you provide your JS code with exact parameters. Code like yours should never be used.
Object ID or class should contain alphanumerical characters only, should not begin with number(s), and optionally, - or _ might be used. Avoid spaces or, as you've already shown yourself, using embedded PHP code which is highly unlikely to work in any further project of yours. It's also dangerous.
instead of this code $("#Yes<?php echo $row['br_loc'];?>")
try the following
$("#test<?php echo $row['br_loc'];?>").
Because you used id of button as "test<?php echo $row['br_loc'];?>". so only your click event not worked.
How would I for example, take a url with some $_GET data, for example http://www.website.com/something?food=steak
How would I then output steak? My current situation is that I'm trying to use the Header function to redirect to a page where I have it so that if $_GET["duplicate"] is equal to 1, then echo this, else, echo nothing. But its not taking the $_GET data I can tell I did a var_dump($_GET);
<?PHP if ($_GET["duplicate"] == 1 )
{
echo "<h1>Username Taken!</h1>";
}
else
{
echo "";
}
?>
The above is using the url http://something.com/register?duplicate=1
It's just a variable, treat it like one:
echo $_GET['food'];
Everything after question mark is available in form of global array $_GET.
$a=$_GET["food"];
echo $a;
also
if url has ?food=steak&color=red;
$a=$_GET["food"];
$b=$_GET["color"];
more than one is possible. Also search for $_POST.
Alright, so I figured my issue out. I have a $_GET variable that gets the end of the page and declares it as "p" for page. I need to do the following to get it to work.
?p=createuser&duplicate=1
My problem is I have a php variable $ba with a value of 147 retrieved from a DB the below snipets of my code does not work, no image is shown. If I add $ba=147; before the fill_div call it works perfectly. I am stumped as to why it dos'nt work when $ba populated from the DB.
In both cases a check of the source code for the page shows the call being filled correctly fill_div("147");
<script type='text/javascript'>
function fill_div(ba)
{
document.getElementById("ba").innerHTML="<img src='admin/images/image.gif'/>";
}
</script>
<script>
fill_div("<? echo stripslashes($ba); ?>");
</script
<div id="<? echo $ba ?>" style="border:1px solid; width:120px; height:40px"></div>
You're passing the string literal"ba" to getElementById when you need to pass the variable ba
document.getElementById(ba).innerHTML="<img src='admin/images/image.gif'/>";
Also the stripslashes might not be a good idea if $ba has quotes in it, if $ba has a " in it will cause an error in your JavaScript if it is not escaped.
try ..
document.getElementById(ba).innerHTML
document.getElementById("ba")
should be
document.getElementById(ba)
Try changing your document.getElementById to:
document.getElementById(ba)
If it has quotes (as in your example code) "ba" is treated as a string, not a variable.
hi guys im trying to show and hide div according to mysql value but i couldnt do it can you help me what im doing wrong
here is my code thanks a lot for your ideas
var Value = <?php echo json_encode($valuek) ?>;
if (Value==1){
$('#show_hide').show();
}
else{
$('#show_hide').hide();
}
<?php
$valuek = $session->userinfo['vcc'];
?>
<div id="show_hide">
some code
</div>
<?php echo json_encode($valuek) ?>
will return a json string, instead try just using "echo"
<?php echo $valuek ?>
If all you are going for is a boolean value then there is simply no need for JSON.
Echo the value directly into the JavaScript. Remember to ensure you are passing a valid boolean value.
PHP code -
<?php
$showDiv = ($dbValue == 1? 'true' : 'false');
?>
JavaScript + PHP injection -
<script>
var value = '<?php echo $showDiv; ?>';
<script>
Don't forget to wrap the PHP injected value with quotes.
$valuek = $session->userinfo['vcc'];
I'm not sure if you have the code in this order in your php file, or just showed pieces of code in this order, but Should go BEFORE your js code. It has no value when js code is run.
To see what $valuek is, just echo it on top of the screen
<?php echo "<h1>$valuek</h1>" ?>.
Or just look at the source - at your js function, to see what is printed after 'var Value ='
That's the main thing really - to make sure that you getting what you expect from session.
And as been said, you don't need jason_encode, but you do need a semi-colon after echo command.
Also, I hope your jquery code is within $(document).ready function, not as is.