This question already has answers here:
The 3 different equals
(5 answers)
Closed 6 years ago.
if($_GET["content"] ="foo"){
echo("<h4>foo</h4>");
exit;
}
When I type in URL "127.0.0.1/_/index.php?content=foo" it seems to output the previous code I wrote
if($_GET["content"] ="picture"){
echo("Picture:<br>");
echo("<img src='./ku~1.jpg'></img>");
exit;
}
What is the problem here?
if($_GET["content"] ="picture"){
assigns $_GET["content"] the value "picture". You want to use
if($_GET["content"] =="picture"){
and
if($_GET["content"] =="foo"){
instead.
Have you started your file with
<?php
And you are assigning the value content by only using one =
Do this instead
if($_GET["content"] == "picture"){
echo "Picture:<br>";
echo '<img src="./ku~1.jpg"></img>';
exit;
}
You were also wrapping your echo with parentheses when they should be contained in quotations.
I forgot the first example... That should be:
if($_GET["content"] == "foo"){
echo "<h4>foo</h4>";
exit;
}
Related
This question already has answers here:
How to use store and use session variables across pages?
(8 answers)
Reference - What does this error mean in PHP?
(38 answers)
Closed 2 years ago.
$_SESSION['Active'] = 1; I have defined this in my login.php file.
if($_SESSION['Active'] ==1){ I am checking if this exists in my AdminControl File
echo "Hello"; when I login this works.
}
if (isset($_POST['submit'])) { this is the code that I used for going back to the AdminControl Page
header("Location: AdminControl.php");
exit();
}
When I go back to the Admin Control the Hello disappears.
In this picture you can see that there is not Hello
on your admin control page you could add the following.
<?php if(isset($_SESSION['Active']) && ($_SESSION['Active'] == '1')) { echo "Hello"; } else { echo "Something else";} ?>
Hope this helps you.
This question already has answers here:
PHP Pass variable to next page
(9 answers)
Closed 3 years ago.
After a form submit, I am redirecting to the mentioned header location using below codes:
PHP Part:
$TestMessage = "This is a sample message. This is not a constant value. Original data will be collecting from DB";
if(mysqli_affected_rows($conn) > 0) {
header('Location:mydaomain/expenses?success=1');
}else{
header('Location:mydomain/expenses?failed=1');
}
HTML Part:
<div class="SubResult" id="SubResult" >
<?php
if ( isset($_GET['success']) && $_GET['success'] == 1 )
{
echo $TestMessage;
echo "<h1 style='color:green;padding:3%;'>Success !!</h1>";
}
if ( isset($_GET['failed']) && $_GET['failed'] == 1 )
{
echo $TestMessage;
echo "<h1 style='color:red;padding:3%;'>SQL Error !!</h1>";
}
?>
</div>
Issue with the above code is,HTML wont display $TestMessage PHP variable content.
Why I am using this header option in PHP:
Earlier, form was getting submitted whenever I refresh the page after an original submit. I found this solution to avoid that issue.
When I remove this header part from php file, I am able to echo variable to PHP (But at that I am facing issue with the form submission on page refresh issue)
Is there any way I can echo this variable to HTML ?
When you use header, you are doing a redirect, so your variable $TestMessage is not available after that, if you want to use it, make sure you pass using query string, for example:
header('Location:mydaomain/expenses?success=1&testMessage='.$TestMessage);
and in the next page use $_GET['testMessage'] to get his value.
This question already has answers here:
The 3 different equals
(5 answers)
Closed 5 years ago.
I am trying to figure out this issue I am having.
I am trying to create a link but ONLY if there's an admin logged in, otherwise the link should be hidden.
if ($administrator = true) {
echo '<a href="medewerkertoevoegen.php?id='.'">Medewerkers
toevoegen</a>';
}
else
{
echo '<span></span>';
}
I am not sure if this is how it should work, currently my database looks like this. http://i.imgur.com/CdgLXkj.png
Please let me know if you can help me because I am very new at this, thanks!
Because '=' is assignation (not comparing). You must use '==' or '==='.
if ($administrator === true) {
echo '<a href="medewerkertoevoegen.php?id='.'">Medewerkers
toevoegen</a>';
} else {
echo '<span></span>';
}
This question already has an answer here:
Enabling php.ini for backward compatibility
(1 answer)
Closed 9 years ago.
Ok so i want to have an include code on my index.php page that will include all of the other html pages within it. I used to do this using an id?=link.html link and this:
<?php
$id = $HTTP_GET_VARS['id'];
if ( !$id || $id == "" )
{
$number=10;
include("news/show_news.php");
}
else
{
include "$id";
}
?>
but apparantly http_get_vars is unrecognized or something? How can I fix this so that it will work? Or if things have changed, why should I not use this kind of thing for includes?
You can use $_GET to fetch the query string parameter by GET request, e.g.
index.php?id=123
The id value can be obtained by $_GET['id'].
p.s. your PHP codes are really old.
solved with the following:
<?php
if (!empty($_GET['id'])) {
$id = $_GET['id'];
$id = basename($id);
include("$id");
} else {
include("news/newsfilename.php");
}
?>
and
<a href="index.php?id=pagename.html">
Page Name
</a>
as the html
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Hilighting The Current Navigation Tab Using URL in PHP
hilighiting the current tab without php extension not working
<?php if ("index.php" || "index"==$Current)
{echo "selected";}else {echo "";}?>
I think you want:
<?php if ("index.php"==$Current || "index"==$Current) {
echo "selected";
}else {
echo "";
}
?>
What you wrote didn't really make sense.
This code
if ("index.php" || "index"==$Current)
already return true because
if ("index.php")
same
if ("index.php" != "")