mikwit Posted August 7, 2009 Share Posted August 7, 2009 I've been doing php for a while now, I've just started using jquery/ajax, but this doesn't seem to be a problem with that. I have a nasty problem that I've been trying to trouble shoot for the past couple hours and was wondering if an of you guys could help. The code in question is function getAllVotes($number) { /** Returns an array whose first element is likes and the second one is dislikes **/ $votes = array(); $q = "SELECT * FROM entries WHERE number = $number"; $r = mysql_query($q); if(mysql_num_rows($r)==1)//id found in the table { $row = mysql_fetch_assoc($r); $votes[0] = $row['likes']; $votes[1] = $row['dislikes']; } return $votes; } $number = $_POST['id']; $action = $_POST['action']; if($action=='vote_up') //voting up { $q = "UPDATE wlu_main SET likes = likes+1 WHERE number = $number"; } elseif($action=='vote_down') //voting down { $q = "UPDATE entries SET dislikes = dislikes+1 WHERE number = $number"; } $r = mysql_query($q); if($r) { $votes = getAllVotes($number); //This is the error line echo "Thats Awsome (".$votes[0].") Thats terrible (".$votes[1] .")"; } elseif(!$r) { echo "Failed!"; } The page is an action for a javascript call thingy the error I'm getting is Parse error: syntax error, unexpected T_ECHO ... on Line 39 (marked above). Is there anything I missed? If it helps the javascript used in calling it is echo "<span class='votes' id='votes_count".$row['number']."'> <a href='javascript:;' class='vote_up' id='".$row['number']."'>Thats Awsome</a> ('".$row['likes'].") <a href='javascript:;' class='vote_down' id='".$row['number']."'>Thats terrible </a>(".$row['dislikes'].")</span>"; And the whole thing is suppose to display "Thats awsome (4) Thats terrible (2)" with the number changing the mysql database when its clicked. Thanks Link to comment https://forums.phpfreaks.com/topic/169292-solved-stumped-on-t_echo/ Share on other sites More sharing options...
jamesxg1 Posted August 8, 2009 Share Posted August 8, 2009 Try this, echo '<span class='votes' id='votes_count' .$row['number']. > <a href="javascript:;" class='vote_up' id="' .$row['number']. '">Thats Awsome</a> (' .$row['likes']. ') <a href="javascript:;" class='vote_down' id=' .$row['number']. '>Thats terrible </a>(' .$row['dislikes']. ')</span>'; James. Link to comment https://forums.phpfreaks.com/topic/169292-solved-stumped-on-t_echo/#findComment-893359 Share on other sites More sharing options...
jamesxg1 Posted August 8, 2009 Share Posted August 8, 2009 Sorry, This. echo '<span class="votes" id="votes_count' .$row['number']. '"> <a href="javascript:;" class="vote_up" id="' .$row['number']. '">Thats Awsome</a> (' .$row['likes']. ') <a href="javascript:;" class="vote_down" id=' .$row['number']. '>Thats terrible </a>(' .$row['dislikes']. ')</span>'; James. Link to comment https://forums.phpfreaks.com/topic/169292-solved-stumped-on-t_echo/#findComment-893360 Share on other sites More sharing options...
mikwit Posted August 8, 2009 Author Share Posted August 8, 2009 It's still giving the same error Link to comment https://forums.phpfreaks.com/topic/169292-solved-stumped-on-t_echo/#findComment-893363 Share on other sites More sharing options...
jamesxg1 Posted August 8, 2009 Share Posted August 8, 2009 I have a similar line to yours that works have a look at mine and see if it helps you with yours, echo '<td class="last"><input type="text" id="address" name="address" class="text" value="' . $row['address'] . '"/></td></tr>'; James. Link to comment https://forums.phpfreaks.com/topic/169292-solved-stumped-on-t_echo/#findComment-893366 Share on other sites More sharing options...
mikwit Posted August 8, 2009 Author Share Posted August 8, 2009 Because the actual page loads up fine and its only when the javascript action calls on the action and then the action returns an error message where the updated information is I feel like it should be somewhere in the larger php file but i can't find anything wrong there. wierd Maybe if i post a abrv version of the main page that'll help someone. <html> <head> <link rel="stylesheet" type="text/css" href="./css.css"> <script type='text/javascript' src='jquery.pack.js'></script> <script type='text/javascript'> $(function(){ $("a.vote_up").click(function(){ the_id = $(this).attr('id'); $("span#votes_count"+the_id).fadeOut("fast"); //the main ajax request $.ajax({ type: "POST", data: "action=vote_up&id="+$(this).attr("id"), url: "votes.php", success: function(msg) { $("span#votes_count"+the_id).html(msg); $("span#votes_count"+the_id).fadeIn(); } }); }); $("a.vote_down").click(function(){ the_id = $(this).attr('id'); //the main ajax request $.ajax({ type: "POST", data: "action=vote_down&id="+$(this).attr("id"), url: "votes.php", success: function(msg) { $("span#votes_count"+the_id).html(msg); $("span#votes_count"+the_id).fadeIn(); } }); }); }); </script> </head> <body> <?php $host = "d***"; $username = "***"; $password = "***"; $database = "***"; // Database name mysql_connect($host,$username,$password); @mysql_select_db($database); $sql = 'SELECT * FROM `wlu_main` LIMIT 0, 30 '; $result = mysql_query($sql) or die('query:<br />'.mysql_error()); while ($row = mysql_fetch_assoc($result)){ echo '<b class="b1"></b><b class="b2"></b><b class="b3"></b><b class="b4"></b> <div class="contentb"><div>'; echo nl2br($row['text']); echo "<br />"; echo '<span class="votes" id="votes_count'.$row['number'].'"><a href="javascript:;" class="vote_up" id="'.$row['number'].'">Thats Awsome</a>(' .$row['likes']. ') <a href="javascript:;" class="vote_down" id="' .$row['number']. '">Thats terrible </a>(' .$row['dislikes']. ')</span>'; echo '</div> </div> <b class="b4"></b><b class="b3"></b><b class="b2"></b><b class="b1"></b> <br />'; } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/169292-solved-stumped-on-t_echo/#findComment-893369 Share on other sites More sharing options...
jamesxg1 Posted August 8, 2009 Share Posted August 8, 2009 I cannot see no javascript in your larger php file ?. James. Link to comment https://forums.phpfreaks.com/topic/169292-solved-stumped-on-t_echo/#findComment-893370 Share on other sites More sharing options...
mikwit Posted August 8, 2009 Author Share Posted August 8, 2009 I scraped a lot of the javascript off a tut I saw but from my loose understanding of javascript I kept it all in tact atleast all the necessary things, and seeing as the error is a php parsing kind of thing I assumed it would be a php error. Link to comment https://forums.phpfreaks.com/topic/169292-solved-stumped-on-t_echo/#findComment-893372 Share on other sites More sharing options...
mikwit Posted August 8, 2009 Author Share Posted August 8, 2009 I don't know what i did but i rewrote most of the action php and it works now, whatevs... Thanks a lot for your help jamesxg1 Link to comment https://forums.phpfreaks.com/topic/169292-solved-stumped-on-t_echo/#findComment-893415 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.