PDA

View Full Version : from mysql table


tony09uk
04-22-2012, 01:13 AM
I have a mysql table which I am trying to pull results from. The idea is the user can select an article from another page and be redirected to a modify page. The table is:

article

the rows in it are:

article_id user_id title content date

The code ive used is:

if(!isset($_POST['submit'])){
$article = "SELECT * FROM article WHERE article_id = $_GET[id]";
$result = mysql_query($article);
$news = mysql_fetch_array($result);
}

I can see the problem is with my sql command, but I cant work out where. I have used var_dump() which has returned NULL

edbr
04-22-2012, 01:34 AM
echo $_GET['id'] to check the value or what i do for debug is something like

$id= ( add a value, and can later replace it with $_GET['id'] ) ;

$article = "SELECT * FROM article WHERE article_id = $id";

tony09uk
04-22-2012, 08:28 PM
Okay, now Ive tried this:

if(!isset($_POST['submit'])){
$id = $_GET['id'];
$article = "SELECT * FROM article WHERE article_id = $id";
var_dump($article);
echo "<br/>";
$result = mysql_query($article);
var_dump($result);
$news = mysql_fetch_array($result);
}

output

string(42) "SELECT * FROM article WHERE article_id = 1"
bool(false)
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\noTuts\news\modify.php on line 29

I have left the var_dump() in there just to show the results.

I feeling lost, if you are unable to advise with what Ive provided could you please tell me what could I read up on to try and understand/learn where im going wrong

tony09uk
04-22-2012, 10:15 PM
So sorry for wasting your time. I made a mistake which I guess is a beginner error :( I didnt connect to the database on that page ooopppsss :oops:

edbr
04-23-2012, 01:35 AM
no problem, not the last time you do something like that i promise you.