Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-17-2007, 09:26 PM   PM User | #1
mlmorg
Regular Coder

 
Join Date: Mar 2007
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts
mlmorg is an unknown quantity at this point
php mysql $id problem

Hi all,
I'm very new to php mysql but have been learning from http://www.freewebmasterhelp.com/tutorials/phpmysql/1

I have set up a web page and my home page (the one that displays what is in my database) works nicely; however, my edit page does not work unless I specify the exact id number I want to edit. Even though there's currently only one row in my database, if I have:

PHP Code:
$query="SELECT * FROM home WHERE id='$id'"
on my edit page, the page doesn't display; however, if I do:

PHP Code:
$query="SELECT * FROM home WHERE id='1'"
It works. The page I'm working on http://www.katherinewagnerdesigns.co...ford/index.php is set up with two "posts". One titled "Movies in the Park," the other "Annual Flea Market and Crafts Fair." Since I just started learning php mysql, only the first post uses php (the second one html for now). The edit page, http://www.katherinewagnerdesigns.co...lford/edit.php right now is set up with id=1 but I would like to have it so the edit page has every post on it, with the ability to add new posts and edit/delete old ones. So, it seems that this problem I'm having will stop me from being able to do this unless I can get it to work and auto-increment down the page each successive id post.

I hope this makes sense to everyone...sorry I'm still learning this. Thanks for any help anyone can give me. Matt

Last edited by mlmorg; 07-17-2007 at 09:51 PM..
mlmorg is offline   Reply With Quote
Old 07-17-2007, 09:46 PM   PM User | #2
whizard
Senior Coder

 
whizard's Avatar
 
Join Date: Jan 2005
Location: Philadelphia, PA, USA
Posts: 1,457
Thanks: 10
Thanked 37 Times in 37 Posts
whizard will become famous soon enoughwhizard will become famous soon enough
I think what you might want to do is have a couple different pages: one to add a new post, one to view all the current posts, and one to edit posts.

So, your page to show all the post could have a link at the bottom along the lines of "Click here to add new post", which would point to the new post script. Then, the page would also list all the current posts with a link next to them that says "Click here to edit post", and point to edit.php?id=ID where ID is equal to that post's id in the database. Then you could use the more dynamic query you already have set up in edit.php to edit the requested article

HTH
Dan
__________________
If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.
Step 1: Learn. Step 2: Search. Step 3: Post here.

Last edited by whizard; 07-17-2007 at 09:58 PM.. Reason: I seemed to mistype a word in such a fashion as to confuse the filter
whizard is offline   Reply With Quote
Old 07-17-2007, 09:55 PM   PM User | #3
CFMaBiSmAd
Senior Coder

 
CFMaBiSmAd's Avatar
 
Join Date: Oct 2006
Location: Denver, Colorado USA
Posts: 2,711
Thanks: 2
Thanked 251 Times in 243 Posts
CFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the rough
Actually, this is php problem because the query is only doing what you tell it to. I suspect that the $id variable is empty.

Echo out your $query variable after you assign the string to it to see if it contains the expected contents (any debugging involves finding at what point the data is the expected or when it is not and tracing back through the code/data to find out why it is not as expected.)

If you find that the $id variable is empty or contains something other than the record number you are trying to display, back track through the program execution path until you find out why it does not contain the expected value.
__________________
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.
CFMaBiSmAd is offline   Reply With Quote
Old 07-17-2007, 10:06 PM   PM User | #4
mlmorg
Regular Coder

 
Join Date: Mar 2007
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts
mlmorg is an unknown quantity at this point
CF it looks like you were right...I checked in phpmyadmin and the id was set to 1...But I assume $id starts at 0...so I changed it to 0 and it seemed to work. Thanks very much!

Now is there a way to set up the edit page so that it displays however many posts there are in that database table? Maybe I would use some sort of if statement..."If there is another row in this table, then display those values here"
mlmorg is offline   Reply With Quote
Old 07-17-2007, 10:09 PM   PM User | #5
whizard
Senior Coder

 
whizard's Avatar
 
Join Date: Jan 2005
Location: Philadelphia, PA, USA
Posts: 1,457
Thanks: 10
Thanked 37 Times in 37 Posts
whizard will become famous soon enoughwhizard will become famous soon enough
$query = "SELECT * FROM table";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
$row['title']."&nbsp;<br />";
}

Something like that should work
__________________
If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.
Step 1: Learn. Step 2: Search. Step 3: Post here.
whizard is offline   Reply With Quote
Old 07-17-2007, 10:26 PM   PM User | #6
mlmorg
Regular Coder

 
Join Date: Mar 2007
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts
mlmorg is an unknown quantity at this point
*edit*
Nevermind, figured it all out. Thanks for the help in pushing me forward guys, it's greatly appreciated.

Thanks, Matt

Last edited by mlmorg; 07-18-2007 at 01:08 AM..
mlmorg is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 +1. The time now is 10:10 AM.


Advertisement
Log in to turn off these ads.