Problem sa skriptom za glasanje

Problem sa skriptom za glasanje

offline
  • Pridružio: 08 Nov 2007
  • Poruke: 12
  • Gde živiš: Brcko, BiH

Moze li neko da mi pomogne oko ove skripte. Kada kliknem na dugme glasaj ne prikazuje mi nikakav sadrzaj na php stranici gdje bi trebali biti rezultati.

Napravio sam bazu i u njoj dodato tabelu

create table poll_results (
pitanja varchar(30),
num_votes int
);
insert into poll_results values
('Los', 0),
('Dobar', 0),
('Moze bolje', 0),
('Extra', 0)
;

zatim i formu:

<form method="post" action="glasanje.php"> <input type="radio" name="vote" value="Los">Los<br /> <input type="radio" name="vote" value="Dobar">Dobar<br /> <input type="radio" name="vote" value="Moze bolje">Moze bolje<br /> <input type="radio" name="vote" value="Extra">Extra<br /> <div style="text-align:center"><input type="submit" value="Glasaj"></div></form>

i na kraju skriptu

<?php /*********************************************************************** Skripta glasanja. ************************************************************************/ $vote=$_REQUEST['vote']; if (!@$db_conn = new mysql('localhost', 'database', 'user', 'pass'))    {       echo 'Error:Ne moze da se uspostavi veza sa bazom podataka!<br />';       exit;    }; if (!empty($vote))    {       $vote = addslashes($vote);       $query = "update poll_results       set num_votes = num_votes + 1       where pitanja = '$vote'";       if(!($result = @ $db_conn -> query($query)))          {             echo 'Ne moze da se uspostavi veza sa bazom podataka!<br />';             exit;          }    }    $query = 'select * from poll_results';    if(!($result = @ $db_conn -> query($query)))       {          echo 'Ne moze da se uspostavi veza sa bazom podataka!<br />';          exit;       }       $num_pitanja = $result -> num_rows;              $total_votes = 0;       while ($row = $result -> fetch_object ())       {          $total_votes += $row -> num_votes;       }       $result -> data_seek (0);        putenv('GDFONTPATH=C:/WINDOWS/FONTS'); $width=500; $left_margin=50; $right_margin=50; $bar_height=40; $bar_spacing=$bar_height/2; $font='arial'; $title_size=16; $main_size=12; $small_size=12; $text_indent=10; $x = $left_margin + 60; $y = 50; $bar_unit = ($width - ($x+$right_margin)) / 100; $height = $num_pitanja * (bar_height + bar_spacing) + 50; $im = ImageCreateTrueColor ($width,$height); $white=ImageColorAllocate($im, 255,255,255); $black=ImageColorAllocate($im, 0,0,0); $red=ImageColorAllocate($im, 255,0,0); $gray=ImageColorAllocate($im, 153,153,153); $text_color=$white; $percent_color=$white; $bg_color=$black; $line_color=$gray; $bar_color=$red; $number_color=$white; ImageFilledRectangle ($im,0,0,$width,$height,$bg_color); ImageRectangle ($im,0,0,$width-1,$height-1,$line_color); $title = 'Rezultati glasanja'; $title_dimensions = ImageTTFBBox($title_size,0,$font,$title); $title_length = $title_dimensions[2] - $title_dimensions[0]; $title_height = abs($title_dimensions[7] - $title_dimensions[1]); $title_above_line = abs($title_dimensions[7]); $title_x = ($width-$title_length)/2; $title_y = ($y - $title_height)/2 + $title_above-line; ImageTTFText($im, $title_size, 0, $title_x, $title_y, $text_color, $font, $title); ImageLine($im, $x, $y-5, $x, $height-15, $line_color); while ($row = $result -> fetch_object ()) {    if ($total_votes > 0)       $percent = intval(($row -> num_votes/$total_votes)*100);    else       $percent = 0; $percent_dimensions = ImageTTFBBox($main_size, 0, $font, $percent.'%'); $percent_length = $percent_dimensions[2] - $percent_dimensions[0]; ImageTTFText($im, $main_size, 0, $width-$percent_length-$text_indent, $y+($bar_height/2), $percent_color, $font, $percent.'%'); $bar_length = $x + ($percent * $bar_unit); ImageFilledRectangle($im, $x, $y-2, $bar_length, $y+$bar_height, $bar_color); ImageTTFText($im, $main_size, 0, $text_indent, $y+($bar_height/2), $text_color, $font, "$row -> pitanja"); ImageRectangle($im, $bar_length+1, $y-2, ($x+(100*$bar_unit)), $y+$bar_height, $line_color); ImageTTFText($im, $small_size, 0, $x+(100*$bar_unit)-50, $y+($bar_height/2), $number_color, $font, $row ->num_votes.'/'.$total_votes); $y=$y+($bar_height+$bar_spacing); } Header('Content-type: image/png'); ImagePng($im); ImageDestroy($im); ?>



Registruj se da bi učestvovao u diskusiji. Registrovanim korisnicima se NE prikazuju reklame unutar poruka.
offline
  • PHP developer
  • Pridružio: 22 Mar 2006
  • Poruke: 3675
  • Gde živiš: 127.0.0.1

Jel ovo ne radi na localhostu ili na serveru? Mislim, na serveru NEMA SANSE da radi, nego jel ti bar u lokalu radi?

na serveru ne radi zato sto na linux serveru, tesko ces da nadjes

putenv('GDFONTPATH=C:/WINDOWS/FONTS');

folder, a ako je windows server (u sta sumnjam, ali ajde) opet nema sanse da te pusti u windows folder Smile

a drugo, stavi $_POST umesto $_REQUEST, verovatno nije do toga ali opet, ako nesto radis, radi kako treba Smile



Ko je trenutno na forumu
 

Ukupno su 542 korisnika na forumu :: 13 registrovanih, 2 sakrivenih i 527 gosta   ::   [ Administrator ] [ Supermoderator ] [ Moderator ] :: Detaljnije

Najviše korisnika na forumu ikad bilo je 3466 - dana 01 Jun 2021 17:07

Korisnici koji su trenutno na forumu:
Korisnici trenutno na forumu: _Sale, A.R.Chafee.Jr., Dorcolac, goxin, indja, Konda, MB120mm, mihajlot2013, Miskohd, Mixelotti, Srle993, vasa.93, yrraf