I have a redirectURL that currently redirects to a default page and works great
$WA_redirectURL = "mypage.php";
I want to insert a _GET value that is available but am getting a syntax error. Here is what I am trying. I thought the periods would allow me to get the value into the URL?
$WA_redirectURL = "mypage.php?EmpNumber=". echo $_GET['EmpNumber'] .";
You don't use echo when concatenating strings:
$WA_redirectURL = "mypage.php?EmpNumber=". echo $_GET['EmpNumber'] .";
should be:
$WA_redirectURL = "mypage.php?EmpNumber=". $_GET['EmpNumber'];
(The last quote is also an error).
You use echo to send text to the user.
If you want to join strings together use the period to join things.
For example:
echo "hello"; // this will print hello to the screen
$testing = "hello "."world!";
echo $testing; // this will print hello world! to the screen.
Related
I have this URL in my page
https://www.albaama.com/search.php?qry=Fashion%20&%20Clothing
and I use this code below to echo out the value of the variable 'qry'
<?php
if (isset($_GET['qry'])) {
echo $_GET['qry'];
}
else {
echo "";
}
?>
but whenever I echo it, I only get Fashion instead of Fashion & Clothing.
please how do I get the complete value?
This query string: https://www.albaama.com/search.php?qry=Fashion%20&%20Clothing
Translates to this:
URL: https://www.albaama.com/search.php
Parameter 1: qry="Fashion " ("Fashion" and a trailing space)
Parameter 2: " Clothing" ("Clothing" and a leading space)
The problem is that & introduces a second parameter.
You need to urlencode() the entire string "Fashion & Clothing"
I want to pass the two variable from the below php script to the next php page that is pid and title. pid is working fine but I don't know how to take the title from SQL query and pass it to the next php script.
$result= mysqli_query($bd, "select p.title, p.description from POI p where p.pid='$pid'");
while($row=mysqli_fetch_array($result))
{
echo "<i><h2><a href=link_comment.php?pid=$pid&title='$row[0]'>$row[0]</a></h2></i>";
echo $row[1];
echo "<br>";
echo "<br>";
}
the below code is for getting the values from the above php script:
$pid=$_REQUEST['pid'];
$title=$_REQUEST['row[0]'];
Change this
echo "<i><h2><a href=link_comment.php?pid=$pid&title='$row[0]'>$row[0]</a></h2></i>";
to this
echo "<i><h2><a href='link_comment.php?pid={$pid}&title={$row[0]}'>{$row[0]}</a></h2></i>";
When you build the url, you are passing parameters named pid and title.
Change
$title=$_REQUEST['row[0]'];
to be
$title=$_REQUEST['title'];
Instead of the ' you are using in title='$row[0]', use {}, title={$row[0]}:
echo "<i><h2><a href=link_comment.php?pid={$pid}&title={$row[0]}>{$row[0]}</a></h2></i>";
And on the next page, $_REQUEST['title'];
Try this:
echo "<i><h2>".$row[0]."</h2></i>";
Then on the link_comment.php script:
$pid=$_GET['pid'];
$title=$_GET['title'];
I have a php function which displays a rating bar with the arguments. I have a variable called itemID inside my php page which holds the unique item number. I need to send this value to my function and also echo command must stay. Is there a way to achieve this?
Here is the code, which does not work. When I try it on the server, it does not show the id of item, it prints the variable name as it is.
<?php echo rating_bar('$as',5) ?>
What I get at html file:
<div id="unit_long$as">
instead of the item id in place of $as.
Single Quotes do not support variable replace,
$as = "test";
echo '$as'; //$as in your end result
echo "$as"; // test in your end result
echo $as; // test in your end result
//For proper use
echo " ".$as." "; // test in your end result
Update for newer PHP versions you should now use Template Syntax
echo "{$as}"
If I get what you are saying, this is what you are asking.
<?php echo rating_bar($itemID,5); ?>
With the limited code you are providing, thats what looks like you are asking.
Interesting. I have 2 links calling 2 JS functions - the first works , the second - doesn't. It only calls function addns() when the argument is empty. Otherwise nope...
PHP:
while ($row_mem = mysqli_fetch_array($mem)) {
$membs[] = $row_mem['username'];
$membs_id[] = $row_mem['user_id'];
}
}
//FIRST FOREACH CALL PROPERLY
foreach($membs_id as $val_id) {
echo"<a href='javascript:addms($val_id)'><img src='$pcheck' width='66' height='68'
border='1' class='currmem'/></a> ";
}
//THIS ONE DOESN'T
foreach($membs as $mes_id) {
echo"<a href='javascript:addns($mes_id)'>$mes_id</a> ";
}
JS:
function addms(msid) {
var addm = msid;
alert(addm);
}
function addns(nsid) {
var addn = nsid;
alert(addn);
}
I cannot see any error - thanks for comments !
Update to match new answer:
you need to put quotes around your variables. ($val_id) probably works because you're retrieving an id which I'm guessing is an integer, so it's a valid JavaScript literal.
($mes_id) probably doesn't work because you're getting strings back but not wrapped with quotes, so they aren't valid JavaScript literals.
so usernames will be joe and shmoe, javascript becoems
addns(joe) and addns(shmoe), which is probably not what you want. You want addns("joe") and addns("shmoe").
Also note once you fix this is an XSS vulnerability if users can choose their username.
See here: http://us2.php.net/manual/en/function.echo.php
Using single quotes will print the variable name, not the value
echo 'foo is $foo'; // foo is $foo
I can't see how you're using the wrong quotes to be honest, other than if the JavaScript function requires them, so just to make everything simple, try this:
//FIRST FOREACH CALL PROPERLY
foreach($membs_id as $val_id) {
echo "<a href='javascript:addms(\"".$val_id."\")'><img src='".$pcheck."' width='66' height='68'
border='1' class='currmem'/></a> ";
}
//THIS ONE DOESN'T
foreach($membs as $mes_id) {
echo "<a href='javascript:addns(\"".$mes_id."\")'>".$mes_id."</a> ";
}
as above when a user is logged into my website, I want it to say hello or welcome "user"
i'm using the code below:
[code]
<?php
$user = $_GET['session_is_registered'];
echo ('$user');
?>
[/code]
but the php just displays "$user"
what am I doing wrong?
thanks
just use
echo $user;
echo is a keyword, not a function, so you don't need the parenthesis. Also, to evaluate variables inside a string you need to use double quotation marks e.g. echo "Hello, $user";. If you're just using the variable on its own you don't need the quotation marks at all.
echo $user;
echo 'Hello, ' . $user;
echo "Hello, $user. Your last visit was $lastVisitDate.";
Use double quotes if you want to evaluate $user variable inside a string. Otherwise just use:
echo $user;
As other answers have already stated.
When using ' single quotes, it means literal. You don't need any quotes.
echo $user;
Thats it.