Faults in this code?

vaulient2

New Member
Mar 12, 2013
27
3
Code:
<?PHP
 
$p1 = 5;
 
$pages = mysql_query("SELECT COUNT(id) FROM cms_comments");
$p2 = ceil(mysql_result($pages, 0) / $p1);
 
$page = (isset($_GET['page'])) ? (int)$_GET['page'] :  1;
$start = ($page - 1) * $p1;
 
 
$uids = $_SESSION['user']['id'];
$id = preg_replace('/\D/', '', $_GET['id']);
 
function getPost($uid) {
$sql = "SELECT * FROM cms_comments WHERE author = '$uid' LIMIT $start, $p1";
$query = mysql_query($sql) or die(mysql_error());
$nummy = mysql_query("SELECT * FROM cms_comments");
$numrows = mysql_num_rows($nummy);
if(mysql_num_rows($query) > 0 && $_SESSION['user']['rank'] < 0) {
return true;
}
else { return false; }
}
if(getPost($uids) == true) { echo 'You may only post once!'; }
function post($data, $story, $uid) {
$clean = htmlentities(mysql_real_escape_string($data));
$sql = "INSERT INTO cms_comments (story, comment, date, author) VALUES ('$story', '$clean', '". time() ."', '$uid')";
$query = mysql_query($sql) or die(mysql_error());
}
$posts = getPost($uids);
if(isset($_POST['comment']) && strlen($_POST['comment']) > 0 && strlen($_POST['comment']) < 500 && $posts == false) {
post($_POST['comment'], $id, $uids);
echo '<head><meta http-equiv="refresh" content="0"></head>';
}
 
 
 
 $sql = "SELECT * FROM cms_comments WHERE story = '{$id}' ORDER BY id DESC";
$query = mysql_query($sql) or die(mysql_error());
 
while($ua = mysql_fetch_array($query)) {
$uiq = mysql_query("SELECT * FROM users WHERE id = ". $ua['author']) or die(mysql_error());
$ui = mysql_fetch_array($uiq) or die(mysql_error());
 
if($ui['rank'] >= 10) { $username = '<span style="font-family:Arial,Helvetica,sans-serif; color: #7D0A79;text-shadow: 0px 0px 5px #343434;background:url(/app/tpl/skins/Custom-Habbo/images/glitter.gif);">'. $ui['username'] .'</span>';}
else { $username = '<span style="font-family:Arial,Helvetica,sans-serif;">'. $ui['username'] .'</span>'; }
 
if($ui['rank'] >= 6) { $username = '<span style="font-family:Arial,Helvetica,sans-serif; color: #7D0A79;text-shadow: 0px 0px 5px #343434;background:url(/app/tpl/skins/Custom-Habbo/images/glitter.gif);">'. $ui['username'] .'</span>';}
else { $username = '<span style="font-family:Arial,Helvetica,sans-serif;">'. $ui['username'] .'</span>'; }
}
echo "Pages: ";
if($p2 >= 1 && $page <= $p2){
for($x=1; $x<=$p2; $x++) {
 
echo ($x == $page) ? '<strong><a href="?page='.$x.'">'.$x.'</a></strong> ' : '<a href="?page='.$x.'">'.$x.'</a> ';
}
}
 
?>
Well I've been working on this fo sometime now , and I'm stuck with a syntax error. I can't find it anywhere , could any of you help me out?
 

Sean

‫‫‫‫‫‫  ‫  Don't Worry, Be Happy
Dec 12, 2011
1,121
405
If you read the error it tells you what is wrong.
Your SQL syntax is wrong.
I see quite a lot of missing parts like.. () "" .. ;; `` ''
I suggest you re-do all of your SQL queries

And it says something about server version so your SQL might be out of date aswell.

What are you using to test / develop your program on?
 

vaulient2

New Member
Mar 12, 2013
27
3
If you read the error it tells you what is wrong.
Your SQL syntax is wrong.
I see quite a lot of missing parts like.. () "" .. ;; `` ''
I suggest you re-do all of your SQL queries

And it says something about server version so your SQL might be out of date aswell.

What are you using to test / develop your program on?

Well I'm using xampp 1.7.3 since I'm just working on this on localhost .. and redoing it would mean alot more work again ._.
 

vaulient2

New Member
Mar 12, 2013
27
3
Update your Xampp, 1.7.3 is very old

There is another code

Code:
<?PHP
$p1 = 3;
$pages = mysql_query("SELECT COUNT(id) FROM cms_comments");
$p2 = ceil(mysql_result($pages, 0) / $p1);
$page = (isset($_GET['page'])) ? (int)$_GET['page'] :  0;
$start = ($page - 1) * $p1;
if(mysql_num_rows($getComments) == 0) {
    echo "No comments for this article!";
} else {
echo '<table width="528px">';
          while($Comments = mysql_fetch_array($getComments)){
          $getUserInfo = mysql_query("SELECT * FROM users WHERE username = '".$Comments['author']."'");
$userInfo = mysql_fetch_array($getUserInfo);
$nummy = mysql_query("SELECT * FROM cms_comments");
$numrows = mysql_num_rows($nummy);
                  echo '
                  <tr>
                    <td width="90px" valign="top"></div>
                    <div style="
height: 65px;
width: 50px;
float: left;
overflow: hidden;
">
                      <div style="float:left"><img position:absolute; src="http://habbo.fr/habbo-imaging/avatarimage?figure='.$userInfo['look'].'&size=b&direction=2&head_direction=3&gesture=sml&size=2"></div>
                      ';                                       
                echo '
                </td>
                    <td width="427px" valign="top">
                    <i><a href="/me">'.$userInfo['username'].' </a></i>
                                        <br /><br />'.$Comments['comment'].'                                   
                    </td>
                  </tr>
          <tr>
                    <td width="80px" valign="top">               
                    </td>
                                <td width="400px" align="right">                                                                                                           
</div></div></div></div>
<br>
<div style="width:125%; height:1px; background-color:#ccc; margin-top:-17px;"></div>
            </td>
          </tr>';
          }
          echo '</table>';
}
echo "Pages: ";
if($p2 >= 1 && $page <= $p2){
for($x=1; $x<=$p2; $x++) {
echo ($x == $page) ? '<strong><a href="' . $_SERVER['PHP_SELF'] . '?page='.$x.'">'.$x.'</a></strong> ' : '<a href="' . $_SERVER['PHP_SELF'] . '?page='.$x.'">'.$x.'</a> ';
}
}
?>

Given by Monsta on another old thread of mine where I fairly got the pagination to work , where it shows the number of pages but doesn't show the comments. Also , which xampp do you recommend?
 

Users who are viewing this thread

Top