/    Sign up×
Community /Pin to ProfileBookmark

Hey everyone. I was working at a members section where the member could vote. Once I combined my script along with the voting script the page wouldn’t show anything – just whitespace. ๐Ÿ˜ฎ

I was wondering if some of the php experts help me out! ?

Thanks,

Chris

Script:

<?php

session_register(“Email”);

if (!isset($_SESSION[‘Email’]))
{
// User not logged in, redirect to login page
Header(“Location: payments.html”);
}

//Variables for connection
$dbhost = “localhost”;
$dbname = “na032339”;
$dbuser = “na032339”;
$dbpass = “na032339”;

//Connect to database
$link_id = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname);

//Select statements
$sql = “SELECT `Title`,`Question`,`ID` FROM `poll_data` ORDER BY `ID` DESC LIMIT 1″;
if(!($result = mysql_query($sql))) die(mysql_error());
$PollData = mysql_fetch_array($result);

$sql = “SELECT `Option1`,`Option2`,`Option3`,`Votes` FROM `poll_data` WHERE `ID` = ‘” . $PollData[‘ID’] . “‘ ORDER BY `ID` DESC LIMIT 1″;
if(!($result = mysql_query($sql))) die(mysql_error());
if(!($VoteData = mysql_fetch_array($result))) die(mysql_error());

//Get percent
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 .”%”;
}

// Display Member information
echo “<p>Currently logged in as: ” . $_SESSION[“Email”];

// Display logout link
echo “<p>Not you?<a href=”logout.php”> Logout!</a></p>”;

?>

<html>
<head>
<title>Memembers Section</title>
</head>
<body>
<form method=”POST” action=”vote.php”>
<table width=”500″ border=”1″ cellspacing=”0″ cellpadding=”8″>
<tr>
<td colspan=”3″><b><?=$PollData[‘Title’]?> – <?=$PollData[‘Question’]?></b></td>
</tr>
<tr>
<td width=”35%”>
<input type=”radio” name=”Vote” value=”Option1″>
Yes</td>
<td width=60%>
<img src=”bar.gif” width=”<?=$VotePercent1?>” height=”20″>
</td>
<td><?=$VoteData[“Option1”]?> Votes</td>
</tr>
<tr>
<td width=”35%”>
<input type=”radio” name=”Vote” value=”Option2″>
No </td>
<td width=60%>
<img src=”bar.gif” width=”<?=$VotePercent2?>” height=”20″>
</td>
<td><?=$VoteData[“Option2”]?> Votes</td>
</tr>
<tr>
<td width=”35%”>
<input type=”radio” name=”Vote” value=”Option3″ >
Not Sure</td>
<td width=”60%”>
<img src=”bar.gif” width=”<?=$VotePercent3?>” height=”20″>
</td>
<td><?=$VoteData[“Option3”]?> Votes</td>
</tr>
<tr>
<td colspan=”3″>
<center>
<input type=”submit” name=”Submit” value=”Vote”>
</center>
</td>
</tr>
</table>
</form>
</body>
</html>

to post a comment
PHP

11 Comments(s) โ†ด

Copy linkTweet thisAlerts:
@NogDogMay 26.2005 โ€”ย One thing that stands out is that this...
[code=php]
// Display Member information
echo "<p>Currently logged in as: " . $_SESSION["Email"];

// Display logout link
echo "<p>Not you?<a href="logout.php"> Logout!</a></p>";
[/code]

...does not close the first <p> tag, and it comes before your opening <html> and <body> tags.
Copy linkTweet thisAlerts:
@doyle_loaderauthorMay 26.2005 โ€”ย Hey

I changed it to

// Display Member information

echo "<p>Currently logged in as: " . $_SESSION["Email"] . "</p>";

But still get the same result.

Cheers,

Chris
Copy linkTweet thisAlerts:
@Stephen_PhilbinMay 26.2005 โ€”ย What about the actual source it kicks out? Does it throw any source code out that the browser just doesn't render? Or is the script not outputting any markup at all to the browser?
Copy linkTweet thisAlerts:
@doyle_loaderauthorMay 26.2005 โ€”ย Hey

(I think I understand what your saying, but if I missed the boat let me know! :rolleyes: )

When the page loads it appears that there is no markup at all. It is possible that I messed up and none of the source even displays at all... I just can't find the error.

Thanks,

Chris
Copy linkTweet thisAlerts:
@ScleppelMay 26.2005 โ€”ย You never start the session so you can't use anything saved in the users session.

You didn't exit(); after the header, this could cause an error (although i don't think it's this).

Your header has to be a full url for it to be properly redirected.
[CODE]
<?php
session_start();

if(!isset($_SESSION['Email']))
{
header("Location: http://your_domain.tld/payments.html");
exit();
}
[/CODE]

I think whats happening is that it's got no session data, so is redirecting but hasn't got a proper url to go to, so outputs nothing.

PS. You don't need session_register();.
Copy linkTweet thisAlerts:
@doyle_loaderauthorMay 26.2005 โ€”ย The session data comes from the previous page. I know it did work fine cause I had it working so that it displayed the logged in user and the option to log out. When I put in the voting scripts and the html I began getting these problems. ?

If it's still wrong let me know!! haha

Cheers,

Chris
Copy linkTweet thisAlerts:
@floydiologyMay 27.2005 โ€”ย You need to echo out your code. look for this stuff:


[COLOR=DarkOrange]?=$PollData['Title']?> - <?=$PollData['Question']?>[/COLOR]

should read[COLOR=DarkGreen]<? echo $pollData['Question']; ?>[/COLOR] aqnd so forth through the vote block of code.
Copy linkTweet thisAlerts:
@doyle_loaderauthorMay 27.2005 โ€”ย Ok.I will try that later and let you know if it works

Thanks

Chris
Copy linkTweet thisAlerts:
@ScleppelMay 27.2005 โ€”ย Did you try putting my codat the top instead? You HAVE to have session_start(); at the begining of your script or you cannot access session data, even if it is from the previous page!

"<?=" is shorthand for "<? echo", but you should probably put ;s after the closing ]s. Eg.
[CODE]
<?=$PollData['Question'][COLOR=Red];[/COLOR]?>
[/CODE]
Copy linkTweet thisAlerts:
@doyle_loaderauthorMay 27.2005 โ€”ย Hey,

I didn't try session_start() because before the code began to go blank it was passing the email variable fine. I had it so it would display "You are logged in as: " + the email and when I would log in, it would display "You are logged in as: [email][email protected][/email]" for example. So that use to work fine.

I am going to first try echoing out my code like floydiology mentioned. If I can't get the session to work then I will try adding session_start()

Cheers,

Chrs
Copy linkTweet thisAlerts:
@doyle_loaderauthorMay 27.2005 โ€”ย I tried putting ;'s in but still no difference.

Nice guess though! haha I thought that was it when I seen it!
[CODE]<?=$PollData['Question'];?>[/CODE]

Thanks,

Chris
ร—

Success!

Help @doyle_loader spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 โ€” BETA 5.20,
whats_new: community page,
up_next: more Davinciโ€ข003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinciโ€ข003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...