Current location: Hot Scripts Forums » Programming Languages » PHP » PHP and MySQL Help


PHP and MySQL Help

Reply
  #1 (permalink)  
Old 02-17-06, 07:02 AM
Ady Ady is offline
Newbie Coder
 
Join Date: Feb 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
PHP and MySQL Help

'pages' Table:
http://img106.imageshack.us/img106/2240/sig2409sm.jpg

PHP Code:

<?

include("config.php");
$sql "SELECT * FROM pages WHERE id='" mysql_escape_string($_GET['user']) . "'"
$result3=mysql_query($sql);
$rows2=mysql_fetch_array($result3);
$user2=$rows2['id'];
$key2=$rows2['key'];
$title2=$rows2['title'];
$body2=$rows2['body'];
if(
$user==$user2 && $page==$key2){ echo ('<b>' $title2 '</b><br>' $body2); };
?>
I'm sure I've done this right, but it doesn't work. I'm trying to make it so if you visit the page with ?user=#&page=#, it searches the table for rows with whatever $user and $page are. If they are both in the same row, then it displays 'title' and 'body' from that row. I hope someone understands what I'm talking about... any help is appreciated.

PS. Sorry my code is probably really messy, I'm not too good with PHP / MySQL.

EDIT: Fixed a little of the code.

Last edited by Ady; 02-17-06 at 07:26 AM.
Reply With Quote
  #2 (permalink)  
Old 02-17-06, 07:16 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
The $page variable is not set, and the $user variable neither. At least can't I see them. And are you sure the $user variable is a number and not a name?

The table looks kinda weird too. The entries are duplicated.
Reply With Quote
  #3 (permalink)  
Old 02-17-06, 07:40 AM
Ady Ady is offline
Newbie Coder
 
Join Date: Feb 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by nico_swd
The $page variable is not set, and the $user variable neither. At least can't I see them. And are you sure the $user variable is a number and not a name?

The table looks kinda weird too. The entries are duplicated.
$page should be what the ?page= is in the URL, and the same with $user. $user is also definatley a number. To make sure, I've echoed the variable and it comes up with a number. The 'id' column in the table just represents what user the page is assigned to.
Reply With Quote
  #4 (permalink)  
Old 02-17-06, 07:44 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Try replacing $page with $_GET["page"] then. Or is the variable somewhere else set?

And I'd strongly recommend not using numbers in the var names. This is only confusing.
Reply With Quote
  #5 (permalink)  
Old 02-17-06, 07:48 AM
Ady Ady is offline
Newbie Coder
 
Join Date: Feb 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by nico_swd
Try replacing $page with $_GET["page"] then. Or is the variable somewhere else set?

And I'd strongly recommend not using numbers in the var names. This is only confusing.
I've changed $page to $_GET["page"] now, but still no luck. I think I need to do this too:

PHP Code:

$sql "SELECT key FROM pages WHERE key='" mysql_escape_string($_GET['page']) . "'"
mysql_fetch_array($sql); 
But it just comes up saying:

Quote:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/smashroc/public_html/webedit/index.php on line 68
Reply With Quote
  #6 (permalink)  
Old 02-17-06, 07:52 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
You forgot the mysql_query()

PHP Code:

$sql mysql_query("SELECT key FROM pages WHERE key='" mysql_escape_string($_GET['page']) . "'"); 

mysql_fetch_array($sql); 
Reply With Quote
  #7 (permalink)  
Old 02-17-06, 08:02 AM
Ady Ady is offline
Newbie Coder
 
Join Date: Feb 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by nico_swd
You forgot the mysql_query()

PHP Code:

$sql mysql_query("SELECT key FROM pages WHERE key='" mysql_escape_string($_GET['page']) . "'"); 

mysql_fetch_array($sql); 
Oh yeh lol. It still comes up with the same thing though.
Reply With Quote
  #8 (permalink)  
Old 02-17-06, 08:10 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Try this.

PHP Code:

$sql mysql_query("SELECT * FROM pages WHERE key='" mysql_escape_string($_GET['page']) . "'"); 

mysql_fetch_array($sql); 
Reply With Quote
  #9 (permalink)  
Old 02-17-06, 08:15 AM
Ady Ady is offline
Newbie Coder
 
Join Date: Feb 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Still doesn't work. It's starting to annoy me now lol. Thanks for your help so far anyway. I appreciate it a lot.
Reply With Quote
  #10 (permalink)  
Old 02-17-06, 08:22 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Ok, try this then:

PHP Code:

$sql mysql_query("SELECT * FROM pages WHERE id='"$_GET["user"] ."' AND key='"$_GET["page"] ."'");

$row mysql_fetch_array($sql); 
Now call your-site.com/?user=1&key=page1

This should work.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
Need help with some php mysql TheTinkeringToad PHP 9 02-01-06 10:56 AM
IIS MYSQL and PHP nommiiss PHP 6 01-31-06 04:30 PM
RESELLER WEB HOSTING - $9.99/MONTH For 4GB HD & 30GB BW! CPanel, PHP, MySQL & MORE! IncognitoNet General Advertisements 0 11-25-04 02:09 AM
RESELLER WEB HOSTING - $9.99/MONTH For 4GB HD & 30GB BW! CPanel, PHP, MySQL & MORE! IncognitoNet General Advertisements 2 11-12-04 03:25 PM


All times are GMT -5. The time now is 06:34 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.