Previous Thread
Next Thread
Print Thread
Rate Thread
#18733 07/09/03 05:39 PM
Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
OP Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
Ok, I'm playing with MySQL (I don't know it for my life), I believe I have this down right (it's my first time doin this so feel free to tear it apart) but it won't work, anyone have any ideas?

DB:
Code
CREATE TABLE applications ( 
	name varchar(20), 
	nick varchar(20), 
	telephone varchar(50), 
	cellular varchar(50), 
	date varchar(20), 
	chance varchar(4), 
	complete varchar(4), 
	address varchar(50), 
	citystzip varchar(75), 
	age varchar(4), 
	email varchar(75), 
	aim varchar(20), 
	irc varchar(20), 
	ubb varchar(20), 
	username varchar(20), 
	password varchar(20), 
        sections varchar(100), 
	yob varchar(4), 
	admin varchar(4), 
	staff varchar(4), 
	wantadmin varchar(4), 
	wantmod varchar(4), 
	wantnews varchar(4), 
	wasadmin varchar(4), 
	wasmod varchar(4), 
	wasnews varchar(4), 
	notes varchar(255),
	id int(4) NOT NULL auto_increment, 
	PRIMARY KEY (id), 
	UNIQUE id (id)
)TYPE=MyISAM;
PHP Page:


Code
<?php
$db = mysql_connect("localhost", "[user]", "[pass]");
mysql_select_db("undergroundc",$db);
$result = mysql_query("SELECT * FROM applications",$db);
printf("Name %s
\n", mysql_result($result,0,"name"));
printf("Nick %s
\n", mysql_result($result,0,"nick"));
printf("Telephone %s
\n", mysql_result($result,0,"telephone"));
printf("Cellular %s
\n", mysql_result($result,0,"cellular"));
printf("Date %s
\n", mysql_result($result,0,"date"));
printf("Chance %s
\n", mysql_result($result,0,"chance"));
printf("Complete %s
\n", mysql_result($result,0,"complete"));
printf("Address %s
\n", mysql_result($result,0,"address"));
printf("City, ST, Zip %s
\n", mysql_result($result,0,"citystzip"));
printf("Age %s
\n", mysql_result($result,0,"age"));
printf("E-Mail %s
\n", mysql_result($result,0,"email"));
printf("AIM %s
\n", mysql_result($result,0,"aim"));
printf("IRC %s
\n", mysql_result($result,0,"irc"));
printf("UBB %s
\n", mysql_result($result,0,"ubb"));
printf("Username %s
\n", mysql_result($result,0,"username"));
printf("Password %s
\n", mysql_result($result,0,"password"));
printf("Sections %s
\n", mysql_result($result,0,"sections"));
printf("Birth Year %s
\n", mysql_result($result,0,"yob"));
printf("Admin %s
\n", mysql_result($result,0,"admin"));
printf("Staff %s
\n", mysql_result($result,0,"staff"));
printf("Wants Admin %s
\n", mysql_result($result,0,"wantadmin"));
printf("Wants Mod %s
\n", mysql_result($result,0,"wantmod"));
printf("Wants News %s
\n", mysql_result($result,0,"wantnews"));
printf("Was Admin %s
\n", mysql_result($result,0,"wasadmin"));
printf("Was Mod %s
\n", mysql_result($result,0,"wasmod"));
printf("Was News %s
\n", mysql_result($result,0,"wasnews"));
printf("Notes %s
\n", mysql_result($result,0,"notes"));
?>
I just want it to load the data in the db so that i can play around, but it keeps 500 erroring on me frown ...

FYI, yes, this is for the application system, eventually anyway lol...


*sorry Having to scroll was bugging me. �in_tax *


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#18734 07/09/03 11:03 PM
Joined: Mar 2002
Posts: 256
Likes: 1
UGN Security Staff
Offline
UGN Security Staff
Joined: Mar 2002
Posts: 256
Likes: 1
Well, theres a few things...
I have noticed I get a 500 error when Apache can't find my php.

Code
$result = mysql_query("SELECT * FROM applications",$db);
could more properly be

Code
$result = mysql_query("SELECT * FROM `applications`",$db);
And I have no [censored] clue if this is valid PHP but it looks like you went C style. So here is how I would do it.

Code
printf("Name %s
\n", mysql_result($result,0,"name"));
=

Code
echo("Name " .  mysql_result($result,0,"name") . "
\n",);
But even then that doesn't look like it would work but I am unaware of a mysql_result function so I don't know.. heres the final way it would look for me.

[code]
foreach($r as mysql_fetch_array($result)) {
echo "all your stuff: " . $r["name"];
}

#18735 07/09/03 11:04 PM
Joined: Mar 2002
Posts: 256
Likes: 1
UGN Security Staff
Offline
UGN Security Staff
Joined: Mar 2002
Posts: 256
Likes: 1
oh yes. ph33r the spacing because of gay ubb

#18736 08/01/03 08:35 PM
Joined: Jul 2003
Posts: 14
S
Junior Member
Offline
Junior Member
S
Joined: Jul 2003
Posts: 14
Here is how i would retreive rows from a mysql database using php. I like OO programming so i will retreive the rows as objects.

Code
// db parameters
define ('MYSQL_HOST', 'localhost');
define ('MYSQL_USER','db_username');
define ('MYSQL_PASS','db_password');
define ('MYSQL_DB','db_name');

mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_PASS);  // connect to mysql server
mysql_select_db(MYSQL_DB);   // select database
$query = "select * from table_name";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_object($result))
{
    // loop through all the rows returned int he $row object assuming you know the column names
    echo "Name : ".$row->name;
    echo "
Username : ".$row->username;
    echo "Password : ".$row->password;
    echo "Email : ".$row->email;
    // ......... more ..........
    
}
This is how i would do it. Hope this helped you out a little.

#18737 08/05/03 11:44 AM
Joined: Dec 2002
Posts: 3,255
Likes: 3
UGN Elite
Offline
UGN Elite
Joined: Dec 2002
Posts: 3,255
Likes: 3
Gizzy... I think this is what you want. I am not familar with %s and
and \n are the same thing. But here is what I came up with

Code
CREATE TABLE applications ( 
	name varchar(20), 
	nick varchar(20), 
	telephone varchar(50), 
	cellular varchar(50), 
	date varchar(20), 
	chance varchar(4), 
	complete varchar(4), 
	address varchar(50), 
	citystzip varchar(75), 
	age varchar(4), 
	email varchar(75), 
	aim varchar(20), 
	irc varchar(20), 
	ubb varchar(20), 
	username varchar(20), 


	psswd varchar(20), 


	sections varchar(100), 
	yob varchar(4), 
	admin varchar(4), 
	staff varchar(4), 
	wantadmin varchar(4), 
	wantmod varchar(4), 
	wantnews varchar(4), 
	wasadmin varchar(4), 
	wasmod varchar(4), 
	wasnews varchar(4), 
	notes varchar(255),
	id int(4) NOT NULL auto_increment, 
	PRIMARY KEY (id), 
	UNIQUE id (id)
)TYPE=MyISAM;
notice I re-named your password field. I ran into issues with the word "password" in my code. I think it is reserved for HTML or PHP or some crap like that. Trust me, re-name it now saves big head aches later.


Code
$db = mysql_connect("localhost", "[user]", "[pass]");
	mysql_select_db("undergroundc",$db);
		$result = mysql_query("SELECT * FROM applications");
//
//
/*all you needed to do was pull the results out
in a loop.  It took all data from the table and 
put it in an array.*/
//
//
		while($result2 = mysql_fetch_array($result)){



			echo "Name 
\n, ".$result2['name'].";
			echo "Nick 
\n, ".$result2['nick'].";
			echo "Telephone 
\n, ".$result2['telephone'].";
			echo "Cellular 
\n, ".$result2['cellular'].";
			echo "Date 
\n, ".$result2['date'].";
			echo "Chance 
\n, ".$result2['chance'].";
			echo "Complete 
\n, ".$result2['complete'].";
			echo "Address 
\n, ".$result2['address'].";
			echo "City, ST, Zip 
\n, ".$result2['citystzip'].";
			echo "Age 
\n, ".$result2['age'].";
			echo "E-Mail 
\n, ".$result2['email'].";
			echo "AIM 
\n, ".$result2['aim'].";
			echo "IRC 
\n, ".$result2['irc'].";
			echo "UBB 
\n, ".$result2['ubb'].";
			echo "Username 
\n, ".$result2['username'].";
			echo "Password 
\n, ".$result2['password'].";
			echo "Sections 
\n, ".$result2['sections'].";
			echo "Birth Year 
\n, ".$result2['yob'].";
			echo "Admin 
\n, ".$result2['admin'].";
			echo "Staff 
\n, ".$result2['staff'].";
			echo "Wants Admin 
\n, ".$result2['wantadmin'].";
			echo "Wants Mod 
\n, ".$result2['wantmod'].";
			echo "Wants News 
\n, ".$result2['wantnews'].";
			echo "Was Admin 
\n, ".$result2['wasadmin'].";
			echo "Was Mod 
\n, ".$result2['wasmod'].";
			echo "Was News 
\n, ".$result2['wasnews'].";
			echo "Notes 
\n, ".$result2['notes'].";
		}

?>
if this dosen't work take the commas out.

Code
echo "Notes 
\n, ".$result2['notes'].";
                  ^
              Those commas
notice how I called the while loop

Code
while($result2 = mysql_fetch_array($result)){
it takes the data from

Code
$result = mysql_query("SELECT * FROM applications");
and throws it into an array called $result2

The While loop is going through the table line by line(by that I mean row by row). So we call our variable like so

Code
$array_name['colum_name']
Hope this helps

#18738 08/24/03 01:14 AM
Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
OP Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
Learner, now I'm getting:
Quote:
Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in c:\program files\easyphp\www\test.php on line 9
The code i'm using is:
Code
<?php
$db = mysql_connect("localhost", "[user]", "[pass]");
	mysql_select_db("applications",$db);
		$result = mysql_query("SELECT * FROM applications");

		while($result2 = mysql_fetch_array($result)){

			echo "Name 
\n ".$result2['name'].";
			echo "Nick 
\n ".$result2['nick'].";
			echo "Telephone 
\n ".$result2['telephone'].";
			echo "Cellular 
\n ".$result2['cellular'].";
			echo "Date 
\n ".$result2['date'].";
			echo "Chance 
\n ".$result2['chance'].";
			echo "Complete 
\n ".$result2['complete'].";
			echo "Address 
\n ".$result2['address'].";
			echo "City, ST, Zip 
\n ".$result2['citystzip'].";
			echo "Age 
\n ".$result2['age'].";
			echo "E-Mail 
\n ".$result2['email'].";
			echo "AIM 
\n ".$result2['aim'].";
			echo "IRC 
\n ".$result2['irc'].";
			echo "UBB 
\n ".$result2['ubb'].";
			echo "Username 
\n ".$result2['username'].";
			echo "Password 
\n ".$result2['password'].";
			echo "Sections 
\n ".$result2['sections'].";
			echo "Birth Year 
\n ".$result2['yob'].";
			echo "Admin 
\n ".$result2['admin'].";
			echo "Staff 
\n ".$result2['staff'].";
			echo "Wants Admin 
\n ".$result2['wantadmin'].";
			echo "Wants Mod 
\n ".$result2['wantmod'].";
			echo "Wants News 
\n ".$result2['wantnews'].";
			echo "Was Admin 
\n ".$result2['wasadmin'].";
			echo "Was Mod 
\n ".$result2['wasmod'].";
			echo "Was News 
\n ".$result2['wasnews'].";
			echo "Notes 
\n ".$result2['notes'].";
		}
?>


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#18739 08/24/03 01:16 AM
Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
OP Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
Note that line 9 would be:
Code
echo "Nick 
\n ".$result2['nick'].";


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#18740 08/24/03 01:37 AM
Joined: Mar 2002
Posts: 122
Member
Offline
Member
Joined: Mar 2002
Posts: 122
you have one too many quotes on each line it looks like...

#18741 08/25/03 04:27 AM
Joined: Jul 2003
Posts: 14
S
Junior Member
Offline
Junior Member
S
Joined: Jul 2003
Posts: 14
Gizmo,

Instead of ending all your echo lines with
.";
end them with just
;

And why are you using
and \n ?

If my fist suggestion doesn't work erase the \n from all your echo lines

#18742 08/25/03 07:32 AM
Joined: Aug 2003
Posts: 9
B
Aptenodytes Forsteri
Offline
Aptenodytes Forsteri
B
Joined: Aug 2003
Posts: 9
Along with the suggestions, to return an assoc array, mysql_fetch_array does not do this. It returns a 1 dimensional array, not a hash. This either needs to be changed to mysql_fetch_array($result, MYSQL_ASSOC) or use the mysql_fetch_assoc() function. Doesn't matter really. (Small millisecond diff)
Code
<?php
$db = mysql_connect("localhost", "[user]", "[pass]");
mysql_select_db("applications",$db);
$result = mysql_query("SELECT * FROM `applications`");
while($result2 = mysql_fetch_array($result, MYSQL_ASSOC)) {
	echo "Name 
\n ".$result2['name'];
	echo "Nick 
\n ".$result2['nick'];
	echo "Telephone 
\n ".$result2['telephone'];
	echo "Cellular 
\n ".$result2['cellular'];
	echo "Date 
\n ".$result2['date'];
	echo "Chance 
\n ".$result2['chance'];
	echo "Complete 
\n ".$result2['complete'];
	echo "Address 
\n ".$result2['address'];
	echo "City, ST, Zip 
\n ".$result2['citystzip'];
	echo "Age 
\n ".$result2['age'];
	echo "E-Mail 
\n ".$result2['email'];
	echo "AIM 
\n ".$result2['aim'];
	echo "IRC 
\n ".$result2['irc'];
	echo "UBB 
\n ".$result2['ubb'];
	echo "Username 
\n ".$result2['username'];
	echo "Password 
\n ".$result2['password'];
	echo "Sections 
\n ".$result2['sections'];
	echo "Birth Year 
\n ".$result2['yob'];
	echo "Admin 
\n ".$result2['admin'];
	echo "Staff 
\n ".$result2['staff'];
	echo "Wants Admin 
\n ".$result2['wantadmin'];
	echo "Wants Mod 
\n ".$result2['wantmod'];
	echo "Wants News 
\n ".$result2['wantnews'];
	echo "Was Admin 
\n ".$result2['wasadmin'];
	echo "Was Mod 
\n ".$result2['wasmod'];
	echo "Was News 
\n ".$result2['wasnews'];
	echo "Notes 
\n ".$result2['notes'];
}
mysql_free_result($result);
mysql_close($db);
?>

#18743 08/25/03 09:36 AM
Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
OP Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
mmmm, works...


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#18744 10/03/03 03:41 AM
Joined: Oct 2003
Posts: 7
L
Junior Member
Offline
Junior Member
L
Joined: Oct 2003
Posts: 7
Sorry for leaving you hanging. how is it going?

#18745 10/03/03 03:54 AM
Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
OP Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
gave up for a bit lol, i'd have to find my documentation wherever I left it lol... Been busy with other things... god I need to hire some PHP/MySQL guys here smirk


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#18746 10/04/03 03:57 PM
Joined: Oct 2003
Posts: 7
L
Junior Member
Offline
Junior Member
L
Joined: Oct 2003
Posts: 7
What you paying? :*


Link Copied to Clipboard
Member Spotlight
Posts: 43
Joined: November 2002
Forum Statistics
Forums41
Topics33,840
Posts68,858
Average Daily Posts1
Members2,176
Most Online3,253
Jan 13th, 2020
Latest Postings
Where and how do you torrent?
by danni75 - 03/01/24 05:58 AM
Animation,
by JohanKaariainen - 08/15/19 01:18 AM
Blackbeard.....
by Gremelin - 10/03/18 07:02 PM
my old account still exists!
by Crime - 08/10/18 02:47 PM
Okay WTF?
by HenryMiring - 09/27/17 01:45 AM
The History Thread...
by Gremelin - 08/11/17 12:11 PM
My friend NEEDS your HELP!
by Lena01 - 07/21/17 12:06 AM
I'm having fun with this guy.
by gabithompson730 - 07/20/17 01:50 AM
I want to upgrade my phone
by gabithompson730 - 07/20/17 01:49 AM
Doom 3
by Cyrez - 09/11/14 08:58 PM
Amazon Gift Card Generator/KeyGen?te
by Gecko666 - 08/22/14 09:21 AM
AIM scene 99-03
by lavos - 09/02/13 08:06 AM
Planetside 2
by Crime - 03/04/13 07:10 AM
Beta Testers Wanted
by Crime - 03/04/13 06:55 AM
Hello Everyone
by Gremelin - 02/12/12 06:01 PM
Tracfone ESN Generator
by Zanvin Green - 01/18/12 01:31 PM
Python 3 issue
by Testing - 12/17/11 09:28 PM
tracfone airtime
by Drache86 - 07/30/11 03:37 AM
Backdoors and the Infinite
by ZeroCoolStar - 07/10/11 03:52 AM
HackThisZIne #12 Releaseed!
by Pipat2 - 04/28/11 09:20 PM
gang wars? l33t-wars?
by Gremelin - 04/28/11 05:56 AM
Consolidate Forums
by diggin2deep - 04/21/11 10:02 AM
LAN Hacking Noob
by Gremelin - 03/12/11 12:42 AM
Top Posters
UGN Security 41,392
Gremelin 7,203
§intå× 3,255
SilentRage 1,273
Ice 1,146
pergesu 1,136
Infinite 1,041
jonconley 955
Girlie 908
unreal 860
Top Likes Received
Ghost 2
unreal 1
Crime 1
Ice 1
Dartur 1
Powered by UBB.threads™ PHP Forum Software 7.7.5