jvuz
asked on
UPDATE mysql
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/sessio n.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:accessden ied.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/checku ser.php");
?>
</div>
<!-- End Left Column -->
<!-- Begin Right Column -->
<div id="rightcolumn">
<center><h2>Result</h2></c enter>
<?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'].'&nb sp; - '.$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['a uthor'].'< /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['a uthor'].'< /h5><h6>Gr ade: '.$r3.'&nb sp;('.$r2[ 'counter'] .' vo te(s))</h6 ></div>';}
?>
<br />
<?php
include("../scripts/counti ng.php");
?>
<br />
<a href="../index.php">Anothe r 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©2007</h 4>
</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
<?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/sessio
// 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:accessden
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/checku
?>
</div>
<!-- End Left Column -->
<!-- Begin Right Column -->
<div id="rightcolumn">
<center><h2>Result</h2></c
<?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[
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['a
else {
$r3=round ($r2['score']/$r2['counter
echo '</div><div class="author"><h5>'.$r['a
?>
<br />
<?php
include("../scripts/counti
?>
<br />
<a href="../index.php">Anothe
<div class="clear"></div>
</div>
<!-- End Right Column -->
<div class="clear"></div>
</div>
<!-- End Faux Columns -->
<!-- Begin Footer -->
<div id="footer">
<h4>Jo Vanattenhoven©2007</h
</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
not sure what do you want exactly?
ASKER
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.
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());
mysql_query("UPDATE articles SET views = (views + 1) WHERE id=$_GET[id]") or die(mysql_error());
mysql_query("UPDATE articles SET views = (views + 1) WHERE id='".$_GET[id]."'") or die(mysql_error());
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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/sessio n.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:accessden ied.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/checku ser.php");
?>
</div>
<!-- End Left Column -->
<!-- Begin Right Column -->
<div id="rightcolumn">
<center><h2>Result</h2></c enter>
<?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'].'&nb sp; - '.$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['a uthor'].'< /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['a uthor'].'< /h5><h6>Gr ade: '.$r3.'&nb sp;('.$r2[ 'counter'] .' vo te(s))</h6 ><h6>Viewe d: '. $r2['views '].' </h6></div >';}
?>
<br />
<?php
include("../scripts/counti ng.php");
?>
<br />
<a href="../index.php">Anothe r 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©2007</h 4>
</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
<?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/sessio
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:accessden
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/checku
?>
</div>
<!-- End Left Column -->
<!-- Begin Right Column -->
<div id="rightcolumn">
<center><h2>Result</h2></c
<?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[
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['a
else {
$r3=round ($r2['score']/$r2['counter
echo '</div><div class="author"><h5>'.$r['a
?>
<br />
<?php
include("../scripts/counti
?>
<br />
<a href="../index.php">Anothe
<div class="clear"></div>
</div>
<!-- End Right Column -->
<div class="clear"></div>
</div>
<!-- End Faux Columns -->
<!-- Begin Footer -->
<div id="footer">
<h4>Jo Vanattenhoven©2007</h
</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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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/sessio n.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:accessden ied.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/checku ser.php");
?>
</div>
<!-- End Left Column -->
<!-- Begin Right Column -->
<div id="rightcolumn">
<center><h2>Result</h2></c enter>
<?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'].'&nb sp; - '.$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['a uthor'].'< /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['a uthor'].'< /h5><h6>Gr ade: '.$r3.'&nb sp;('.$r2[ 'counter'] .' vo te(s))</h6 ><h6>Viewe d: '. $r2['views '].' </h6></div >';}
?>
<br />
<?php
include("../scripts/counti ng.php");
?>
<br />
<a href="../index.php">Anothe r 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©2007</h 4>
</div>
<!-- End Footer -->
</div>
<!-- End Wrapper -->
</body>
</html>
<?php
ob_end_flush();
?>
<?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/sessio
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:accessden
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/checku
?>
</div>
<!-- End Left Column -->
<!-- Begin Right Column -->
<div id="rightcolumn">
<center><h2>Result</h2></c
<?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[
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['a
else {
$r3=round ($r2['score']/$r2['counter
echo '</div><div class="author"><h5>'.$r['a
?>
<br />
<?php
include("../scripts/counti
?>
<br />
<a href="../index.php">Anothe
<div class="clear"></div>
</div>
<!-- End Right Column -->
<div class="clear"></div>
</div>
<!-- End Faux Columns -->
<!-- Begin Footer -->
<div id="footer">
<h4>Jo Vanattenhoven©2007</h
</div>
<!-- End Footer -->
</div>
<!-- End Wrapper -->
</body>
</html>
<?php
ob_end_flush();
?>
ASKER
Sorry, no changes.
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/sessio n.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:accessden ied.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/checku ser.php");
?>
</div>
<!-- End Left Column -->
<!-- Begin Right Column -->
<div id="rightcolumn">
<center><h2>Result</h2></c enter>
<?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'].'&nb sp; - '.$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['a uthor'].'< /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['a uthor'].'< /h5><h6>Gr ade: '.$r3.'&nb sp;('.$r2[ 'counter'] .' vo te(s))</h6 ><h6>Viewe d: '. $r2['views '].' </h6></div >';}
?>
<br />
<?php
include("../scripts/counti ng.php");
?>
<br />
<a href="../index.php">Anothe r 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©2007</h 4>
</div>
<!-- End Footer -->
</div>
<!-- End Wrapper -->
</body>
</html>
<?php
ob_end_flush();
?>
<?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/sessio
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:accessden
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/checku
?>
</div>
<!-- End Left Column -->
<!-- Begin Right Column -->
<div id="rightcolumn">
<center><h2>Result</h2></c
<?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[
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['a
else {
$r3=round ($r2['score']/$r2['counter
echo '</div><div class="author"><h5>'.$r['a
?>
<br />
<?php
include("../scripts/counti
?>
<br />
<a href="../index.php">Anothe
<div class="clear"></div>
</div>
<!-- End Right Column -->
<div class="clear"></div>
</div>
<!-- End Faux Columns -->
<!-- Begin Footer -->
<div id="footer">
<h4>Jo Vanattenhoven©2007</h
</div>
<!-- End Footer -->
</div>
<!-- End Wrapper -->
</body>
</html>
<?php
ob_end_flush();
?>
still the same error ?
ASKER
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?
I already looked at the places where there is FROM articles, but I don't see anything wrong. Do you?
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/sessio n.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:accessden ied.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/checku ser.php");
?>
</div>
<!-- End Left Column -->
<!-- Begin Right Column -->
<div id="rightcolumn">
<center><h2>Result</h2></c enter>
<?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'].'&nb sp; - '.$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['a uthor'].'< /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['a uthor'].'< /h5><h6>Gr ade: '.$r3.'&nb sp;('.$r2[ 'counter'] .' vo te(s))</h6 ><h6>Viewe d: '. $r2['views '].' </h6></div >';}
?>
<br />
<?php
include("../scripts/counti ng.php");
?>
<br />
<a href="../index.php">Anothe r 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©2007</h 4>
</div>
<!-- End Footer -->
</div>
<!-- End Wrapper -->
</body>
</html>
<?php
ob_end_flush();
?>
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/sessio
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:accessden
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/checku
?>
</div>
<!-- End Left Column -->
<!-- Begin Right Column -->
<div id="rightcolumn">
<center><h2>Result</h2></c
<?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[
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['a
else {
$r3=round ($r2['score']/$r2['counter
echo '</div><div class="author"><h5>'.$r['a
?>
<br />
<?php
include("../scripts/counti
?>
<br />
<a href="../index.php">Anothe
<div class="clear"></div>
</div>
<!-- End Right Column -->
<div class="clear"></div>
</div>
<!-- End Faux Columns -->
<!-- Begin Footer -->
<div id="footer">
<h4>Jo Vanattenhoven©2007</h
</div>
<!-- End Footer -->
</div>
<!-- End Wrapper -->
</body>
</html>
<?php
ob_end_flush();
?>
ASKER
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect!
I knew that ;-)