Hi there trying to do srcipt like Vote
So Row bitwa_glosy are setted to 0
and when i press button post method should incrase value from 0 to 1. and should grown up everytime i pressed the button.
Reading the value from DB
$Query="SELECT * FROM tentego_img WHERE id='$aid'";
$QueryResult=mysql_query($Query);
while($Kol_a=mysql_fetch_array($QueryResult)){
$a_glos =$Kol_a['bitwa_glosy']; // Values= 0
Now im know that value from bitwa_glosy are 0
and trying to incrase
if(isset($_POST['glos_a']))
{
$plus = 1;
$a_glos = $a_glos+$plus;
$dodaj_glos_a = "UPDATE `tentego_img` SET `bitwa_glosy` = $plus WHERE `id`=$aid";
$idzapytania = mysql_query($dodaj_glos_a);
}
But it does not work and i dont know why
Theres the Post Form
<form method="post"><input type="submit" name="glos_a" value="Głosuj +"/></form>
***EDITED FINALL CODE from your sugestions and answers And still does not work, i give up with them Thanks everybody trying to help me
cheeers
Thanks everybody for attention, i give up with them, code sometimes works and sometimes not, and tried all things from answers.
theres code btw some modified with your suggestions but still does not work
Cheers!!
<!-- Begin Block -->
<?php
$ilosc= 1;
$typ= 'img';
#Lewa
$Query="SELECT * FROM tentego_img WHERE type='img' ORDER BY RAND() LIMIT ".$ilosc;
$QueryResult=mysql_query($Query);
while($Kol=mysql_fetch_array($QueryResult)){
$atytul =$Kol['title'];
$asrc =$Kol['src'];
$aid =$Kol['id'];
}
#Prawa
$QueryResult=mysql_query($Query);
while($Kol1=mysql_fetch_array($QueryResult)){
$btytul =$Kol1['title'];
$bsrc =$Kol1['src'];
$bid =$Kol1['id'];
}
echo '<table border="0"><tr>';
echo '<td><span style="color:green">#1#</span> '.$atytul.'</td><td></td><td><span style="color:red">#2#</span> '.$btytul.'</td><tr>';
echo '<td><a href="/img/'.$aid.'/'.$atytul.'/"><img src="/upload/'.$asrc.'" alt="'.$atytul.'" title="'.$atytul.'" width="370px" height="370px" /></a>Liczba głósów:0<form method="post"><input type="submit" name="glos_a" value="Głosuj +"/></form></td><td><img src="./_themes/fajna/bitwa/vs.png" /></td>';
echo '<td><a href="/img/'.$bid.'/'.$btytul.'/"><img src="/upload/'.$bsrc.'" alt="'.$btytul.'" title="'.$btytul.'" width="370px" height="370px" /></a>Liczba głosów:0<form method="post"><input type="submit" name="glos_b" value="Głosuj +"/></form></td>';
echo '</tr></table>';
$plus = 1;
if(isset($_POST['glos_a']))
{
$a_glos = $a_glos+$plus;
$dodaj_glos_a = "UPDATE `tentego_img` SET `bitwa_glosy` = `bitwa_glosy` + $plus WHERE `id`=$aid";
$idzapytania = mysql_query($dodaj_glos_a);
}
if(isset($_POST['glos_b']))
{
$dodaj_glos_b = "UPDATE `tentego_img` SET `bitwa_glosy` = `bitwa_glosy` + $plus WHERE `id`=$bid";
$idzapytania2 = mysql_query($dodaj_glos_b);
}
?>
</div>
<!-- End Block -->
bitwa_glosy=bitwa_glosy+1 is a more simple way to do it.$plus = 1and then you update the record and set the bitwa_glossy value to the value of$pluswhich is 1. Instead you should be setting it to$a_glosusing your current code.$a_glosis an anti-pattern, and should be avoided, if the intent is to "increment the current value by one". There is no need to retrieve the column value in a separate statement. Much better to reference the CURRENT value in the column IN THE SAME STATEMENT that updates the column.To further what @phpisuber01 said, not only is there a "more simple" way to do this, but that way is much better as well.