register globals, i tried everyting on these forums

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
Cyclonis
-


Joined: 06 Sep 2004
Posts: 4

PostPosted: Mon Sep 06, 2004 1:35 am    Post subject: register globals, i tried everyting on these forums Reply with quote

my script does the weirdest thing... after following all your tips it actually works..in a way...
i turned ON registering globals, i correctly used POST and tried REQUEST when using POST for the form method...
when no action has been registered it will correctly display my normal page, as soon as you hit the submit button it will correctly display the next page content.

so why do i still see the following error on the front page? >.<

Notice: Undefined index: action in D:\Abyss Web Server\htdocs\testing\vote.php on line 11



here is my code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Heers Poll</title>

<?php



$action=$_REQUEST['action'];


$dbhost = "localhost";
$dbname = "mydb";
$dbuser = "******";
$dbpass = "******";

$db = mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname,$db);

$result = mysql_query("SELECT title,question,id FROM poll_data ORDER BY id LIMIT 1",$db);
$PollData = mysql_fetch_array($result);

$result2 = mysql_query("SELECT option1,option2,option3,votes FROM poll_data WHERE id = '" .$PollData['id'] . "' ORDER BY 'id' DESC LIMIT 1",$db);
$VoteData = mysql_fetch_array($result2);



if($VoteData["option1"] != 0) {
$VotePercent1 = Round(($VoteData["option1"]/$VoteData["votes"]) * 100) . "%";
}
else {
$VotePercent1 = 0 . "%";
}

if($VoteData["option2"] != 0) {
$VotePercent2 = Round(($VoteData["option2"]/$VoteData["votes"]) * 100) . "%";
}
else {
$VotePercent2 = 0 . "%";
}

if($VoteData["option3"] != 0) {
$VotePercent3 = Round(($VoteData["option3"]/$VoteData["votes"]) * 100) . "%";
}
else {
$VotePercent3 = 0 . "%";
}



if($action == '') {

$contents= "
<form method='POST' action='vote.php'>
<input type='hidden' value='heers' name='action'>
<table width='500' border='1' cellspacing='0' cellpadding='8' summary='dolf'>
<tr>
<td colspan='3'><b>" . $PollData['title'] . " - " . $PollData['question'] . "</b></td>
</tr>
<tr>
<td width='50'>
<input type='radio' name='Vote' value='option1'>Yes
</td>
<td width='100'>
<img src='bar.gif' width='" . $VotePercent1 . "' height='20' alt='heers'>
</td>
<td>" . $VoteData['option1'] . " Votes (" . $VotePercent1 . ")</td>
</tr>
<tr>
<td width='50'>
<input type='radio' name='Vote' value='option2'>No
</td>
<td width='100'>
<img src='bar.gif' width='" . $VotePercent2 . " ' height='20' alt='heers'>
</td>
<td>" . $VoteData['option2'] . " Votes (" . $VotePercent2 . ")</td>
</tr>
<tr>
<td width='50'>
<input type='radio' name='Vote' value='option3'>Dolf!
</td>
<td width='100'>
<img src='bar.gif' width='" . $VotePercent3 . "' height='20' alt='heers'>
</td>
<td>" . $VoteData['option3'] . " Votes (" . $VotePercent3 . ")</td>
</tr>
<tr>
<td colspan='3'>
<center><input type='submit' name='Submit' value='Vote'></center>
</td>
</tr>
</table>
</form>";



}

elseif($action == "heers"){ $contents = "wow"; }
echo $contents;

?>

</head>
<body>





</body>
</html>
Back to top View user's profile Send private message
roganty
-


Joined: 08 Jun 2004
Posts: 357
Location: Bristol, UK

PostPosted: Mon Sep 06, 2004 12:36 pm    Post subject: Re: register globals, i tried everyting on these forums Reply with quote

Take the following line (line 1 i think):
Code:
$action=$_REQUEST['action'];


and change it to:
Code:
$action= ( isset($_REQUEST['action']) ) ? $_REQUEST['action'] : "";


this creates a neat, 1 line if statement that assigns nothing to the variable if it doesn't exist

Q: why don't you have the contents echo'd between the body tags?
sorry, im just being fussy, as it will display correctly either way
_________________
Anthony R

Roganty
| Links-Links.co.uk
Back to top View user's profile Send private message Visit poster's website
Cyclonis
-


Joined: 06 Sep 2004
Posts: 4

PostPosted: Mon Sep 06, 2004 7:34 pm    Post subject: thanx Reply with quote

hey man thanx for the tip. yesterday i also simply edited my php.ini to display only error messages and no notices! =D
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group