Reply
Simple problem...
Old 11-11-2004, 07:08 PM Simple problem...
Junior Talker

Posts: 1
I keep getting the error:

Code:
Notice: Undefined index: sending in /home/r0106985/public_html/duct-central/winawallet.php on line 8
When all my code says is:

Code:
<?php
	$title = "Win A Wallet";
	include("header.php");
	include("mainfuncs.php");
?>

<?php
	$sending = $_POST['sending'];
	if($sending == 1){
                             SOME RANDOM CODE
	}
	frame(1, 'winawallet');
?>


</body>
</html>
The problem I guess comes because sometimes $sending is passed from a form to this script and sometimes another script doesn't send that variable. How do I make it so that it won't complain if the variable doesn't exist?
expectthis is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 11-11-2004, 07:37 PM
Gaffer Sports's Avatar
Ultra Talker

Posts: 397
Name: Steve
Location: Scotland
Try this:

Code:
<?php
	$title = "Win A Wallet";
	include("header.php");
	include("mainfuncs.php");
?>

<?php
                if(empty($sending))
                {
                 $sending == 0;
                }
	$sending = $_POST['sending'];
	if($sending == 1){
                             SOME RANDOM CODE
	}
	frame(1, 'winawallet');
?>


</body>
</html>
Steve.
__________________
Media Help & Discussion
Gaffer Sports is offline
Reply With Quote
View Public Profile Visit Gaffer Sports's homepage!
 
Old 11-11-2004, 10:05 PM
foobar's Avatar
Extreme Talker

Posts: 225
Or just simplify the whole thing ...

PHP Code:
if((!empty($_POST['sending'])) && ($_POST['sending']==1))
{
   
WHATEVER YOU NEED TO DO;
}

frame(1'winawallet'); 
foobar is offline
Reply With Quote
View Public Profile Visit foobar's homepage!
 
Old 11-11-2004, 10:22 PM
Republikin's Avatar
Super Moderator

Posts: 3,191
I agree with foobar but I want to point this out for the sake of Gaffer...

PHP Code:
if(empty($sending))
                {
                 
$sending == 0;
                }
    
$sending $_POST['sending'];
    if(
$sending == 1){
                             
SOME RANDOM CODE
    
}
    
frame(1'winawallet'); 
Your pretty much working backwords here as you say if $sending is empty then set it to 0 which also equivicates to boolean false. Then you set $sending to equal $_POST['sending'] which this whole thing is bad for two reasons. One you never want to reffer to $sending when $_POST['sending'] is the variable, the use of registered globals will be is being deprecated. Two, you set sending to a boolean value but if $_POST['sending'] is empty it will revert to a string as php automatically casts types. An empty string will throw the same error again.
Republikin is offline
Reply With Quote
View Public Profile
 
Old 11-11-2004, 10:58 PM
Gaffer Sports's Avatar
Ultra Talker

Posts: 397
Name: Steve
Location: Scotland
On understanding your post, I have to disagree.
__________________
Media Help & Discussion
Gaffer Sports is offline
Reply With Quote
View Public Profile Visit Gaffer Sports's homepage!
 
Old 11-11-2004, 11:03 PM
Gaffer Sports's Avatar
Ultra Talker

Posts: 397
Name: Steve
Location: Scotland
If the code I have posted senses a null for $sending, it will not run the final script. It will only run the script if it has an input for $sending.

And if you want to emphasise a problem in my coding or anyone else's, please use paragraphs and sentences, as it is easier to read.

Steve.
__________________
Media Help & Discussion
Gaffer Sports is offline
Reply With Quote
View Public Profile Visit Gaffer Sports's homepage!
 
Old 11-11-2004, 11:09 PM
Republikin's Avatar
Super Moderator

Posts: 3,191
$sending = $_POST['sending'];

That line effectively turns $sending into a string, not null. Null in php is a special value and is not default under any circumstance (at least that I'm aware of).

Setting $sending to 0 is not the same thing as setting $_POST['sending'] to 0. In other words take out that line and the script should run fine.
Republikin is offline
Reply With Quote
View Public Profile
 
Old 11-11-2004, 11:13 PM
Gaffer Sports's Avatar
Ultra Talker

Posts: 397
Name: Steve
Location: Scotland
$sending is taking the 'sending' from the $POST and setting it to zero. If you can understand the post format, any setting will be added to a variable when the script kicks in.
__________________
Media Help & Discussion
Gaffer Sports is offline
Reply With Quote
View Public Profile Visit Gaffer Sports's homepage!
 
Old 11-11-2004, 11:15 PM
Gaffer Sports's Avatar
Ultra Talker

Posts: 397
Name: Steve
Location: Scotland
Basically:

$sending1 = $sending;

Would do the same job as:

$sending = $_POST['sending'];
__________________
Media Help & Discussion
Gaffer Sports is offline
Reply With Quote
View Public Profile Visit Gaffer Sports's homepage!
 
Old 11-11-2004, 11:20 PM
Republikin's Avatar
Super Moderator

Posts: 3,191
And what happens when register globals is turned off? (which it is by default now)

$sending becomes a seperate variable from $_POST['sending']
Republikin is offline
Reply With Quote
View Public Profile
 
Old 11-12-2004, 12:15 AM
Gaffer Sports's Avatar
Ultra Talker

Posts: 397
Name: Steve
Location: Scotland
Do you not understand that a php form that has a post of 'sending' will be accepted as $sending in a php form handler?
__________________
Media Help & Discussion
Gaffer Sports is offline
Reply With Quote
View Public Profile Visit Gaffer Sports's homepage!
 
Old 11-12-2004, 12:17 AM
Gaffer Sports's Avatar
Ultra Talker

Posts: 397
Name: Steve
Location: Scotland
Personally I would re-write this script to my standards, but as I charge a fee, I am sure that would not be accepted.
__________________
Media Help & Discussion
Gaffer Sports is offline
Reply With Quote
View Public Profile Visit Gaffer Sports's homepage!
 
Old 11-12-2004, 12:26 AM
Republikin's Avatar
Super Moderator

Posts: 3,191
Quote:
Originally Posted by Gaffer Sports
Do you not understand that a php form that has a post of 'sending' will be accepted as $sending in a php form handler?
Do you not understand that in order for it to work like that register_globals has to be set on. By default in php it is off as its a sloppy way to code and can open yourself up to security holes.

http://www.php.net/manual/en/security.globals.php
Republikin is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Simple problem...
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.16785 seconds with 12 queries