Jump to content

Archived

This topic is now archived and is closed to further replies.

Lynk

Song Update/Insert

Recommended Posts

ok, here the deal, i want users to rate the current song playing, so, if the song isnt in the database it wil be created, however, i want it to update that same song if it is voted again...but i cant get it to update  :'( ...some help would be REALLY appreciated...thanks :D

http://lynkonline.atlas2wielers.nl/index.temp.php

<?
/* $song[0] is connected to my winamp. it shows the current song playing! */
?>

<? if(isset($_POST['form'])){?>

<?php function lynkfm_rate(){$select_data = "SELECT * FROM lynk_fm WHERE song='$song[0]' LIMIT 1";
$object = mysql_query($select_data) or die($MySQLError.mysql_error()); return $object; } $res99 = lynkfm_rate();
$show = mysql_fetch_object($res99); $new_score = $show->score + $score2 ; $new_vote = $show->votes + 1 ; ?>

<? if( $show->song = "$song[0]") {mysql_query("UPDATE lynk_fm SET score='$new_score', votes='$new_vote' ");
echo"new score: $show->score"; }
elseif ($show->song != "$song[0]") {mysql_query("INSERT INTO lynk_fm (id,date,artist,title,song,score,votes) VALUES ('', '$date_now', '".htmlspecialchars($artist)."', '".htmlspecialchars($title)."', '".htmlspecialchars($song[0])."', '$score2', '$votes') ") or die(mysql_error()); echo"$show->title"; }
else{echo "UPDATE DIDNT WORK! !!";}?>

<? } ?>
<form method="post"  name="lynk_fm" action="<?=$PHP_SELF?>">
<input type="hidden" name="form" value="1">
<select name="score2">
  <option disabled>Rate</option>
  <option value="10">10</option>
  <option value="9">9</option>
  <option value="8">8</option>
  <option value="7">7</option>
  <option value="6">6</option>
  <option value="5">5</option>
  <option value="4">4</option>
  <option value="3">3</option>
  <option value="2">2</option>
  <option value="1">1</option>
</select> <input name="Submit" type="submit" class="I_send" value="Go >" />
Rate this song!</form>

Share this post


Link to post
Share on other sites
The correct syntax for checking if values are equal in an if statment is  == 
if($value1 == $value2)
But that is going to make your update code run every time.

Also I'm not sure how your $song[0] is connected to the current song if there is a problem here then you will never actually find a match in the database to update.

Share this post


Link to post
Share on other sites
[quote author=DocSeuss link=topic=102373.msg406207#msg406207 date=1154298714]
The correct syntax for checking if values are equal in an if statment is   ==  
if($value1 == $value2)
But that is going to make your update code run every time.

Also I'm not sure how your $song[0] is connected to the current song if there is a problem here then you will never actually find a match in the database to update.
[/quote] thanks for your reply :D the $song[0] request the current song on winamp, i have a code that wil print the current song, you can see it working here: http://lynkonline.atlas2wielers.nl/sc_song/now.php

Share this post


Link to post
Share on other sites
I would set the mysql_query to a varible so it has a place to return any results.

$myquery = mysql_query(UPDATE ........);

then you can test $myquery for a true or false state 

also put the or die statement with the mysql error for more clues

Share this post


Link to post
Share on other sites
ill check it out thanks fot the tips. can you find anything obviously wrong with the code?

i know its probably something very silly, but i just cant find out what it is...  ::)

Share this post


Link to post
Share on other sites
nah, nothing, not i get this error when i update...

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 'WHERE artist='Busta Rhymes' AND title='Touch It (Remix part III)' SET score='10'' at line 1

Share this post


Link to post
Share on other sites
yeey, i got it working, you can remove this topic so :P  ;D ;D ;D ;D

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×

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.