473,395 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Post a variable with value 0

KeredDrahcir
426 256MB
I have a program and I need to post a variable to a page. On the target page I need to test to see if a variable has been posted and redirect the user if it hasn't.
Sometimes the value of the variable needs to be the number zero (0) but when I post it, then it does the redirect. Is there I way I can make it tell the difference between the post zero and a non-posted value.

The value is posted through a standard HTML form and the number crunching is done via PHP.
Expand|Select|Wrap|Line Numbers
  1. if ($_SESSION['value']=="")
  2.   {
  3.     if (!($_POST['value']))
  4.     {
  5. ?>
  6.       <script type="text/javascript">
  7.         location.replace("index.php");
  8.       </script>
  9. <?php
  10.     }
  11.     else
  12.     {
  13.       $id=$_POST['value'];
  14.       $_SESSION['value']=$id;
  15.       $setup=0;
  16.     }
  17.   }
  18.  
Any help would be greatly appreciated.
Sep 1 '13 #1

✓ answered by Rabbit

In PHP, you can use the isset function to see if a variable is set or not.

6 1531
Rabbit
12,516 Expert Mod 8TB
In PHP, you can use the isset function to see if a variable is set or not.
Sep 2 '13 #2
Dormilich
8,658 Expert Mod 8TB
question, why writing a JavaScript redirect (that can be turned off) when you can write a PHP redirect?
Sep 2 '13 #3
KeredDrahcir
426 256MB
I knew that Rabbit. I don't know how I forgot. Thanks. I'll sort that.

I tried that Dormlilch but it didn't work for some reason. Are you able to give me the correct code?
Sep 2 '13 #4
Dormilich
8,658 Expert Mod 8TB
I tried that Dormlilch but it didn't work for some reason.
then what have you tried? what error messages have you got? (note that a PHP redirect does not work after you have printed/echoed something out (and that emits a notice).
Sep 2 '13 #5
KeredDrahcir
426 256MB
Good point. I think I tired it on a different page after I had printed something out and it didn't work. I used the JavaScript one and then probably decided to use that again, but I should be able to use the php one.
Thanks I'll sort that out.
Sep 2 '13 #6
KeredDrahcir
426 256MB
I've just fixed it with isset andit works so much like a charm I just had to thank you. Brilliant Rabbit.
I'll try your suggestion next Dormilich.
Sep 2 '13 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Tom Asken | last post by:
Short version: IE 6.0 wrongly posts <button ..> value. Internet Explorer should only post the value of the clicked submit button - but IE 6 posts the value of several submit buttons if they have...
10
by: John Bailo | last post by:
I want to pass a SqlCommand object as a input parameter to a method. I want to pass the SqlCommand "by value" so that any updates to the original object are *not* reflected in the object within...
4
by: martin1 | last post by:
Hi, All below is the seperate include file called CommonVarValue.aspx <% Dim dcnid as integer dcnid = 67 %> then another aspx file has sqlDataSource section whose selectCommand needs to...
1
by: dvpandya | last post by:
Hi friends thanks in advance i want to check password field value after submiting the form by post method. How can i get that value in html page using javascirpt Example :
3
by: bb nicole | last post by:
Below is my job post code, it cannot post into database... WHAT IS THE PROBLEM OF IT?? <?php session_start(); ob_start(); //connect to server and select database
5
by: Redapple | last post by:
Hello everybody I have a script that looks like this: <?php if (isset($_POST)) { echo "$_POST"; }
3
by: farukcse | last post by:
Hi, Can any one tell me how to assign a php variable value using ajax / javascript? Regards, Faruk Chowdhury
0
by: nwright6 | last post by:
I'm new to ASP and having difficulty integrating the HTTP Post of a name value pair into my ASP page. I'm using inline C# and I'm not clear if I really need to include the Standard ASP Form...
9
xxoulmate
by: xxoulmate | last post by:
how can i include & sign in posting. eg. <a href='home.php?a=hello&world'>hello</a> when i retrieve a its value is just hello., how can i retrieve all value of a which is a = hello&world
3
by: perhapscwk | last post by:
Inside the function Header, I want to display the logo and the variable $this->test , but finally my PDF file can show the logo only. please help. Thanks. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.