I'm making a script like hotornot.com where you rate things. Only problem is that instead of inserting the rating values onto the specific picture its inserting new rows. I'm a complete noob at php and most of this script besides the rating part was written by a friend of mine. If anyone could please explain how I could get the ratings to go into the specific row I would apprciate it.
PHP Code:<html>
<head>
</title></title>
</head>
<body>
<form name="image" method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">
<select name="Gender" onchange="image.submit()">
<option value="male">Men
<option value="female">Women
</select>
<select name="Age" onchange="image.submit()">
<option value="1">18-25
<option value="2">26-32
<option value="3">33-40
<option value="4">Above 40
</select>
<select name="type" onchange="image.submit()">
<option value="***">***
<option Value="boobs">Boobs
</select>
</form>
<?php
$db = mysql_connect("localhost", "","") or die(mysql_error());
mysql_select_db("dugreg_assntitties",$db) or die(mysql_error());
$query = "select * from pictures order by rand() limit 1";
$sql = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($sql);
?>
<img src="/images/<?=$row["filename"]?>"><br>
<form name="rating" method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">
<input type="radio" name="rate" value="1" onchange="rating.submit()"> 1
<input type="radio" name="rate" value="2" onchange="rating.submit()"> 2
<input type="radio" name="rate" value="3" onchange="rating.submit()"> 3
<input type="radio" name="rate" value="4" onchange="rating.submit()"> 4
<input type="radio" name="rate" value="5" onchange="rating.submit()"> 5
<input type="radio" name="rate" value="6" onchange="rating.submit()"> 6
<input type="radio" name="rate" value="7" onchange="rating.submit()"> 7
<input type="radio" name="rate" value="8" onchange="rating.submit()"> 8
<input type="radio" name="rate" value="1" onchange="rating.submit()"> 9
<input type="radio" name="rate" value="10" onchange="rating.submit()"> 10
</form>
<?
$query2 = "select * from pictures where filename = '" . $row['filename'] . "' and votes = '$votes' and total = '$total' and avg = '$avg'";
$sql = mysql_query($query2) or die(mysql_error());
$row = mysql_fetch_assoc($sql);
print $row["id"];
print $row["votes"];
print $row["total"];
print $row["avg"];
$newvotes = $votes + 1;
$newtotal = $total + $rate;
$newavg = ($newtotal) / ($newvotes);
$row["filename"] = $filename;
$query3 = "INSERT INTO `pictures` (filename,votes,total,avg) VALUES ('$filename','$newvotes','$newtotal','$newavg')";
$sql = mysql_query($query3) or die(mysql_error());
?>
</body>
</html>






Bookmarks