freemancomputer Posted May 9, 2012 Share Posted May 9, 2012 I am attempting to i have an if else statement that looks at 2 different things and if both are false then do something else. I am getting a Parse error: syntax error, unexpected T_ELSE in /home/drinktot/public_html/rules_main_test.php on line 173 I will note line 173 in the code IE. look into one table to see if there is a match, if there's not look in a different table for a match. If none is found there then post a button. I have been playing with this for a while now and I don't think I'm really seeing anything anymore, and its all blending together. <div id="to_play"> <?php if($rank>=1){ include"scripts/connect.php" ; mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $userquery_to_play = mysql_query("SELECT * FROM to_watch WHERE (to_watch_movie_id='$title') AND (to_watch_user_id='$loggedinusername')"); if (mysql_num_rows($userquery_to_play) > 0) { $user_to_play = mysql_result($userquery_to_play,$i,"to_watch_id"); ?> <div><span class="rulesub">This is in your to play list</span><br></div> <?php } else{ include"scripts/connect.php" ; mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $userquery_in_rating = mysql_query("SELECT * FROM rateing WHERE (title='$title') AND (user_id='$loggedinusername')"); if (mysql_num_rows($userquery_in_rating) > 0) { $user_in_rating = mysql_result($userquery_in_rating,$i,"to_watch_id"); ?> <div><span class="rulesub">You have rated this movie</span><br></div> <?php ****this is line 173 } } else { ?> <script type="text/javascript"> $(function() { $('#to-watch').submit(function(event) { event.preventDefault() $(this).hide('fast'); var movie_id_watch = $('#to-watch [name="MOVIE_ID_TO_WATCH"]').val(); var user_id_watch = $('#to-watch [name="USER_ID_TO_WATCH"]').val(); $.ajax({type: 'POST', url: 'to_play_add.php', cache: false, timeout: 10000, data: {to_watch_user_id: user_id_watch, to_watch_movie_id: movie_id_watch}, success: function() { $('#div_show_play').text('Added to your to play list'). append(html).show('fast'); }, error: function() { $('#div_show_play').text('There is a problem').show('fast'); } }); }); }); </script> <form id="to-watch"> <input type="hidden" name="MOVIE_ID_TO_WATCH" value="<?php echo $title; ?>"> <input type="hidden" name="USER_ID_TO_WATCH" value="<?php echo $loggedinusername; ?>"> <input type="submit" value="Add to my to play list"> </form> <div id="div_show_play" class="rulesub" align="left"> </div> <?php } } ?> </div> Thank you Quote Link to comment https://forums.phpfreaks.com/topic/262277-if-else-help/ Share on other sites More sharing options...
scootstah Posted May 9, 2012 Share Posted May 9, 2012 You can't have two else's with the same if. You can, however, have multiple elseif's and then a else. For example: if (1 == 3) { // one equals three } else if (1 == 2) { // one equals two } else { // one doesnt equal either three or two } Quote Link to comment https://forums.phpfreaks.com/topic/262277-if-else-help/#findComment-1344129 Share on other sites More sharing options...
freemancomputer Posted May 9, 2012 Author Share Posted May 9, 2012 Thanks for that, thought I had that in there. Fixed that problem which brings up another. When the movie is not in the rateing table its suppose to show the button in the last else but it is not doing that. Here is what I have now. <div id="to_play"> <?php if($rank>=1){ include"scripts/connect.php" ; mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $userquery_to_play = mysql_query("SELECT * FROM to_watch WHERE (to_watch_movie_id='$title') AND (to_watch_user_id='$loggedinusername')"); if (mysql_num_rows($userquery_to_play) > 0) { $user_to_play = mysql_result($userquery_to_play,$i,"to_watch_user_id"); ?> <div><span class="rulesub">This is in your to play list</span><br></div> <?php } else if($rank>=1){ include"scripts/connect.php" ; mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $userquery_in_rating = mysql_query("SELECT * FROM rateing WHERE (title='$title') AND (user_id='$loggedinusername')"); if (mysql_num_rows($userquery_in_rating) > 0) { $user_in_rating = mysql_result($userquery_in_rating,$i,"to_watch_id"); ?> <div><span class="rulesub">You have rated this movie</span><br></div> <?php } } else { ?> <script type="text/javascript"> $(function() { $('#to-watch').submit(function(event) { event.preventDefault() $(this).hide('fast'); var movie_id_watch = $('#to-watch [name="MOVIE_ID_TO_WATCH"]').val(); var user_id_watch = $('#to-watch [name="USER_ID_TO_WATCH"]').val(); $.ajax({type: 'POST', url: 'to_play_add.php', cache: false, timeout: 10000, data: {to_watch_user_id: user_id_watch, to_watch_movie_id: movie_id_watch}, success: function() { $('#div_show_play').text('Added to your to play list'). append(html).show('fast'); }, error: function() { $('#div_show_play').text('There is a problem').show('fast'); } }); }); }); </script> <form id="to-watch"> <input type="hidden" name="MOVIE_ID_TO_WATCH" value="<?php echo $title; ?>"> <input type="hidden" name="USER_ID_TO_WATCH" value="<?php echo $loggedinusername; ?>"> <input type="submit" value="Add to my to play list"> </form> <div id="div_show_play" class="rulesub" align="left"> </div> Quote Link to comment https://forums.phpfreaks.com/topic/262277-if-else-help/#findComment-1344131 Share on other sites More sharing options...
kiqeri Posted May 9, 2012 Share Posted May 9, 2012 I don't know if this is going to help or not, but instead of escaping from php a few times for html, why don't you just use echo instead, so the coding will look neat. Just a suggestion if you don't mind. Is the error said "unexpected $end" ? because you didn't tell the second problem. I tried to correct it and the error is because of the first 'if' isn't close (the bracket is still open). <div id="to_play"> <?php if($rank>=1) { include"scripts/connect.php" ; mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $userquery_to_play = mysql_query("SELECT * FROM to_watch WHERE (to_watch_movie_id='$title') AND (to_watch_user_id='$loggedinusername')"); if (mysql_num_rows($userquery_to_play) > 0) { $user_to_play = mysql_result($userquery_to_play,$i,"to_watch_user_id"); echo "<div><span class='rulesub'>This is in your to play list</span><br></div>"; } else if($rank>=1) { include"scripts/connect.php" ; mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $userquery_in_rating = mysql_query("SELECT * FROM rateing WHERE (title='$title') AND (user_id='$loggedinusername')"); } else { echo "<script type='text/javascript'>"; // your javascript echo "</script>"; echo "<form id='to-watch'>"; echo "<input type='hidden' name='MOVIE_ID_TO_WATCH' value='<?php echo $title; ?>'>"; echo "<input type='hidden' name='USER_ID_TO_WATCH' value='<?php echo $loggedinusername; ?>'>"; echo "<input type='submit' value='Add to my to play list'>"; echo "</form>"; echo "<div id='div_show_play' class='rulesub' align='left'>"; echo "</div>"; } } ?> sorry if it doesn't help. Quote Link to comment https://forums.phpfreaks.com/topic/262277-if-else-help/#findComment-1344152 Share on other sites More sharing options...
freemancomputer Posted May 9, 2012 Author Share Posted May 9, 2012 Old habits die hard, you pick up a lot of bad ones when you teach or self along the way. This does make the code flow a lot better but it does not fix the problem. If a movie has not been added to the to_watch table and is not in the rateing table the to-watch form should come up with the button but this does not happen, only the rating form shows. If the move is in the to_watch table only the rating form shows along with the "This is in your to play list" statement. Here is where I am at. From the start of the div that its located in to the end. I know there is a better way of doing the rating images and that's my next project. Thanks <div id="rule_your_rating"> <?php if($rank>=1){ include"scripts/connect.php" ; mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $userquery_show_rating = mysql_query("SELECT * FROM rateing WHERE (movie_id='$id') AND (user_id='$loggedinusername')"); if (mysql_num_rows($userquery_show_rating) > 0) { $user_rating_show = mysql_result($userquery_show_rating,$i,"rating"); echo "<tr><td><span class='rulemain'>Your Rating:</span><br>"; if($user_rating_show==1) { echo "<img src='beer_mug_finish.jpg' name='beer_mug' width='50' height='50'>"; } if($user_rating_show==2) { echo "<img src='beer_mug_finish.jpg' name='beer_mug' width='50' height='50'>"; echo "<img src='beer_mug_finish.jpg' name='beer_mug' width='50' height='50'>"; } if($user_rating_show==3) { echo "<img src='beer_mug_finish.jpg' name='beer_mug' width='50' height='50'>"; echo "<img src='beer_mug_finish.jpg' name='beer_mug' width='50' height='50'>"; echo "<img src='beer_mug_finish.jpg' name='beer_mug' width='50' height='50'>"; } if($user_rating_show==4) { echo "<img src='beer_mug_finish.jpg' name='beer_mug' width='50' height='50'>"; echo "<img src='beer_mug_finish.jpg' name='beer_mug' width='50' height='50'>"; echo "<img src='beer_mug_finish.jpg' name='beer_mug' width='50' height='50'>"; echo "<img src='beer_mug_finish.jpg' name='beer_mug' width='50' height='50'>"; } if($user_rating_show==5) { echo "<img src='beer_mug_finish.jpg' name='beer_mug' width='50' height='50'>"; echo "<img src='beer_mug_finish.jpg' name='beer_mug' width='50' height='50'>"; echo "<img src='beer_mug_finish.jpg' name='beer_mug' width='50' height='50'>"; echo "<img src='beer_mug_finish.jpg' name='beer_mug' width='50' height='50'>"; echo "<img src='beer_mug_finish.jpg' name='beer_mug' width='50' height='50'>"; } } else { ?> <script type="text/javascript"> $(function() { $('#add-rating').submit(function(event) { event.preventDefault() $(this).hide('fast'); $(div_show).hide('fast'); var movie_rating_s = $('#add-rating [name="MOVIE_RATING"]:checked').val(); var movie_id_s = $('#add-rating [name="MOVIE_ID"]').val(); var movie_title_s = $('#add-rating [name="MOVIE_TITLE"]').val(); var user_id_s = $('#add-rating [name="USER_ID"]').val(); $.ajax({type: 'POST', url: 'movie_watched.php', cache: false, timeout: 10000, data: {rating: movie_rating_s, movie: movie_id_s, title: movie_title_s, user: user_id_s}, success: function() { var html = '<br/>'; for (var i = 0; i < movie_rating_s; i++) { html += '<img src="beer_mug_finish.jpg" alt="" name="beer_mug" width="50" height="50">'; } $('#div_show').text('You have rated ' + movie_title_s). append(html).show('fast'); }, error: function() { $('#div_show').text('There is a problem').show('fast'); } }); }); }); </script> <?php echo "<form id='add-rating'>"; echo "<input type='radio' name='MOVIE_RATING' value='1' > 1"; echo "<input type='radio' name='MOVIE_RATING' value='2' > 2"; echo "<input type='radio' name='MOVIE_RATING' value='3' checked='yes'> 3"; echo "<input type='radio' name='MOVIE_RATING' value='4' > 4 "; echo "<input type='radio' name='MOVIE_RATING' value='5' > 5 <br>"; echo "<input type='hidden' name='MOVIE_ID' value='<?php echo $id; ?>'>"; echo "<input type='hidden' name='MOVIE_TITLE' value='<?php echo stripslashes($title); ?>'>"; echo "<input type='hidden' name='USER_ID' value='<?php echo $loggedinusername; ?>'>"; echo "<input type='submit' value='Rate'>"; echo "</form>"; echo "<div id='div_show' class='rulesub' align='left'>"; echo "</div>"; } echo "<div id='to_play'>"; if($rank>=1){ include"scripts/connect.php" ; mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query_to_play = mysql_query("SELECT * FROM to_watch WHERE (to_watch_movie_id='$title') AND (to_watch_user_id='$loggedinusername')"); if(mysql_num_rows($query_to_play) > 0) { $user_to_play = mysql_result($query_to_play,$i,"to_watch_user_id"); echo "<div><span class='rulesub'>This is in your to play list</span><br></div>"; } else if($rank>=1) { include"scripts/connect.php" ; mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $userquery_in_rating = mysql_query("SELECT * FROM rateing WHERE (title='$title') AND (user_id='$loggedinusername')"); if (mysql_num_rows($userquery_in_rating) > 0) { $user_in_rating = mysql_result($userquery_in_rating,$i,"to_watch_id"); echo "<div><span class='rulesub'>You have rated this movie</span><br></div>"; } } else { ?> <script type='text/javascript'> $(function() { $('#to-watch').submit(function(event) { event.preventDefault() $(this).hide('fast'); var movie_id_watch = $('#to-watch [name="MOVIE_ID_TO_WATCH"]').val(); var user_id_watch = $('#to-watch [name="USER_ID_TO_WATCH"]').val(); $.ajax({type: 'POST', url: 'to_play_add.php', cache: false, timeout: 10000, data: {to_watch_user_id: user_id_watch, to_watch_movie_id: movie_id_watch}, success: function() { $('#div_show_play').text('Added to your to play list'). append(html).show('fast'); }, error: function() { $('#div_show_play').text('There is a problem').show('fast'); } }); }); }); </script> <?php echo "<form id='to-watch'>"; echo "<input type='hidden' name='MOVIE_ID_TO_WATCH' value='<?php echo $title; ?>'>"; echo "<input type='hidden' name='USER_ID_TO_WATCH' value='<?php echo $loggedinusername; ?>'>"; echo "<input type='submit' value='Add to my to play list'>"; echo "</form>"; echo "<div id='div_show_play' class='rulesub' align='left'>"; echo "</div>"; } } ?> </div> <?php } ?> </div> Quote Link to comment https://forums.phpfreaks.com/topic/262277-if-else-help/#findComment-1344361 Share on other sites More sharing options...
kiqeri Posted May 10, 2012 Share Posted May 10, 2012 Did you mean the form <form id="to-watch"> ? And is it calling below's javascript function? $(function() { $('#to-watch').submit(function(event) { event.preventDefault() $(this).hide('fast'); var movie_id_watch = $('#to-watch [name="MOVIE_ID_TO_WATCH"]').val(); var user_id_watch = $('#to-watch [name="USER_ID_TO_WATCH"]').val(); $.ajax({type: 'POST', url: 'to_play_add.php', cache: false, timeout: 10000, data: {to_watch_user_id: user_id_watch, to_watch_movie_id: movie_id_watch}, success: function() { $('#div_show_play').text('Added to your to play list'). append(html).show('fast'); }, error: function() { $('#div_show_play').text('There is a problem').show('fast'); } }); }); }); as far as I know we cannot call function using that way. Sorry if I misunderstood, though. Guess I'm not helping Quote Link to comment https://forums.phpfreaks.com/topic/262277-if-else-help/#findComment-1344385 Share on other sites More sharing options...
freemancomputer Posted May 10, 2012 Author Share Posted May 10, 2012 All fixed, I had one of the If statements further down out side of a bracket. Thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/262277-if-else-help/#findComment-1344389 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.