logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 04-22-2012, 02:13 AM   #1
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default from mysql table

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
tony09uk is offline   Reply With Quote
Old 04-22-2012, 02:34 AM   #2
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,175
Default

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";
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 04-22-2012, 09:28 PM   #3
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default

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 is offline   Reply With Quote
Old 04-22-2012, 11:15 PM   #4
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default

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
tony09uk is offline   Reply With Quote
Old 04-23-2012, 02:35 AM   #5
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,175
Default

no problem, not the last time you do something like that i promise you.
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:48 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com