|
Posted by Norman Peelman on 07/31/05 01:32
"Steve" <ThisOne@Aint.Valid> wrote in message
news:pan.2005.07.29.04.47.55.712979@Aint.Valid...
> On Thu, 28 Jul 2005 09:21:58 -0700, Maximus wrote:
>
> > <?
> > session_start();
> > require_once('db.inc.php');
> > $id=$_GET['id'];
> > if(!$id) {
> > header('Location: main.php');
> > } else {
> >
> > mysql_select_db("tbl_posts")
> > $sql=mysql_query"SELECT * FROM tbl_posts WHERE post_id ='" .$id. "'";
> > $r=mysql_fetch_array($sql);
> > }
> > ?>
> >
> > can anyone tell me what's wrong with this code? it keeps givin me:
> >
> > Parse error: syntax error, unexpected T_VARIABLE in C:\Program
> > Files\Apache Group\Apache2\htdocs\secretBox\viewtopic.php on line 10
>
> 2 mistakes... and that kind of indentation of braces was designed to save
> paper on a teletype. Now I'm old enough to remember using a tty43, but I
> don't *ever* use this style!
>
> Steve
>
> <?
> session_start();
> require_once('db.inc.php');
> $id=$_GET['id'];
> if(!$id)
> {
> header('Location: main.php');
> }
> else
> {
>
> mysql_select_db("tbl_posts");
> $sql=mysql_query ("SELECT * FROM tbl_posts WHERE post_id ='" .$id. "'");
> $r=mysql_fetch_array($sql);
> }
> ?>
That and,
$sql=mysql_query ("SELECT * FROM tbl_posts WHERE post_id = '$id'");
will work just fine if you are sure you need quotes around $id, or just
$sql=mysql_query ("SELECT * FROM tbl_posts WHERE post_id = $id");
if not... all that quoting when there is no need to can drive a person
crazy!
Try:
session_start();
require_once('db.inc.php');
if(!isset($_GET['id']))
{ // request variable 'id' is not set, dump back to main
header('Location: main.php');
}
else
{ // request variable 'id' is set, let's get the data
// add any error checking on 'id' here, ie: $_GET['id'] < 0, etc.
mysql_select_db('tbl_posts')
$sql=mysql_query("SELECT * FROM tbl_posts WHERE post_id = $_GET[id]");
// this line is not a typo!
$r=mysql_fetch_array($sql);
}
.... also, you can substitute $_GET and $_POST with $_REQUEST if you don't
care how 'id' is passed to your script.
Norm
---
FREE Avatar hosting at www.easyavatar.com
Navigation:
[Reply to this message]
|