Session variables in PHP not appearing [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 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 "

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.'">';

echo a form and some jquery codes [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 6 years ago.
Improve this question
I would like to post and redirect some values to my path.
I find out the best solution is using a echo form .
but my code does not work :
function goToCodes($method = '' , $tr_ids = '')
{
$path = base_url().'cart/codes';
$jquery = base_url().'assests/new/js/jquery.js';
echo '<form action="'.$path.'" method="post" >';
echo '<input name="method" type="hidden" value="'.$method.'" />';
echo '<input name="tr_ids" type="hidden" value="'.$tr_ids.'" />';
echo '<input id="goToCodeSubmit" type="submit"/>';
echo '</form>';
echo '<script src="'.$jquery.'"></script>';
echo '<script>';
echo '$(function(){
$(#goToCodeSubmit).click();
});';
echo '</script>';
}
in the console I get this error :
SyntaxError: illegal character
You should put quotes around your jQuery selector, $("#goToCodeSubmit").
As a side note, without the quotes around #goToCodeSumit you're attempting to reference an element by the name #goToCodeSumit, which isn't an element in the DOM. Also, the hashtag is probably the thing causing the illegal character error.

how to check textbox with ctype_digit PHP [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 7 years ago.
Improve this question
This is my code, I get variable from textbox but nothing appears.
This code checks if a input is number:
this is a number
or not:
this is not a number
<?php
echo'<form method="post" action="">';
echo '<input type=text name=t/>';
echo'<input type=submit name=su/>';
echo'</form>';
if(isset($_POST['su']))
{
if (ctype_digit($_POST['t'])) {
echo "This is number.\n";
} else {
echo "This is not a number.\n";
}
}
?>
All of code is in one page.
Your code is failing because you have unquoted elements/attributes.
The following require quotes for:
echo '<input type=text name=t/>';
^^^^ ^^^^^^
echo'<input type=submit name=su/>';
^^^^^^ ^^^^^^^
Modify your code to read as:
<?php
echo'<form method="post" action="">';
echo '<input type="text" name="t"/>';
echo'<input type="submit" name="su"/>';
echo'</form>';
if(isset($_POST['su']))
{
if (ctype_digit($_POST['t'])) {
echo "This is number.\n";
} else {
echo "This is not a number.\n";
}
}
?>
Certain web browsers will not accept unquoted elements/attributes and will simply be ignored, such as the current version of Firefox and will fail silently even with error reporting set to catch/display, strangely enough.
You can test for a number using the JS function isNAN. PHP processes on the server so once the page is loaded it is not available. Javascript is available though after the page loads. JS is client side and is executed on the browser. Here's a js solution:
var test = 1;
if(isNaN(test)) {
alert('String');
} else {
alert('number');
}
This would alert number.
Here's a longer write up on that JS function, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN.
If method is not defined in <form> then the default is GET. So
<form>
is the same as
<form method="GET">
If you want to use $_POST, you need to do
<form method="POST">

PHP Function name needs to be a string [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'm trying to make an incredibly basic php form that outputs some text a user puts in to a database. Looked at a couple other questions like this to make sure and from what I can tell no one else asked about this. Here's the create.php that takes input from the html.
<?php
include 'connection.php';
$firstname= $_POST('inputName');
$lastname= $_POST('inputName2');
if($_POST ['SUBMIT']) { echo "please fill out the form";
header('location: ../index.html');
} else {
mysql_query("INSERT INTO requestdata ('firstname', 'lastname')
VALUES ('$firstname', '$lastname')") or die(mysql_error());
echo "User has been added"; header ('Location: ../index.html');
}
?>
Here's the html code for the form:
<form action = "php/create.php" method = "POST">
First Name <input type ="text" name='inputName' value=""/>
Last Name <input type="text" name='inputName2' value=""/>
<br />
<input type="submit" name = "button">
</form>`
and the error I'm getting is:
"Fatal error: Function name must be a string in
mywebsite.com/php/create.php on line 8
I think your $_POST variables are wrong.
Please try $_POST['inputName'] instead of $_POST('inputName') and $_POST['inputName2'] instead of $_POST('inputName2')

Php variable not showing up? [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
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{
?>

Categories