Php variable not showing up? [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Hi I'm trying to change the picture for facebook thumbnail by having php set the image in the meta tag depending on the page. I have this code but for some reason when I go to Facebook and debug it it actually shows the variable and not what the value of the variable is. Here is my code please help thank you!
<?php
if($ifpage == 'picture.php')
{
$metaimage = '<meta property="og:image" content="http://www.quickdailylaugh.com/photos/print $picture" />';
print($metaimage);
}
?>

Your variable is inside of a string enclosed with single quotes. Single quotes will take the literal value of the string $varname and not translate the variable to it's value. You need to use double quotes. Example:
$var1 = 'test';
$foo = 'The value of var1 is: $var1'; // The value of var1 is: $var1
$bar = "The value of var1 is: $var1"; // The value of var1 is: test

To interpret the varible you must use double quotes.
<?php
if($ifpage == 'picture.php')
{
$metaimage = "<meta property=\"og:image\" content=\"http://www.quickdailylaugh.com/photos/print $picture\" />";
print($metaimage);
}
?>

I had to do another query for it to show... Thank you all for the answers here is what i used...
<?php
if($ifpage == 'picture.php')
{
$photoid = $_GET['picture'];
$sql = "SELECT * FROM photos WHERE id=$photoid";
$pic = mysql_query($sql);
while($row = mysql_fetch_array($pic))
{
$picture=$row['picture'];
}
$metaimage = "<meta property=\"og:image\" content=\"http://www.quickdailylaugh.com/photos/$picture\" />";
print($metaimage);
}else{
?>

Related

my all value is not showing in view, what can i d [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
This is my edit page where i want to get data from database in input box
#php
$abs = explode(',' , $order->product);
$quantitys = explode(',' , $order->quantity);
foreach (array_combine( $quantitys, $abs) as $quantity => $ab) {
$val = $ab . " " . $quantity;
echo "<input type=text name=pro value=$val>";
echo $val;
echo '<br>';
}
#endphp
This is pic you understand well after see image at bottom of input box this is original value that has to come
Rewrite this:
echo "<input type=text name=pro value=$val>";
to this
// add double quotes to attribute values
echo '<input type="text" name="pro" value="'.$val.'">';

Session variables in PHP not appearing [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I have read all the questions concerning this but I'm still at a loss.
Using a test script like this
// PAGE 1
<?php session_start();
echo var_dump($_SESSION) . "<br>";
$_SESSION[‘session_var’] = "stuff";
$PHPSESSID = session_id();
echo session_id() . "<br>";
?>
<html>
<head><title>Testing Sessions page 1</title></head> <body>
<p>This is a test of the sessions feature.
<form action="sessionTest2.php" method="POST">
<input type= "text" name= "form_var" value= "testing">
<input type= "submit" value= "Go to Next Page"> </form>
</body>
</html>
//PAGE 2
<?PHP session_start();
echo var_dump($_SESSION);
$session_var = $_SESSION['session_var'];
$form_var = $_POST['form_var'];
echo "session_var =" . $session_var. "</br>";
echo "form_var =" . $form_var. "<br>";
$PHPSESSID = session_id();
echo session_id();
?>
the results I get in page 2 are
array(1) { ["‘session_var’"]=> string(5) "stuff" } session_var =
form_var =testing
al89u6vu02lstp99cs4damdn04
As you can see the variable session_var can be seen in the array but is not being output to the screen where expected, and yes session_start() is at the very top of both pages.
Any ideas what may be wrong
$_SESSION[‘session_var’] = "stuff";
Is using non ascii ‘’ quote marks.
Are you using a word processor to edit your code?
Those quotes are now part of the key name, see this ["‘session_var’"].
Stick to simple ascii single and double quotes ' or "

Extra "?>" symbol in PHP file (top left corner) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have an issue with a PHP page which displays a "?>" symbol in the top left corner. It looks like this:
<?php
include_once("DBconnect.php");
$getuser = $_POST["RegUsername"];
$getpass = $_POST["Pass"];
$getrepass = $_POST["RePass"];
$getemail = $_POST["Email"];
if($getuser){
if($getpass){
if($getrepass){
if($getpass == $getrepass){
if($getemail){
$code = rand();
if(mysqli_query($link, "INSERT INTO users VALUES ('', '$getuser', '$getpass', '$getemail', '0', '$code')")){
echo "INFO1";
}
else{
echo "ERROR6";
}
}
else{
echo "ERROR5";
}
}
else{
echo "ERROR4";
}
}
else{
echo "ERROR3";
}
}
else{
echo "ERROR2";
}
}
else{
echo "ERROR1";
}
?>
And I use this jQuery function to display the PHP returned value in my HTML page:
$("#RegSubmit").click(function(){
$.post( $("#RegForm").attr("action"),
$("#RegForm :input").serializeArray(),
function(info){
$("#RegErrorLog").empty();
$("#RegErrorLog").html(info);
});
$("#RegForm").submit(function(){
return false;
});
});
I always get the "?>" in front of the PHP "ERROR" returned value.
How can I get rid of that? Or how can I return a value from the PHP file using a variable instead of echo
I guess there's a problem in your DBconnect.php file.
Apart from that... you should really think about validating values taken from Http POSTs in your PHP script, before using them in db queries.
Check if you are not printing that symbol on the included file "DBconnect.php".

PHP: Assign $page variable if page url is = to '?' [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Is there a way in PHP to assign or display a variable if the page URL is equal to a specific value?
I have a site with 100 pages. Each page has a list of variables that are echoed through it based on $page variable. I would like to have this variable assigned on the fly. I want to be able to set a variable, 1-100 for example, based on page URL.
If page URL is equal to
www.example.com/page/dog
set the $page variable for page to dog.
If page URL is equal to
www.example.com/page/cat
set the $page variable for page to cat.
So on and so forth. Once the variable is set certain things will happen. In order for the correct information to be displayed I need the correct page variable to be set.
Below is ALL the code that exists on each page.
<?php $page = 'example1'; ?>
<?php include '../includes/core/overall/header.php'; ?>
<?php include '../includes/core/overall/footer.php'; ?>
Use the following:
$page = basename($_SERVER['SCRIPT_FILENAME']);
You can combine basename($_SERVER['SCRIPT_FILENAME']) like this:
<?php
include '../includes/core/overall/header.php';
include '../includes/core/overall/footer.php';
$var = basename($_SERVER['SCRIPT_FILENAME']);
//get page with .php
$var = preg_replace('/\.php$/', '', $var);
//remove .php from end
if($var == "dog"){
$page = "dog";
}
else if($var == "cat"){
$page = "cat";
}
else{
$page = "foo";
}
echo $page;
?>
Hope this helps!
Take advantage of HTTP's pathinfo.
$DOCUMENT_ROOT/page/index.php:
<?
$page = substr($_SERVER['PATH_INFO'], 1);
...

Count words from textarea , error switch [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have a form with an input type number and a textarea, named valoare and textarea
I have 5 radiobuttons,each with name option and value 1,2,3,4,5
so lets say for first radio button I want to display the number of words from textarea.
This is the code:
if (!empty($_POST['textarea']) && !empty($_POST['valoare']))
{
$option = "option";
switch($option)
{
case 1:
if(isset($_POST['submit']))
{
$count =str_word_count($_POST['textarea']);
echo $count;
break;
}
}
}
what's wrong with this ? I don't see any result.
Thanks
That code is correct, but as you have manually set $option to the value of option, it is not 1 so the code in the case 1 statement does not run.
You should place the break; outside of the if statement though in case you add more options.
You can also add a default option at the end:
switch($option)
{
case 1:
if(isset($_POST['submit']))
{
$count =str_word_count($_POST['textarea']);
echo $count;
}
break;
default:
echo "Option is: " . $option;
}
By the way, if I understand you correctly, you probably want:
$option = $_POST['valoare'];
instead of:
$option = "option";
$option = "option";
switch($option)
{
case 1:
how can you switch option if option is already defined? if you define $option="option" $option will never be 1.

Categories