Jump to content

[SOLVED] Fianl part of my voting system. Not adding to the database


Recommended Posts

Hi all again,

 

Sorry to ask but Ive spent all day on this and i still can't the bloody thing to add the ratings to the database.

 

My page is now pretty complicated and i fear that it may be getting confused. Anyway here goes at an explaination -

 

page - http://www.jungletekno.co.uk/ratings_page_halfway.php

 

script at the top of the page -

 

$var = @$_GET['q'] ;

$trimmed = trim($var);

$user="xxx";

$pass="xxx";

$host = "xxx";

$dbase="xxx";

$table = "Mixes";

mysql_connect($host,$user,$pass);

if ( $mode=="vote")

{

$cookie = "jungletekno$id";

if(isset($_COOKIE[$cookie]))

{

Echo "Sorry You have already voted for that mix <p>";

}

else

{

$month = 2592000 + time();

setcookie(Mysite.$id, Voted, $month);

}

$votes = $_POST['votes'];

$mix = $_POST['m'];

$query = "UPDATE Mixes SET total_votes = total_votes + '$votes', total_voted = total_voted + '1' WHERE id = $id";

@mysql_select_db($dbase) or die("Unable to select database");

$result=mysql_query($query);

}

$query = "SELECT * FROM Mixes WHERE dj LIKE '%$var%' OR rave LIKE '%$var%' OR tracklist LIKE '%$var%' OR date LIKE '%$var%' ORDER BY rave ASC";

@mysql_select_db($dbase) or die("Unable to select database");

$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

?>

 

 

form for the rating -

 

<form method="POST" action="<? echo $_SERVER['PHP_SELF'] ?>?mode=vote&m=<? echo $id ?>">

 

<p><select name="votes">

<option value="">Choose a Rating</option>

<option value="5">I Love It!</option>

<option value="4">Good</option>

<option value="3">Moderate</option>

<option value="2">Not Bad</option>

<option value="1">Poor</option>

</select><br />

<input type="submit" name="v_submit" value=" Rate It! " /></p>

</form>

 

 

Is the problem that I have 2 queries at the top of the page or is it that i have the syntax wrong where some commands should og later in the document? Everything works fine apart from the addition of ratings to the database.

 

Any help would be great.

I'm not sure if it is valid to put the 1 in single quotes.

 

Try changing the following:

$query = "UPDATE Mixes SET total_votes = total_votes + '$votes', total_voted = total_voted + '1' WHERE id = $id";

 

to this:

 

$query = "UPDATE Mixes SET total_votes = total_votes + ".$votes.", total_voted = total_voted + 1 WHERE id = '$id'";

 

Your also missing the single quotes around $id.

 

-Kalivos

Having stripped down the whole lot ot the bear bones I've final found what i hope is the root of my problems -

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' total_voted = total_voted + '1' WHERE id = ''' at line 1

 

I have changed the syntax to every possible permutation and it still has issues. He's the code (m=104 is a know file that I'm trying to use the code to increase through the ratings) -

 

<?

$user = "xxxx";

$pass = "xxxx";

$host = "xxxx";

$dbase = "xxxx";

$table = "Mixes";

mysql_connect($host,$user,$pass);

$votes = $_POST['votes'];

$mix = $_POST['m'];

$new_total_voted = (total_voted + 1);

$new_total_votes = (total_votes + $votes);

$query = "UPDATE Mixes SET total_votes = $new_total_votes , total_voted = $new_total_voted WHERE id = $mix";

@mysql_select_db($dbase) or die("Unable to select database");

$result = mysql_query($query) or die(mysql_error());

mysql_close();

 

?>

<form method="post" action="<? echo $_SERVER['PHP_SELF']; ?>?m=104">

<p><select name="votes">

<option value="">Choose a Rating</option>

<option value="1">Poor</option>

<option value="2">Not Bad</option>

<option value="3">Moderate</option>

<option value="4">Good</option>

<option value="5">I Love It!</option>

</select><br />

<input type="submit" name="v_submit" value=" Rate It! " /></p>

</form>

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.