|
|
|
|
![]() ![]() |
Apr 10 2007, 10:39 PM
Post
#1
|
|
|
Sparkx Group: [HOSTED] Posts: 355 Joined: 11-October 06 From: Dana Point, CA, USA Member No.: 16,496 |
OK so can anyone show me a file that will connect to an sql server with an user inputed quary? So here is an example of what I want to do:
You go to a page to find information about James, you would type in example.php?user=James and the page would find all the data about James (all the tables), then display it as an echo. I already have my users set as unique variables so only one person's information would be echoed. The page name and "user" variable doesn't matter. Do you understand me? I am having trouble explaining it. If someone could show me a code that does this, that would be great and I would add onto your reputation. Thank you very much, Sparkx |
|
|
|
Apr 11 2007, 12:19 AM
Post
#2
|
|
|
Way Out Of Control - You need a life :) Group: Members Posts: 1,086 Joined: 21-June 05 From: New York Member No.: 6,440 |
Hi sparkx, I think I know what you are referring to. You want it to print out all the user DATABASE related information right? I'm not very strong in the SQL area yet, but found a PHP file with the code that might be of some help if you are some what knowledgeable on SQL:
http://forum.mamboserver.com/archive/index.php/t-33885.html This script looks through the database and filters out the specified prefix. You should be able to modify it so it will filter by the database username James and display all the tables in a webpage. |
|
|
|
Apr 11 2007, 06:04 AM
Post
#3
|
|
|
Premium Member Group: [HOSTED] Posts: 377 Joined: 17-June 06 From: Adblock life Member No.: 13,992 |
Hmmm...well, in order to do that, you'd have to use the HTML "GET" variable in your forms. So it'd look something like this:
CODE <form action="example.php" method="get"> Then, you'd have one of your form fields called "user" and then in example.php you'd get the name (in this case James) from that form field called "user". You can then use that name in your SQL query to get the information based on the name and print that information out. That way, if you ever access the url example.php?user=James, it'll always use the name in its SQL query to get and print information about James because the ?user=James refers to the GET form field "user" which is filled in by the url to be "James". Sorry if that wasn't too clear. Perhaps a Google of HTML get method would help plenty. :-) This post has been edited by Arbitrary: Apr 11 2007, 06:05 AM |
|
|
|
Apr 11 2007, 08:27 AM
Post
#4
|
|
|
Nenad Bozidarevic Group: [MODERATOR] Posts: 1,013 Joined: 7-November 05 From: Belgrade, Serbia Member No.: 9,500 |
As for the PHP part of the code, you need to retrieve the data from the database. Here's how it would roughly look:
CODE $user = $_GET['user']; $query = "SELECT * FROM `table` WHERE `user` = '$user'"; $result = mysql_query($query); $row = mysql_fetch_array($result); Of course, there would have to be some validation because of security, but it would end up looking like this. First we get the username, set up the query, and then run it. Then, we move all the data to an array ($row). In order to use it, you will ned $row['column'], where column is the column name in the database. |
|
|
|
Apr 11 2007, 10:35 PM
Post
#5
|
|
|
Sparkx Group: [HOSTED] Posts: 355 Joined: 11-October 06 From: Dana Point, CA, USA Member No.: 16,496 |
Thank you all very much for the help. The codes look like they will probably work. I will try them this weekend when I get the time. I am still learning SQL (in odd ways) just like I always do I learn the hard stuff first and need the more detailed instructions later. I was also trying to learn some C++ last weekend also. Who said you can't learn two languages at a time.
Thanks again, Sparkx I will add onto your reputation once I try out the scripts so don't worry, I didn't forget. |
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
Lo-Fi Version | Time is now: 13th October 2008 - 12:35 AM |