Solved

UPDATE mysql

Posted on 2007-03-20
17
366 Views
Last Modified: 2013-12-13
Hello, I want in the following script

<?php
ob_start();
?>
<?php
// include/require hier evt nog andere zaken
require ("../scripts/connect.php");
// we willen op deze pagina gebruik maken van beveiliging mbv sessies,
// dus includen (requiren) we session.php
require("../scripts/session.php");

   // Fetch the article category
   $rsc = mysql_query("SELECT category FROM articles WHERE id=$_GET[id]") or die(mysql_error());
   $row = mysql_fetch_array($rsc);
      $cat = $row['category'];

  if (($cat == 2) && ((int)$_SESSION['slevel'] < 2)) {
      header("Location:accessdenied.php");
      exit(); //stop the script.
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>KB RBINS</title>
<link rel="stylesheet" type="text/css" href="../main.css" />
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
</head>
<body>
   <!-- Begin Wrapper -->
   <div id="wrapper">
         <!-- Begin Header -->
         <div id="header">
                  <h1>Knowledgebase System RBINS</h1>       
             </div>
             <!-- End Header -->
         <!-- Begin Faux Columns -->
             <div id="faux">            
                   <!-- Begin Left Column -->
                   <div id="leftcolumn">      
                     <?php
                            include("../scripts/checkuser.php");
                     ?>       
                   </div>
                   <!-- End Left Column -->
                   <!-- Begin Right Column -->
                   <div id="rightcolumn">      
                     <center><h2>Result</h2></center>             
                       <?php
                  $res=mysql_query("SELECT ID, title, article, author FROM articles WHERE id = '".$_GET['id']."'") or die(mysql_error()) ;
                  $r = mysql_fetch_array($res);
                  $article = nl2br($r['article']);
                  echo '<div class="result"><h3>KB'.$r['ID'].'&nbsp; - &nbsp;'.$r['title'].'</h3><br />';
                  echo $article;
                  $res2=mysql_query("SELECT score, counter FROM articles WHERE id = '".$_GET['id']."'") or die(mysql_error()) ;
                  $r2 = mysql_fetch_array($res2);
                  if ($r2['counter']=="0") {
                        echo '</div><div class="author"><h5>'.$r['author'].'</h5><h6>No grade has been given yet</h6></div>' ;}
                        else {
                        $r3=round ($r2['score']/$r2['counter'],2);//2 or less decimals
                        echo '</div><div class="author"><h5>'.$r['author'].'</h5><h6>Grade:&nbsp;'.$r3.'&nbsp;('.$r2['counter'].'&nbsp;vote(s))</h6></div>';}
                  ?>      
                  <br />
                  <?php
                        include("../scripts/counting.php");
                  ?>
                  <br />
                  <a href="../index.php">Another search?</a>
                     <div class="clear"></div>                     
                   </div>
                   <!-- End Right Column -->                     
                     <div class="clear"></div>                     
         </div>         
         <!-- End Faux Columns -->
         <!-- Begin Footer -->
         <div id="footer">                  
               <h4>Jo Vanattenhoven&copy;2007</h4>            
         </div>
             <!-- End Footer -->            
   </div>
   <!-- End Wrapper -->
</body>
</html>
<?php
ob_end_flush();
?>

add +1 into the views field of my articles table. It should probably be done through UPDATE. Can I do this in the first lines (so after including connect.php and session.php) or do I need to do that somewhere else
0
Comment
Question by:jvuz
  • 6
  • 5
  • 5
  • +1
17 Comments
 
LVL 14

Expert Comment

by:Aamir Saeed
ID: 18755682
not sure what do you want exactly?
0
 
LVL 21

Author Comment

by:jvuz
ID: 18755693
Everytime a page is viewed, I want to add +1 on the views field. So that way, afterwards I can add somewhere else how many times some article has been viewed.
0
 
LVL 11

Expert Comment

by:elfe69
ID: 18755699
You can do it at the beginning, before fetching your article category, add the following line:

mysql_query("UPDATE articles SET views = (views + 1) WHERE id=$_GET[id]") or die(mysql_error());
0
 
LVL 14

Expert Comment

by:Aamir Saeed
ID: 18755723
mysql_query("UPDATE articles SET views = (views + 1) WHERE id='".$_GET[id]."'") or die(mysql_error());
0
 
LVL 27

Assisted Solution

by:yodercm
yodercm earned 166 total points
ID: 18755764
You can do it at any point in the code that you wish.

However, do NOT do this, as a couple of people have said:

mysql_query("UPDATE articles SET views = (views + 1) WHERE id='".$_GET[id]."'") or die(mysql_error());

Using a $_GET value directly in a query opens you wide open to SQL Injection hacking!!!  NEVER EVER use a $_GET or $_POST variable directly in a query.  ALWAYS pass it through a safety value like

$id = htmlentities($_GET["id"], ENT_QUOTES);

Then, you can use it without danger, as

mysql_query("UPDATE articles SET views = views+1 WHERE id='$id') or die(mysql_error());



0
 
LVL 21

Author Comment

by:jvuz
ID: 18755767
I'm having several problems now:

<?php
ob_start();
?>
<?php
// include/require hier evt nog andere zaken
require ("../scripts/connect.php");
// we willen op deze pagina gebruik maken van beveiliging mbv sessies,
// dus includen (requiren) we session.php
require("../scripts/session.php");
mysql_query("UPDATE articles SET views = (views + 1) WHERE id='".$_GET[id]."'") or die(mysql_error());
   // Fetch the article category
   $rsc = mysql_query("SELECT category FROM articles WHERE id=$_GET[id]") or die(mysql_error());
   $row = mysql_fetch_array($rsc);
      $cat = $row['category'];

  if (($cat == 2) && ((int)$_SESSION['slevel'] < 2)) {
      header("Location:accessdenied.php");
      exit(); //stop the script.
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>KB RBINS</title>
<link rel="stylesheet" type="text/css" href="../main.css" />
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
</head>
<body>
   <!-- Begin Wrapper -->
   <div id="wrapper">
         <!-- Begin Header -->
         <div id="header">
                  <h1>Knowledgebase System RBINS</h1>       
             </div>
             <!-- End Header -->
         <!-- Begin Faux Columns -->
             <div id="faux">            
                   <!-- Begin Left Column -->
                   <div id="leftcolumn">      
                     <?php
                            include("../scripts/checkuser.php");
                     ?>       
                   </div>
                   <!-- End Left Column -->
                   <!-- Begin Right Column -->
                   <div id="rightcolumn">      
                     <center><h2>Result</h2></center>             
                       <?php
                  $res=mysql_query("SELECT ID, title, article, author, FROM articles WHERE id = '".$_GET['id']."'") or die(mysql_error()) ;
                  $r = mysql_fetch_array($res);
                  $article = nl2br($r['article']);
                  echo '<div class="result"><h3>KB'.$r['ID'].'&nbsp; - &nbsp;'.$r['title'].'</h3><br />';
                  echo $article;
                  $res2=mysql_query("SELECT score, counter, views FROM articles WHERE id = '".$_GET['id']."'") or die(mysql_error()) ;
                  $r2 = mysql_fetch_array($res2);
                  if ($r2['counter']=="0") {
                        echo '</div><div class="author"><h5>'.$r['author'].'</h5><h6>No grade has been given yet</h6></div>' ;}
                        else {
                        $r3=round ($r2['score']/$r2['counter'],2);//2 or less decimals
                        echo '</div><div class="author"><h5>'.$r['author'].'</h5><h6>Grade:&nbsp;'.$r3.'&nbsp;('.$r2['counter'].'&nbsp;vote(s))</h6><h6>Viewed:&nbsp;'.$r2['views'].'&nbsp;</h6></div>';}
                  ?>      
                  <br />
                  <?php
                        include("../scripts/counting.php");
                  ?>
                  <br />
                  <a href="../index.php">Another search?</a>
                     <div class="clear"></div>                     
                   </div>
                   <!-- End Right Column -->                     
                     <div class="clear"></div>                     
         </div>         
         <!-- End Faux Columns -->
         <!-- Begin Footer -->
         <div id="footer">                  
               <h4>Jo Vanattenhoven&copy;2007</h4>            
         </div>
             <!-- End Footer -->            
   </div>
   <!-- End Wrapper -->
</body>
</html>
<?php
ob_end_flush();
?>

First I get:
Use of undefined constant id - assumed 'id'
Then I get:
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 'FROM articles WHERE id = '34'' at line 1
0
 
LVL 14

Accepted Solution

by:
Aamir Saeed earned 167 total points
ID: 18755791
try
<?php
ob_start();
?>
<?php
// include/require hier evt nog andere zaken
require ("../scripts/connect.php");
// we willen op deze pagina gebruik maken van beveiliging mbv sessies,
// dus includen (requiren) we session.php
require("../scripts/session.php");
mysql_query("UPDATE articles SET views = (views + 1) WHERE id=".$_GET['id']."") or die(mysql_error());
   // Fetch the article category
   $rsc = mysql_query("SELECT category FROM articles WHERE id=$_GET[id]") or die(mysql_error());
   $row = mysql_fetch_array($rsc);
      $cat = $row['category'];

  if (($cat == 2) && ((int)$_SESSION['slevel'] < 2)) {
      header("Location:accessdenied.php");
      exit(); //stop the script.
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>KB RBINS</title>
<link rel="stylesheet" type="text/css" href="../main.css" />
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
</head>
<body>
   <!-- Begin Wrapper -->
   <div id="wrapper">
         <!-- Begin Header -->
         <div id="header">
                  <h1>Knowledgebase System RBINS</h1>      
             </div>
             <!-- End Header -->
         <!-- Begin Faux Columns -->
             <div id="faux">            
                   <!-- Begin Left Column -->
                   <div id="leftcolumn">      
                     <?php
                            include("../scripts/checkuser.php");
                     ?>      
                   </div>
                   <!-- End Left Column -->
                   <!-- Begin Right Column -->
                   <div id="rightcolumn">      
                     <center><h2>Result</h2></center>            
                       <?php
                  $res=mysql_query("SELECT ID, title, article, author, FROM articles WHERE id = '".$_GET['id']."'") or die(mysql_error()) ;
                  $r = mysql_fetch_array($res);
                  $article = nl2br($r['article']);
                  echo '<div class="result"><h3>KB'.$r['ID'].'&nbsp; - &nbsp;'.$r['title'].'</h3><br />';
                  echo $article;
                  $res2=mysql_query("SELECT score, counter, views FROM articles WHERE id = '".$_GET['id']."'") or die(mysql_error()) ;
                  $r2 = mysql_fetch_array($res2);
                  if ($r2['counter']=="0") {
                        echo '</div><div class="author"><h5>'.$r['author'].'</h5><h6>No grade has been given yet</h6></div>' ;}
                        else {
                        $r3=round ($r2['score']/$r2['counter'],2);//2 or less decimals
                        echo '</div><div class="author"><h5>'.$r['author'].'</h5><h6>Grade:&nbsp;'.$r3.'&nbsp;('.$r2['counter'].'&nbsp;vote(s))</h6><h6>Viewed:&nbsp;'.$r2['views'].'&nbsp;</h6></div>';}
                  ?>      
                  <br />
                  <?php
                        include("../scripts/counting.php");
                  ?>
                  <br />
                  <a href="../index.php">Another search?</a>
                     <div class="clear"></div>                    
                   </div>
                   <!-- End Right Column -->                    
                     <div class="clear"></div>                    
         </div>        
         <!-- End Faux Columns -->
         <!-- Begin Footer -->
         <div id="footer">                  
               <h4>Jo Vanattenhoven&copy;2007</h4>            
         </div>
             <!-- End Footer -->            
   </div>
   <!-- End Wrapper -->
</body>
</html>
<?php
ob_end_flush();
?>
0
 
LVL 14

Expert Comment

by:Aamir Saeed
ID: 18755814
try

<?php
ob_start();
?>
<?php
// include/require hier evt nog andere zaken
require ("../scripts/connect.php");
// we willen op deze pagina gebruik maken van beveiliging mbv sessies,
// dus includen (requiren) we session.php
require("../scripts/session.php");
mysql_query("UPDATE articles SET views = (views + 1) WHERE id=".$_GET['id']."") or die(mysql_error());
   // Fetch the article category
   $rsc = mysql_query("SELECT category FROM articles WHERE id=".$_GET['id']."") or die(mysql_error());
   $row = mysql_fetch_array($rsc);
      $cat = $row['category'];

  if (($cat == 2) && ((int)$_SESSION['slevel'] < 2)) {
      header("Location:accessdenied.php");
      exit(); //stop the script.
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>KB RBINS</title>
<link rel="stylesheet" type="text/css" href="../main.css" />
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
</head>
<body>
   <!-- Begin Wrapper -->
   <div id="wrapper">
         <!-- Begin Header -->
         <div id="header">
                  <h1>Knowledgebase System RBINS</h1>      
             </div>
             <!-- End Header -->
         <!-- Begin Faux Columns -->
             <div id="faux">            
                   <!-- Begin Left Column -->
                   <div id="leftcolumn">      
                     <?php
                            include("../scripts/checkuser.php");
                     ?>      
                   </div>
                   <!-- End Left Column -->
                   <!-- Begin Right Column -->
                   <div id="rightcolumn">      
                     <center><h2>Result</h2></center>            
                       <?php
                  $res=mysql_query("SELECT ID, title, article, author, FROM articles WHERE id = '".$_GET['id']."'") or die(mysql_error()) ;
                  $r = mysql_fetch_array($res);
                  $article = nl2br($r['article']);
                  echo '<div class="result"><h3>KB'.$r['ID'].'&nbsp; - &nbsp;'.$r['title'].'</h3><br />';
                  echo $article;
                  $res2=mysql_query("SELECT score, counter, views FROM articles WHERE id = '".$_GET['id']."'") or die(mysql_error()) ;
                  $r2 = mysql_fetch_array($res2);
                  if ($r2['counter']=="0") {
                        echo '</div><div class="author"><h5>'.$r['author'].'</h5><h6>No grade has been given yet</h6></div>' ;}
                        else {
                        $r3=round ($r2['score']/$r2['counter'],2);//2 or less decimals
                        echo '</div><div class="author"><h5>'.$r['author'].'</h5><h6>Grade:&nbsp;'.$r3.'&nbsp;('.$r2['counter'].'&nbsp;vote(s))</h6><h6>Viewed:&nbsp;'.$r2['views'].'&nbsp;</h6></div>';}
                  ?>      
                  <br />
                  <?php
                        include("../scripts/counting.php");
                  ?>
                  <br />
                  <a href="../index.php">Another search?</a>
                     <div class="clear"></div>                    
                   </div>
                   <!-- End Right Column -->                    
                     <div class="clear"></div>                    
         </div>        
         <!-- End Faux Columns -->
         <!-- Begin Footer -->
         <div id="footer">                  
               <h4>Jo Vanattenhoven&copy;2007</h4>            
         </div>
             <!-- End Footer -->            
   </div>
   <!-- End Wrapper -->
</body>
</html>
<?php
ob_end_flush();
?>
0
Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 21

Author Comment

by:jvuz
ID: 18755828
Sorry, no changes.
0
 
LVL 14

Expert Comment

by:Aamir Saeed
ID: 18755849
try
<?php
ob_start();
?>
<?php
// include/require hier evt nog andere zaken
require ("../scripts/connect.php");
// we willen op deze pagina gebruik maken van beveiliging mbv sessies,
// dus includen (requiren) we session.php
require("../scripts/session.php");
mysql_query("UPDATE articles SET views = (views + 1) WHERE id=".$_GET['id']."") or die(mysql_error());
   // Fetch the article category
   $rsc = mysql_query("SELECT category FROM articles WHERE id=".$_GET['id']."") or die(mysql_error());
   $row = mysql_fetch_array($rsc);
      $cat = $row['category'];

  if (($cat == 2) && ((int)$_SESSION['slevel'] < 2)) {
      header("Location:accessdenied.php");
      exit(); //stop the script.
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>KB RBINS</title>
<link rel="stylesheet" type="text/css" href="../main.css" />
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
</head>
<body>
   <!-- Begin Wrapper -->
   <div id="wrapper">
         <!-- Begin Header -->
         <div id="header">
                  <h1>Knowledgebase System RBINS</h1>      
             </div>
             <!-- End Header -->
         <!-- Begin Faux Columns -->
             <div id="faux">            
                   <!-- Begin Left Column -->
                   <div id="leftcolumn">      
                     <?php
                            include("../scripts/checkuser.php");
                     ?>      
                   </div>
                   <!-- End Left Column -->
                   <!-- Begin Right Column -->
                   <div id="rightcolumn">      
                     <center><h2>Result</h2></center>            
                       <?php
                  $res=mysql_query("SELECT ID, title, article, author, FROM articles WHERE id = '".$_GET['id']."'") or die(mysql_error()) ;
                  $r = mysql_fetch_array($res);
                  $article = nl2br($r['article']);
                  echo '<div class="result"><h3>KB'.$r['ID'].'&nbsp; - &nbsp;'.$r['title'].'</h3><br />';
                  echo $article;
                  $res2=mysql_query("SELECT score, counter, views FROM articles WHERE id = '".$_GET['id']."'") or die(mysql_error()) ;
                  $r2 = mysql_fetch_array($res2);
                  if ($r2['counter']=="0") {
                        echo '</div><div class="author"><h5>'.$r['author'].'</h5><h6>No grade has been given yet</h6></div>' ;}
                        else {
                        $r3=round ($r2['score']/$r2['counter'],2);//2 or less decimals
                        echo '</div><div class="author"><h5>'.$r['author'].'</h5><h6>Grade:&nbsp;'.$r3.'&nbsp;('.$r2['counter'].'&nbsp;vote(s))</h6><h6>Viewed:&nbsp;'.$r2['views'].'&nbsp;</h6></div>';}
                  ?>      
                  <br />
                  <?php
                        include("../scripts/counting.php");
                  ?>
                  <br />
                  <a href="../index.php">Another search?</a>
                     <div class="clear"></div>                    
                   </div>
                   <!-- End Right Column -->                    
                     <div class="clear"></div>                    
         </div>        
         <!-- End Faux Columns -->
         <!-- Begin Footer -->
         <div id="footer">                  
               <h4>Jo Vanattenhoven&copy;2007</h4>            
         </div>
             <!-- End Footer -->            
   </div>
   <!-- End Wrapper -->
</body>
</html>
<?php
ob_end_flush();
?>
0
 
LVL 11

Expert Comment

by:elfe69
ID: 18755857
still the same error ?
0
 
LVL 21

Author Comment

by:jvuz
ID: 18755889
Now I only get: 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 'FROM articles WHERE id = '34'' at line 1

I already looked at the places where there is FROM articles, but I don't see anything wrong. Do you?
0
 
LVL 11

Expert Comment

by:elfe69
ID: 18755929
You have enclosed the id value with ' in your 2 last SELECT statements and id is a numeric field.

Try this:

<?php
ob_start();
?>
<?php
// include/require hier evt nog andere zaken
require ("../scripts/connect.php");
// we willen op deze pagina gebruik maken van beveiliging mbv sessies,
// dus includen (requiren) we session.php
require("../scripts/session.php");
mysql_query("UPDATE articles SET views = (views + 1) WHERE id=".$_GET['id']) or die(mysql_error());
   // Fetch the article category
   $rsc = mysql_query("SELECT category FROM articles WHERE id=".$_GET['id']) or die(mysql_error());
   $row = mysql_fetch_array($rsc);
      $cat = $row['category'];

  if (($cat == 2) && ((int)$_SESSION['slevel'] < 2)) {
      header("Location:accessdenied.php");
      exit(); //stop the script.
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>KB RBINS</title>
<link rel="stylesheet" type="text/css" href="../main.css" />
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
</head>
<body>
   <!-- Begin Wrapper -->
   <div id="wrapper">
         <!-- Begin Header -->
         <div id="header">
                  <h1>Knowledgebase System RBINS</h1>      
             </div>
             <!-- End Header -->
         <!-- Begin Faux Columns -->
             <div id="faux">            
                   <!-- Begin Left Column -->
                   <div id="leftcolumn">      
                     <?php
                            include("../scripts/checkuser.php");
                     ?>      
                   </div>
                   <!-- End Left Column -->
                   <!-- Begin Right Column -->
                   <div id="rightcolumn">      
                     <center><h2>Result</h2></center>            
                       <?php
                  $res=mysql_query("SELECT ID, title, article, author, FROM articles WHERE id = ".$_GET['id']) or die(mysql_error()) ;
                  $r = mysql_fetch_array($res);
                  $article = nl2br($r['article']);
                  echo '<div class="result"><h3>KB'.$r['ID'].'&nbsp; - &nbsp;'.$r['title'].'</h3><br />';
                  echo $article;
                  $res2=mysql_query("SELECT score, counter, views FROM articles WHERE id = ".$_GET['id']) or die(mysql_error()) ;
                  $r2 = mysql_fetch_array($res2);
                  if ($r2['counter']=="0") {
                        echo '</div><div class="author"><h5>'.$r['author'].'</h5><h6>No grade has been given yet</h6></div>' ;}
                        else {
                        $r3=round ($r2['score']/$r2['counter'],2);//2 or less decimals
                        echo '</div><div class="author"><h5>'.$r['author'].'</h5><h6>Grade:&nbsp;'.$r3.'&nbsp;('.$r2['counter'].'&nbsp;vote(s))</h6><h6>Viewed:&nbsp;'.$r2['views'].'&nbsp;</h6></div>';}
                  ?>      
                  <br />
                  <?php
                        include("../scripts/counting.php");
                  ?>
                  <br />
                  <a href="../index.php">Another search?</a>
                     <div class="clear"></div>                    
                   </div>
                   <!-- End Right Column -->                    
                     <div class="clear"></div>                    
         </div>        
         <!-- End Faux Columns -->
         <!-- Begin Footer -->
         <div id="footer">                  
               <h4>Jo Vanattenhoven&copy;2007</h4>            
         </div>
             <!-- End Footer -->            
   </div>
   <!-- End Wrapper -->
</body>
</html>
<?php
ob_end_flush();
?>
0
 
LVL 21

Author Comment

by:jvuz
ID: 18755976
Now, it's 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 'FROM articles WHERE id = 34' at line 1
0
 
LVL 11

Assisted Solution

by:elfe69
elfe69 earned 167 total points
ID: 18756001
Remove the comma after author in your second SELECT statement:

<?php
ob_start();
?>
<?php
// include/require hier evt nog andere zaken
require ("../scripts/connect.php");
// we willen op deze pagina gebruik maken van beveiliging mbv sessies,
// dus includen (requiren) we session.php
require("../scripts/session.php");
mysql_query("UPDATE articles SET views = (views + 1) WHERE id=".$_GET['id']) or die(mysql_error());
   // Fetch the article category
   $rsc = mysql_query("SELECT category FROM articles WHERE id=".$_GET['id']) or die(mysql_error());
   $row = mysql_fetch_array($rsc);
      $cat = $row['category'];

  if (($cat == 2) && ((int)$_SESSION['slevel'] < 2)) {
      header("Location:accessdenied.php");
      exit(); //stop the script.
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>KB RBINS</title>
<link rel="stylesheet" type="text/css" href="../main.css" />
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
</head>
<body>
   <!-- Begin Wrapper -->
   <div id="wrapper">
         <!-- Begin Header -->
         <div id="header">
                  <h1>Knowledgebase System RBINS</h1>      
             </div>
             <!-- End Header -->
         <!-- Begin Faux Columns -->
             <div id="faux">            
                   <!-- Begin Left Column -->
                   <div id="leftcolumn">      
                     <?php
                            include("../scripts/checkuser.php");
                     ?>      
                   </div>
                   <!-- End Left Column -->
                   <!-- Begin Right Column -->
                   <div id="rightcolumn">      
                     <center><h2>Result</h2></center>            
                       <?php
                  $res=mysql_query("SELECT ID, title, article, author FROM articles WHERE id = ".$_GET['id']) or die(mysql_error()) ;
                  $r = mysql_fetch_array($res);
                  $article = nl2br($r['article']);
                  echo '<div class="result"><h3>KB'.$r['ID'].'&nbsp; - &nbsp;'.$r['title'].'</h3><br />';
                  echo $article;
                  $res2=mysql_query("SELECT score, counter, views FROM articles WHERE id = ".$_GET['id']) or die(mysql_error()) ;
                  $r2 = mysql_fetch_array($res2);
                  if ($r2['counter']=="0") {
                        echo '</div><div class="author"><h5>'.$r['author'].'</h5><h6>No grade has been given yet</h6></div>' ;}
                        else {
                        $r3=round ($r2['score']/$r2['counter'],2);//2 or less decimals
                        echo '</div><div class="author"><h5>'.$r['author'].'</h5><h6>Grade:&nbsp;'.$r3.'&nbsp;('.$r2['counter'].'&nbsp;vote(s))</h6><h6>Viewed:&nbsp;'.$r2['views'].'&nbsp;</h6></div>';}
                  ?>      
                  <br />
                  <?php
                        include("../scripts/counting.php");
                  ?>
                  <br />
                  <a href="../index.php">Another search?</a>
                     <div class="clear"></div>                    
                   </div>
                   <!-- End Right Column -->                    
                     <div class="clear"></div>                    
         </div>        
         <!-- End Faux Columns -->
         <!-- Begin Footer -->
         <div id="footer">                  
               <h4>Jo Vanattenhoven&copy;2007</h4>            
         </div>
             <!-- End Footer -->            
   </div>
   <!-- End Wrapper -->
</body>
</html>
<?php
ob_end_flush();
?>
0
 
LVL 21

Author Comment

by:jvuz
ID: 18756027
Perfect!
0
 
LVL 11

Expert Comment

by:elfe69
ID: 18756037
I knew that ;-)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now