I want to redirect if form update successfully, the page i edit
example:
<?php
header("Location: update_lbctn.php?order=2")
?>
my problem is in example above order=2 is dynamic it change depend on page ID
so I try like this
<?php
header("Location: update_lbctn.php?order=" . echo urlencode($current_id['id']) ." " ")
?>
but give me error: Parse error: syntax error, unexpected 'echo' (T_ECHO)
Try this -
header('Location:update_lbctn.php?order='.urlencode($current_id['id']));
exit;
There is no need to add the echo. Just concatenate the id.
In your Code you have used extra quotes. Just Put the following code. echo is not required while using header redirect as it is, itself a php function
header("Location: update_lbctn.php?order=" .urlencode($current_id['id']))
The header function will echo out the inner content so no need to write echo again.
For this you can write
<?php
header("Location: update_lbctn.php?order=".urlencode($current_id['id']);
?>
All you need to do is pass a string to the Location.
And with your code, it will redirect to the location specified by the string, not to print it.
So, in your code:
<?php
header("Location: update_lbctn.php?order=" . echo urlencode($current_id['id']) ." " ")
?>
The echo is unnecessary.
Why do it is giving syntax error:
Its because, you are putting echo just after the dot ..
echo is expected to come at the new line where other line ends or at the first line.
In short either after semi-colon : or right in the beginning of the file.
e.g.
$test = 'gg';
echo $test;
or
echo $_GET['DUMMY_VAR_FOR_TESTING'];
So, its producing syntax error.
Related
I want to fetch the landing_page value from this SQL table and add it to header location
: Ive got the following code at the top of the page but this is giving me a blank page:
<?php
foreach($[user_name] as $user) {
$location="Location:http://".$user['landing_page'];
header($location);
}
?>
<!-- if you need user information, just put them into the $_SESSION variable and output them here -->
Order: <?php echo $_SESSION['user_name']; ?>. You are securely logged in.
Where am i going wrong?
The original code is a login script with me trying to make the user to go google.com once logged in
You are not appending the variable properly. Try with,
header('"'.$user['landing_page'].'");
I think you can do this by Simply appending the argument in header
header("Location: " . $user['landing_page']);
try this:
<?php
header("Location: ".$user['landing_page']);
?>
Try this
<?php
foreach($user_name as $user) {
header("Location:http://".$user['landing_page']);
}
?>
or
<?php
foreach($user_name as $user) {
$location="Location:http://".$user['landing_page'];
header($location);
}
?>
I have this piece of code:
if(isset($_POST['btnSubmit']) && $_POST['btnSubmit'])
{
require_once($_SERVER['DOCUMENT_ROOT'] . 'database.php');
$derpCard = $card;
$derpAccessGroup = $_POST['tbAccessGroup'];
$derpComments = $_POST['tbComments'];
if(isset($_POST['cbActivated']))
$derpActive = $_POST['cbActivated'];
else
$derpActive = "DEACTIVATED";
$x = editCard($derpCard,$derpAccessGroup, $derpComments, $derpActive);
if($x)
{
$_SESSION['editcard'] = $derpCard;
$_SESSION['editgroup'] = $derpAccessGroup;
$_SESSION['editcomments'] = $derpComments;
$_SESSION['editstatus'] = $derpActive;
echo "<script>";
echo "alert(\"Done!\");";
echo "</script>";
}
echo "<script>location.reload(true);</script>";
}
Basically, editCard runs an SQL "UPDATE ... where..." to edit the content within the db. If this is sucessful, I want it to display an alert telling the user it's been updated, as well as refresh the page.
Both the alert and reload code do not run, and i've been trying any and all alternatives! If someone has any idea as to simply refresh the page (thats the minimum i need!) It would be greatly appreciated!
I have to apologize if this answer is too short but the question is too broad or is missing more info. I noticed that one of your lines is wrong.
require_once($_SERVER['DOCUMENT_ROOT'] . 'database.php');
should be:
require_once($_SERVER['DOCUMENT_ROOT'] . '/database.php');
There should be / in it since $_SERVER['DOCUMENT_ROOT'] returns something like this:
"C:/xampp/htdocs"
So if you are to concatenate that with "database.php", you'll be having
"C:/xampp/htdocsdatabase.php" instead of "C:/xampp/htdocs/database.php"
In any case, you should try using firebug or similar browser add-on to help you debug those javascript errors(if there are any).
I hope this helps.
Try to format the script echo like this:
echo "\n<script>\n<!--\n";
echo "alert(\"Done!\");";
echo "\n-->\n</script>\n";
and
echo "\n<script>\n<!--\nlocation.reload(true);\n-->\n</script>\n";
Note the new lines added.
You appear to be missing the type attribute for script.
If you want to specify javascript, you need to include the type.
echo "<script type=\"text/javascript\">";
echo "alert(\"Done!\")";
echo "</script>";
Same goes with the other line
echo "<script type=\"text/javascript\">location.reload(true);</script>";
If the above does not help in the slightest, the problem could be with your logic statements, or that your javascript may just not be outputting what you want.
There are tools to help you figure out these issues, such as the apache logs and firebug plugin
EDIT: Forgot missing semicolon
I know how to include external PHP pages and how to start sessions etc, but I think there is something messed up with my logic on what I am working on. Hoping someone could take a look...
I have an html page that is a form that pulls up a PHP view page with the info it sends to it. I wanted to put my function in an external page, along with using sessions, but I keep getting a syntax error.
When I send my form it goes to the following:
<?php
session_start();
include 'functs.php';
if ($_POST && !empty($_POST['name'])) {
$_SESSION['name'] = $_POST['name'];
$_SESSION['time'] = $_POST['time'];
confirmed();
}
else {
print unconfirmed();
}
?>
My external page with the functions is this:
<?php
function confirmed() {
echo "<head>";
echo "<title>Confirmation Page</title>";
echo '</head>";
echo "<body>";
PRINT <<<HERE
if (isset($_SESSION['name'])) {
echo 'Thank you, '.$_SESSION['name']. ' your reservation is confirmed for ' . $_SESSION['time'] ;
}
else {
echo 'There seems to have been an error processing your reservation. Please ensure that you have cookies enabled and try your request again' ;
}
HERE;
echo "</body></html>";
?>
The error I am getting is Parse error: syntax error, unexpected 'name' (T_STRING), expecting ',' or ';' in E:\Program Files\xampp\htdocs\cis\w2\functs.php on line 10. If I insert the function internally, it works, so I know its something with how I am formatting the include page.
It's pretty obvious via the syntax highlighting what is wrong here:
echo '</head>";
//-----------^
This line has the incorrect quote mark, thus you never terminate the string, and it keeps going.
Edit:
But that isn't the only problem. You also never close your function with a right curly bracket: }.
The main problem is that you have mismatched quotes on this line:
echo '</head>";
However, I have to say I'm confused as to why you have the HEREDOC. Surely you just need the if statement alone?
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.
I'm trying to see if the user has entered a website URL into the database with the following code. If the user did not enter their website's URL, do not display anything. If the user did enter their website, display the website.
I think I'm doing it wrong.
<?php
if (!empty($url))
{
echo'';
} else {
echo'p>Website: <?php echo "http://","$url"; ?></p>';
}
?>
Apart from the wrong order (you need to remove ! before the empty()), you also have some errors in the echo part: the < is missing for the < p > tag and you are including php tags in your string.
It should read something like:
echo '<p>Website: http://' . $url . '</p>';
what you've got there is that you're checking if it's NOT empty (that is, there is some data), you're echoing an empty string. If it IS empty, then you're echoing it out.
Remove the ! in the first line and you should be right.
You're simple mismatching the meaning of "!" :
<?php
if (!empty($url))
{
echo'p>Website: <?php echo "http://","$url"; ?></p>';
} else {
echo'';
}
?>