Lynk Posted July 30, 2006 Share Posted July 30, 2006 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 :Dhttp://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> Link to comment https://forums.phpfreaks.com/topic/16054-song-updateinsert/ Share on other sites More sharing options...
DocSeuss Posted July 30, 2006 Share Posted July 30, 2006 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. Link to comment https://forums.phpfreaks.com/topic/16054-song-updateinsert/#findComment-66136 Share on other sites More sharing options...
Lynk Posted July 30, 2006 Author Share Posted July 30, 2006 [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 Link to comment https://forums.phpfreaks.com/topic/16054-song-updateinsert/#findComment-66138 Share on other sites More sharing options...
DocSeuss Posted July 30, 2006 Share Posted July 30, 2006 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 Link to comment https://forums.phpfreaks.com/topic/16054-song-updateinsert/#findComment-66143 Share on other sites More sharing options...
Lynk Posted July 30, 2006 Author Share Posted July 30, 2006 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... ::) Link to comment https://forums.phpfreaks.com/topic/16054-song-updateinsert/#findComment-66145 Share on other sites More sharing options...
Lynk Posted July 30, 2006 Author Share Posted July 30, 2006 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 Link to comment https://forums.phpfreaks.com/topic/16054-song-updateinsert/#findComment-66164 Share on other sites More sharing options...
Lynk Posted July 31, 2006 Author Share Posted July 31, 2006 yeey, i got it working, you can remove this topic so :P ;D ;D ;D ;D Link to comment https://forums.phpfreaks.com/topic/16054-song-updateinsert/#findComment-66180 Share on other sites More sharing options...
Recommended Posts