Greetings, all!
I have a database table with an individual ID number for each row. In a file such as "example.php", I'd like to pull up row #100 by entering the url "/example.php?id=100"
Would anyone please show me how to do this? I'd also like help with what sort of query I would need in order to pull up information for that row, such as "field1", and "field2" for me to display those fields in an html document. An example using the examples I provided in this post should be sufficient to help me accomplish what I need now and in the future. Much appreciation to anyone who can help me here!
Using a table's ID to pull up a page
Moderator: General Moderators
-
PoolWhirlz
- Forum Newbie
- Posts: 3
- Joined: Thu Apr 22, 2010 4:29 am
Re: Using a table's ID to pull up a page
you can get the id using get method
$id = $_GET['id];
and the query should be like this
$sql = "select * my table_name where id='$id'";
$result = mysql_query($sql) or die ("Error in selection");
$result1 = $result['field1];
$result2 = $result['field2];
print the fields like this
echo $result1;
echo $result2;
url should be like this http://example.com/example.php?id=100
i hope this helps you
$id = $_GET['id];
and the query should be like this
$sql = "select * my table_name where id='$id'";
$result = mysql_query($sql) or die ("Error in selection");
$result1 = $result['field1];
$result2 = $result['field2];
print the fields like this
echo $result1;
echo $result2;
url should be like this http://example.com/example.php?id=100
i hope this helps you
-
PoolWhirlz
- Forum Newbie
- Posts: 3
- Joined: Thu Apr 22, 2010 4:29 am
Re: Using a table's ID to pull up a page
Thanks, but I currently get this error:
Parse error: syntax error, unexpected T_VARIABLE, expecting ']' on line 6.
I think I fixed t by adding in a couple of apostrophes that were missing., but now I have this coming up:
[phpBB Debug] PHP Notice: in file (my file) on line 7: mysql_query() [function.mysql-query]: Access denied for user ''@'localhost' (using password: NO)
[phpBB Debug] PHP Notice: in file (my file) on line 7: mysql_query() [function.mysql-query]: A link to the server could not be established
Error in selection
It's something with this line:
Also, how do I go about using variables such as {field} in the html to pull the info from "field1"?
Parse error: syntax error, unexpected T_VARIABLE, expecting ']' on line 6.
I think I fixed t by adding in a couple of apostrophes that were missing., but now I have this coming up:
[phpBB Debug] PHP Notice: in file (my file) on line 7: mysql_query() [function.mysql-query]: Access denied for user ''@'localhost' (using password: NO)
[phpBB Debug] PHP Notice: in file (my file) on line 7: mysql_query() [function.mysql-query]: A link to the server could not be established
Error in selection
It's something with this line:
$result = mysql_query($sql) or die ("Error in selection");
Also, how do I go about using variables such as {field} in the html to pull the info from "field1"?
Re: Using a table's ID to pull up a page
1: @localhost error - for this u should connect to the database
the db should be connected with proper user name and pwd
2. T_STring error comes because u were missing semicolon in the line
if possible pls post the code
for more help
the db should be connected with proper user name and pwd
2. T_STring error comes because u were missing semicolon in the line
if possible pls post the code
for more help
-
PoolWhirlz
- Forum Newbie
- Posts: 3
- Joined: Thu Apr 22, 2010 4:29 am
Re: Using a table's ID to pull up a page
It is connected to the server, because I use the same DB connection for all other pages and even the page with the error is pulling up my session data, which is from the same exact database saying it can't connect to.