Jump to content


Photo

Song Update/Insert


  • This topic is locked This topic is locked
6 replies to this topic

#1 Lynk

Lynk
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 30 July 2006 - 10:13 PM

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.at.../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>

#2 DocSeuss

DocSeuss
  • Members
  • PipPipPip
  • Advanced Member
  • 73 posts
  • LocationTexas, USA

Posted 30 July 2006 - 10:31 PM

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.
"Unlimited budget? Great, for $5,000,0000 we will run your ad banner for one year"  ----Rasmus Lerdorf

#3 Lynk

Lynk
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 30 July 2006 - 10:34 PM

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.

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.at...sc_song/now.php

#4 DocSeuss

DocSeuss
  • Members
  • PipPipPip
  • Advanced Member
  • 73 posts
  • LocationTexas, USA

Posted 30 July 2006 - 10:46 PM

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
"Unlimited budget? Great, for $5,000,0000 we will run your ad banner for one year"  ----Rasmus Lerdorf

#5 Lynk

Lynk
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 30 July 2006 - 10:49 PM

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...  ::)

#6 Lynk

Lynk
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 30 July 2006 - 11:34 PM

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

#7 Lynk

Lynk
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 31 July 2006 - 01:39 AM

yeey, i got it working, you can remove this topic so :P  ;D ;D ;D ;D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users