Log in

View Full Version : Voting



alexjewell
11-23-2006, 05:45 PM
My band is currently searching for a name. We put together a list and I threw together a site for people to vote on the name. There are A LOT of errors, and I'm at a loss of what to do. There's three main PHP documents: index.php, inc.php, and send.php. inc.php is included in both the index and send pages. inc.php includes some repeated html that goes around the content, as well as:



ini_set('bug_compat_42' , 'off');
ini_set('session.bug_compat_warn' , 'off');


They get rid of some bugs I have with sessions. There's three other things in inc.php: $top, $intro, and $bottom. There's an if statement later including $intro - which is basically homepage info that I just want to display when they first come to the site.

Now, here's the code for index.php, which will make more sense when you see the code for send.php:



include('inc.php');

session_start();

if(!$_GET['name'] && !$_GET['email']){
$error = "\n";}

else if($_GET['name'] || $_GET['email']){

if($_GET['name']) {
$name = $_GET['name'];
if($name = 1){
$error_name = 'Please put your name';
$name_fill = '';}
else{
$error_name = "\n";
$name_fill = $name;}}
else{
$error_name = '';
$name_fill = '';}

if($_GET['email']) {
$email = $_GET['email'];
if($email = 1) {
$error_email = 'Please put your email address';
$email_fill = '';}
else{
$error_name = "\n";
$email_fill = $email;}}
else{
$error_email = '';
$email_fill = '';}

$error = '
<p class="error">
There\'s been an error:<br />'.$error_name.'<br />'.$error_email.'<br />(Please cast your vote again)
</p>';}
else {$error = "\n";}



if($_GET['suggest']) {
$suggest = $_GET['suggest'];
if($suggest = 1){
$suggest_fill = '';}
else{
$suggest_fill = $suggest;}}
else{
$suggest_fill = '';}



if($_GET['comments']) {
$comments = $_GET['comments'];
if($comments = 1) {
$comments_fill = '';}
else if($comments = "yes") {
if($_SESSION['comments']){
$comments_fill = $_SESSION['comments'];}
else{$comments_fill = '';}}
else{
$comments_fill = '';}}
else{
$comments_fill = '';}


echo $top;

if(!$_GET['name'] && !$_GET['email']) {
echo $intro;}


Then, we have the actual form, and we put in the "fills". For example:



<input type="text" name="name" value="<?=$name_fill ?>" />


Now, here's send.php:



include('inc.php');

if (isset($_POST['name']) && isset($_POST['email'])) {

$name = $_POST['name'];
$email = $_POST['email'];

if (isset($_POST['suggest'])) {
$suggest = $_POST['suggest'];}
else { $suggest = "No Suggestions";}

if (isset($_POST['comments'])) {
$comments = $_POST['comments'];}
else { $comments = "No Comments";}

foreach($_POST['band_name'] as $value) {
$band_names = "Band Name: ".$value."\n";}

$ip = $_SERVER['REMOTE_ADDR'] or "N/A";
$browser= $_SERVER['HTTP_USER_AGENT'] or "N/A";

$subject = "Band Name Vote";
$my_email = "alexjewell@sbcglobal.net";

$vote =
'Name: '.$name."\n\n".
'Email: '.$email."\n\n".
$band_names."\n\n".
'Suggest: '.$suggest."\n\n".
'Comments: '.$comments."\n\n".
'IP: '.$ip."\n".
'Browser: '.$browser."\n\n";

mail ( $my_email , $subject , $message = $vote , "From: $email" );

$thanks = "<p>Thanks for voting. We will post the results when the voting is over.</p>";}


else {

if(!isset($_POST['name'])) {
$name = "&name=1";}
else{
$name = "&name=".$_POST['name'];}

if(!isset($_POST['email'])) {
$email = "&email=1";}
else{
$email = "&email=".$_POST['email'];}

if(!isset($_POST['suggest'])) {
$suggest = "&suggest=1";}
else{
$suggest = "&suggest=".$_POST['suggest'];}

if(!isset($_POST['comments'])) {
$comments = "&comments=1";}
else{
$comments = "&comments=yes";
session_start();
$_SESSION['comments'] = $_POST['comments'];}

$refresh = "http://www.alexjewell.com/index.php?".$name.$email.$suggest.$comments;
header('loaction: $refresh');

$thanks = "/n";}

if($thanks = "<p>Thanks for voting. We will post the results when the voting is over.</p>"){
echo $top.$thanks.$bottom;}
else{
echo $thanks;}


Basically, it gets the info from the form, and goes back to the form if name or email is not filled in. What's going wrong?

It's here: www.alexjewell.com/band (http://www.alexjewell.com/band)

alexjewell
11-23-2006, 05:48 PM
Also, on index.php, there's the form:



<form method="post" action="send.php">
<table cellpadding="1px" cellspacing="4px">
<tr>
<td>
<label for="name">Name:</label>
</td>
<td>
<input type="text" name="name" value="<?=$name_fill ?>" />
</td>
</tr>
<tr>
<td>
<label for="email">Email:</label>
</td>
<td>
<input type="text" name="email" value="<?=$email_fill ?>" />
</td>
</tr>
<tr><td id="space_before_votes" colspan="2"></td></tr>
<tr>
<td>
<label for="band_name">Vote:</label>
</td>
<td id="votes">
<table cellpadding="0px" cellspacing="0px">
<tr>
<td><input type="checkbox" name="band_name" value="A Breath of Daylight" /></td><td id="spc"></td><td>A Breath of Daylight</td>
</tr>
<tr>
<td><input type="checkbox" name="band_name" value="Carpenter" /></td><td id="spc"></td><td>Carpenter</td>
</tr>
<tr>
<td><input type="checkbox" name="band_name" value="Moonlit Mirror" /></td><td id="spc"></td><td>Moonlit Mirror</td>
</tr>
<tr>
<td><input type="checkbox" name="band_name" value="Painted Sundays" /></td><td id="spc"></td><td>Painted Sundays</td>
</tr>
<tr>
<td><input type="checkbox" name="band_name" value="Lollipop kids" /></td><td id="spc"></td><td>Lollipop Kids</td>
</tr>
<tr>
<td><input type="checkbox" name="band_name" value="Lonely Led" /></td><td id="spc"></td><td>Lonely Led</td>
</tr>
<tr>
<td><input type="checkbox" name="band_name" value="The Shadow of Vienna" /></td><td id="spc"></td><td>The Shadow of Vienna</td>
</tr>
<tr>
<td><input type="checkbox" name="band_name" value="Beyond Blue" /></td><td id="spc"></td><td>Beyond Blue</td>
</tr>
<tr>
<td><input type="checkbox" name="band_name" value="Holding Hands" /></td><td id="spc"></td><td>Holding Hands</td>
</tr>
<tr>
<td><input type="checkbox" name="band_name" value="Blue Chalk" /></td><td id="spc"></td><td>Blue Chalk</td>
</tr>
<tr>
<td><input type="checkbox" name="band_name" value="Lost Lines" /></td><td id="spc"></td><td>Lost Lines</td>
</tr>
<tr>
<td><input type="checkbox" name="band_name" value="Reason for Rain" /></td><td id="spc"></td><td>Reason for Rain</td>
</tr>
<tr>
<td><input type="checkbox" name="band_name" value="Along the Spine" /></td><td id="spc"></td><td>Along the Spine</td>
</tr>
<tr>
<td><input type="checkbox" name="band_name" value="Warn the Sky" /></td><td id="spc"></td><td>Warn the Sky</td>
</tr>
<tr>
<td><input type="checkbox" name="band_name" value="Chair" /></td><td id="spc"></td><td>Chair</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<label for="suggest">Suggest:</label>
</td>
<td>
<input type="text" name="suggest" value="<?=$suggest_fill ?>" />
</td>
</tr>
<tr>
<td>
<label for="comments">Comments:</label>
</td>
<td>
<textarea name="comments" rows="5" cols="25"><?=$comments_fill ?></textarea>
</td>
</tr>
<tr><td id="space_before_submit"></td></tr>
<tr>
<td colspan="2">
<input type="submit" value="Vote!" class="submit" onClick="return checkmail(this.form.email)" />
</td>
</tr>
</table>
</form>


Then, the bottom of index.php just echo's $bottom, which is in inc.php

thetestingsite
11-27-2006, 08:17 PM
You said that you recieved a lot of errors, what are the errors that you recieve?

djr33
11-27-2006, 09:05 PM
That's a lot of code for someone to just "fix". Specify the errors, and what part of the code they're coming from, so it's not quite so daunting a task to help.

GhettoT
11-27-2006, 09:09 PM
I think that if you look at the site you will see the errors.



Notice: Undefined index: name in d:\webspace\ADMIN\alexjewell.com\WWW\band\index.php on line 7

Notice: Undefined index: email in d:\webspace\ADMIN\alexjewell.com\WWW\band\index.php on line 7

Notice: Undefined index: suggest in d:\webspace\ADMIN\alexjewell.com\WWW\band\index.php on line 44

Notice: Undefined index: comments in d:\webspace\ADMIN\alexjewell.com\WWW\band\index.php on line 55
Notice: Undefined index: name in d:\webspace\ADMIN\alexjewell.com\WWW\band\index.php on line 71

Notice: Undefined index: email in d:\webspace\ADMIN\alexjewell.com\WWW\band\index.php on line 71
Plus their is some code showing up in the forms... I have no clue where he screwed up... lol.

djr33
11-27-2006, 09:18 PM
Yeah, there's no question that something went wrong with the transfer to your webhost from your harddrive.
If that's the problem, then not really sure what to suggest, except just fixing the references.
I assumed that you were just giving us an example (though with some errors, since you didn't change them to fit the new host).
If you want it to work like that, then you'll need to fix all references so they relate to real files on your server.