adamjones Posted January 25, 2010 Share Posted January 25, 2010 Hi, I keep getting this error; Parse error: syntax error, unexpected T_IF in ../payments.php on line 120 This is my code; <?php require_once('config.php'); $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } $sql="SELECT amount FROM payments WHERE user='".$_SESSION['user']."' AND member_id='".$_SESSION['id']."'" if (mysql_num_rows($sql) > 0) { while($rows=mysql_fetch_array($sql)){ ?> Not really sure why I'm getting this error... :S Any help would be appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/189770-unexpected-t_if/ Share on other sites More sharing options...
jsschmitt Posted January 25, 2010 Share Posted January 25, 2010 Hi, I keep getting this error; Parse error: syntax error, unexpected T_IF in ../payments.php on line 120 This is my code; <?php require_once('config.php'); $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } $sql="SELECT amount FROM payments WHERE user='".$_SESSION['user']."' AND member_id='".$_SESSION['id']."'" if (mysql_num_rows($sql) > 0) { while($rows=mysql_fetch_array($sql)){ ?> Not really sure why I'm getting this error... :S Any help would be appreciated! $sql="SELECT amount FROM payments WHERE user='".$_SESSION['user']."' AND member_id='".$_SESSION['id']."'" Is not ended with a ; Quote Link to comment https://forums.phpfreaks.com/topic/189770-unexpected-t_if/#findComment-1001468 Share on other sites More sharing options...
adamjones Posted January 25, 2010 Author Share Posted January 25, 2010 Thanks, but now I get this error; Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource <?php require_once('config.php'); $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } $sql="SELECT amount FROM payments WHERE user='".$_SESSION['user']."' AND member_id='".$_SESSION['id']."'"; if (mysql_num_rows($sql) > 0) { ?> <table cellspacing="0"> <thead> <tr> <th>Service</th> <th>Domain</th> <th>Due Date</th> <td class="tc">Amount</td> <td class="tc">Payment</td> </tr> </thead> <tbody> <?php while($rows=mysql_fetch_array($sql)){ ?> <tr class="first"><!-- .first for first row of the table (only if there is thead) --> <th><?php echo $rows['info']; ?></th> <th><?php echo $rows['domain']; ?></th> <td><?php echo $rows['duedate']; ?></td> <td class="tc"><a class="ico-pay" href="#">£<?php echo $rows['amount']; ?></a></td><!-- a.ico-comms for comment-like backgrounds --> <td valign="bottom" class="tc"><div align="center"><a href="./pay_paypal?v=<? echo $rows['amount']; ?>&id=<? echo $rows['id']; ?>" target="_blank"><img src="css/img/paypal.gif"><br></a> Prefer not to pay via credit card? You can also pay in person.<br> </div></td> </tr> <?php } } ?> </tbody> </table> <?php mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/189770-unexpected-t_if/#findComment-1001469 Share on other sites More sharing options...
jsschmitt Posted January 25, 2010 Share Posted January 25, 2010 I don't see an error... Quote Link to comment https://forums.phpfreaks.com/topic/189770-unexpected-t_if/#findComment-1001471 Share on other sites More sharing options...
schilly Posted January 25, 2010 Share Posted January 25, 2010 FYI no mysql_query call. mysql_num_rows accepts a results set from mysql_query. Quote Link to comment https://forums.phpfreaks.com/topic/189770-unexpected-t_if/#findComment-1001473 Share on other sites More sharing options...
adamjones Posted January 25, 2010 Author Share Posted January 25, 2010 sorry: "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource" Quote Link to comment https://forums.phpfreaks.com/topic/189770-unexpected-t_if/#findComment-1001476 Share on other sites More sharing options...
wildteen88 Posted January 25, 2010 Share Posted January 25, 2010 You need to pass your sql query to mysql_query first! $sql="SELECT amount FROM payments WHERE user='".$_SESSION['user']."' AND member_id='".$_SESSION['id']."'"; if (mysql_num_rows($sql) > 0) { Quote Link to comment https://forums.phpfreaks.com/topic/189770-unexpected-t_if/#findComment-1001478 Share on other sites More sharing options...
adamjones Posted January 25, 2010 Author Share Posted January 25, 2010 You need to pass your sql query to mysql_query first! $sql="SELECT amount FROM payments WHERE user='".$_SESSION['user']."' AND member_id='".$_SESSION['id']."'"; if (mysql_num_rows($sql) > 0) { Oops! Ok, I changed it to; $result = mysql_query("SELECT amount FROM payments WHERE user='".$_SESSION['user']."' AND member_id='".$_SESSION['id']."'"); if (mysql_num_rows($result) > 0) { But I'm still getting this error; Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource Quote Link to comment https://forums.phpfreaks.com/topic/189770-unexpected-t_if/#findComment-1001485 Share on other sites More sharing options...
wildteen88 Posted January 25, 2010 Share Posted January 25, 2010 You have an error with your SQL query. Use mysql_error to find out why. Quote Link to comment https://forums.phpfreaks.com/topic/189770-unexpected-t_if/#findComment-1001487 Share on other sites More sharing options...
adamjones Posted January 25, 2010 Author Share Posted January 25, 2010 Fixed, thanks Quote Link to comment https://forums.phpfreaks.com/topic/189770-unexpected-t_if/#findComment-1001488 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.