SitePoint Sponsor |
|
User Tag List
Results 1 to 20 of 20
Thread: How 2 Do THIS!!!!????
-
May 14, 2005, 03:46 #1
- Join Date
- Mar 2005
- Posts
- 832
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
How 2 Do THIS!!!!????
What is that code so i can make a variable like $username know to look in the username field in database and tell you the information?
Please reply fast.
-
May 14, 2005, 04:33 #2
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
It would be simple select
PHP Code://connect to the base
if(!($db = @mysql_connect(BASESERVER, BASEUSER, BASEPASS))) //connect to base host
die("Cannot connect to the base server.");
if(!@mysql_select_db(BASENAME,$db)) //select base
die("Database doesn't exist!!!");
//this is the actual query
$sql = "SELECT * FROM your_table WHERE Username = '".$username."'";
//perform query
if(($result = @mysql_query($sql,$db)) == 0) //Execute SQL query
{
echo "\n<HR>Database error: <B>".mysql_error()."</B><BR><BR>\n";
die("Query was (<B>$sql</B>) in file <B>$PHP_SELF</B>");
}
//get results
if(mysql_num_rows($result) == 0)
{
echo "No results";
}
else
{
$user = mysql_fetch_assoc($result);
}
-- Jelena --
-
May 14, 2005, 04:33 #3
- Join Date
- Dec 2004
- Location
- Whitley Bay, Tyne & Wear, UK
- Posts
- 246
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hope this helps. Did it as fast as i could
PHP Code:
$Query = @mysql_query(Select * from tablename);
if (!$Query) {
exit('<p>Error retrieving stuff from database!<br />'.
'Error: ' . mysql_error() . '<p>Try Later</p>');
}
while ($Tablename = mysql_fetch_array($Query)) {
$variable = $Tablename['itemname'];
$variable2 = $Tablename['itemname2'];
}
Keith
-
May 14, 2005, 05:06 #4
- Join Date
- Mar 2005
- Posts
- 832
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ok i am using kivisons code and on this part $Query = @mysql_query(Select * from tablename);
what do i add or delete i tried deleting * and adding username but it didnt work
-
May 14, 2005, 05:23 #5
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
you need
SELECT * FROM table WHERE Username = '".$username."'-- Jelena --
-
May 14, 2005, 05:39 #6
- Join Date
- Mar 2005
- Posts
- 832
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I get the error
Parse error: parse error, unexpected T_STRING in /home/chat/public_html/vars.php on line 3
The code on that line is
$Query = @mysql_query(SELECT * FROM table WHERE Username = '".$username."'
-
May 14, 2005, 05:42 #7
Originally Posted by Tidal Wave
PHP Code:$Query = @mysql_query("SELECT * FROM table WHERE Username='$Username'");
-
May 14, 2005, 05:54 #8
- Join Date
- Mar 2005
- Posts
- 832
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Error retrieving stuff from database!
Error: No Database Selected
Try Later
THATS THE ERROR IM GETTING NOW
-
May 14, 2005, 06:01 #9
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
You need to connect to db first as I posted before.
-- Jelena --
-
May 14, 2005, 06:16 #10
- Join Date
- Mar 2005
- Posts
- 832
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ok it works now but the filewont work.
Here is the vars.php file:
<?
include 'config.php';
$Query = @mysql_query("SELECT * FROM $table WHERE Username='$Username'");
if (!$Query) {
exit('<p>Error retrieving stuff from database!<br />'.
'Error: ' . mysql_error() . '<p>Try Later</p>');
}
while ($table = mysql_fetch_array($Query)) {
$username = $table['username'];
$variable2 = $Tablename['itemname2'];
}
?>
Here is the cpanel.php file:
<?
include 'config.php';
include 'vars.php';
echo "Hello $username here is your information:";
echo "<br>";
echo "First Name: $firstname";
echo "<br>";
echo "Last Name: $lastname";
echo "<br>";
echo "Email Address: $email";
echo "<br>";
?>
when i go to www.chat.ninechat.com/cpanel.php it should say hello $username ect.
-
May 14, 2005, 06:22 #11
- Join Date
- Mar 2005
- Posts
- 832
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Does anyone know how to make it work?
-
May 14, 2005, 06:26 #12
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
If username is unique then you don't need while part as it will return only one row, but I do recommend to check if your query returned any results with
PHP Code:if(mysql_num_rows($Query) == 0)
//no results
PHP Code:$user = mysql_fetch_assoc($Query)
-- Jelena --
-
May 14, 2005, 06:30 #13
- Join Date
- Mar 2005
- Posts
- 832
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
im confused you want me to make a php file named mysql_fetch_assoc.php and put in it:
if(mysql_num_rows($Query) == 0)
//no results
then in the file cpanel.php change $username = $table['username'];
to $user = mysql_fetch_assoc($Query)
is that right?
-
May 14, 2005, 06:31 #14
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
No, I want you to call those functions after performing your query.
And yes, echo in cpanel username as $user['Username']-- Jelena --
-
May 14, 2005, 06:37 #15
- Join Date
- Mar 2005
- Posts
- 832
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
im still confused isnt there a more simple way
-
May 14, 2005, 06:47 #16
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Huh... I don't think so.. This is the way I would use.
-- Jelena --
-
May 14, 2005, 07:54 #17
- Join Date
- Mar 2005
- Posts
- 832
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
so is there anyone else who can help me?
-
May 14, 2005, 08:51 #18
- Join Date
- Jan 2005
- Location
- Jackson, New Jersey
- Posts
- 218
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
honestly, Tidal, I think you need to read a tutorial. There's too much information for posts to help you. There are good ones on SitePoint, WebDev, even WebMonkey. Google "PHP MySQL tutorials" and I'm sure you'll get it.
Fesh
imagine what it's going to be like
-
May 14, 2005, 12:29 #19
- Join Date
- Oct 2003
- Location
- Your Monitor
- Posts
- 1,146
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Couple Questions::
1. Is your Username column in the database username or Username -- it matters.
2. Is your $table variable set? Try echoing it out and see what happens. If you don't have a table name than it won't return any values. Also remember that variable set within a function are only available within the function itself unless set otherwise.
-
May 14, 2005, 12:30 #20
- Join Date
- Oct 2003
- Location
- Your Monitor
- Posts
- 1,146
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
BTW -- What's not working now? Can you post the code as it appears now? I'd be more than happy to give it a shot!
Bookmarks