PHP Msqli help

Please tell me why this wont work,
[php]
mysql_connect(“blank”, “blank”, “blank”) or die(mysql_error());
mysql_select_db(“blank”) or die(mysql_error());

//Name of our cookie
$cookie = “Voted”;

function pie() {
$data = mysql_query(“SELECT * FROM poll”) or die(mysql_error());
$result = mysql_fetch_array( $data );
$total = $result[contractor] + $result[myself] + $result[third];
$total = $result[contractor] + $result[myself] + $result[third];
$one = round (360 * $result[contractor] / $total);
$two = round (360 * $result[myself] / $total);
$per1 = round ($result[contreactor] / $total * 100);
$per2 = round ($result[myself] / $total * 100);
$per3 = round ($result[third] / $total * 100);
echo “<img src=vote_pie.php?one=”.$one."&two=".$two.">
";
echo “FIRST = $result[contractor] votes, $per1 %

SECOND = $result[myself] votes, $per2 %

THIRD = $result[third] votes, $per3 %
”;
}
//This runs if it is in voted mode
if ( $mode==“voted”) {
//makes sure they haven’t already voted
if(isset($_COOKIE[$cookie])) {
echo “Sorry You have already voted this month
”;
} else {
//sets a cookie
$month = 2592000 + time();
setcookie(Voted, Voted, $month);

	 // adds their vote to the database

switch ($vote) {
case 1:
mysqli_query($con,“UPDATE poll SET contractor = contractor+1”);
break;
case 2:
mysqli_query($con,“UPDATE poll SET myself = myself+1”);
break;
case 3:
mysqli_query($con,“UPDATE poll SET third = ignore+1”);
}
//displays the poll results
pie ();
}
}
//if they are not voting, this displays the results if they have already voted
if(isset($_COOKIE[$cookie])) {
pie ();
} else {

// or if they have not voted yet, they get the voting box
if(!$mode==‘voted’) {
?>

" method = "GET"> contractor myself ignore <? } } ?>[/php] any help greatly appreciated

Well, one thing I do see is this

echo “<img src=vote_pie.php?one=”.$one."&two=".$two.">

It looks like you’re trying to setup a link from within an image, which can’t be done. It would need to be something like

echo “<a href=‘vote_pie.php?one=$one&two=$two’”>

You’re using mysqli and MySQL - need to pick one.

Hard to tell exactly what’s wrong, where is $vote coming from and I don’t see where $mode is defined.

I’ll chime in a smidgen:

Instead of this [php]" method = "GET"> [/php]

do this [php]" method = "post"> [/php]

Oh before anyone says, but I want to use it for more than one page:
[php] echo ‘’;[/php] —> I used this in a broader php script.

There is no need to use $_SERVER and I don’t know why there are so many bad tutorials out there that do that. (I admit I was suckered into doing that when I first start learning PHP) Besides, it not like the file is going to change its name overnight. :smiley:

If I where you, I would throw this script into File 13 and start from scratch, plus I would visit php.net manual for some help on mysqli.

Sponsor our Newsletter | Privacy Policy | Terms of Service