Go to Post ...if you don't ask, you won't get. - Billfred [more]
Home
Go Back   Chief Delphi > Technical > IT / Communications > Website Design/Showcase
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 16-06-2004, 11:25
Joshua May's Avatar
Joshua May Joshua May is offline
Go Bears!
FRC #1110 (Binary Bulldogs)
Team Role: College Student
 
Join Date: Nov 2003
Rookie Year: 2003
Location: Berkeley, CA
Posts: 1,306
Joshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond repute
Send a message via AIM to Joshua May
MySQL Problem

I am trying to learn working with MySQL databases through PHP but I'm having some problems. I've written this simple scipt which takes a table named "contacts" and first enters some information into the table. Then, it attempts to read and display the data in the table.

Here's the full code:
PHP Code:
<?php
$username 
"username";
$password "password";
$database "hhsrobotics_circuitrunners_com_-_ContactList";

$link mysql_connect(localhost,$username,$password);

@
mysql_select_db($database) or die( "Unable to select database");

$query "INSERT INTO contacts VALUES ('','John','Smith','555-555-5555','444-444-4444','333-333-3333','johnsmith@email.com','http://www.johnsmith.com')";

mysql_query($query);

$result mysql_query("SELECT * FROM contacts",$link);

$num mysql_numrows($result);

$i=0;
while (
$i $num) {

$first mysql_result($result,$i,"first");
$last mysql_result($result,$i,"last");
$phone mysql_result($result,$i,"phone");
$mobile mysql_result($result,$i,"mobile");
$fax mysql_result($result,$i,"fax");
$email mysql_result($result,$i,"email");
$web mysql_result($result,$i,"web");

echo 
"<b>$first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Fax: $fax<br>E-mail: $email<br>Web: $web<br>";

$i++;
}

mysql_close();
?>
The problem is that I keep getting argument errors with the lines
PHP Code:
$result mysql_query("SELECT * FROM contacts",$link); 
PHP Code:
$num mysql_numrows($result); 
and all of the
PHP Code:
$first mysql_result($result,$i,"first"); 
lines.

Oh, and there is a primary key in the first part of the table named "id" which is not displayed to the user, and its set to Auto_incriment so the data doesn't have to be entered for it.
__________________
The FIRST Wiki - openFIRST - Ultimate Robot Challenge - URC Wiki
I currently have 50 GMail invites, PM or email me for one.
UC Berkeley Class of 2009

2005 Las Vegas Regional Autodesk Visualization Award
2005 Las Vegas Regional #8 Seeded Alliance with 988 and 1505
2006 Southern California Regional #15 seed
  #2   Spotlight this post!  
Unread 16-06-2004, 14:17
jeremy562 jeremy562 is offline
Engineer
#0562 (SPARK 562)
 
Join Date: Feb 2002
Location: Fitchburg, MA
Posts: 74
jeremy562 is an unknown quantity at this point
Send a message via AIM to jeremy562
Re: MySQL Problem

I believe the function is "mysql_num_rows", not "mysql_numrows" (note the underscore between num and rows).
__________________
SPARK 562: Students Pursuing Applied Robotics Knowledge

2006 BAE Granite State Regional: Finalists with 319 and 176
2006 BAE Granite State Regional: Winners of Motorola Quality Award
2004 BAE Granite State Regional: 7th Seed
2004 Mayhem on the Merrimack Champions! Thanks, 61 and 1289!
  #3   Spotlight this post!  
Unread 16-06-2004, 20:57
evulish's Avatar
evulish evulish is offline
1010100
AKA: Grant Harding
#0084 (WATTNESS (bot: Chuck))
Team Role: Alumni
 
Join Date: Jul 2002
Location: Towanda/Wysox, PA
Posts: 1,434
evulish is just really niceevulish is just really niceevulish is just really niceevulish is just really nice
Send a message via AIM to evulish
Re: MySQL Problem

Try using:

PHP Code:
$result mysql_query("SELECT * FROM contacts",$link) or die ("Mysql error: ".mysql_error()); 

Also, all that mysql_result stuff is probably overkill thanks to mysql_fetch_array.

PHP Code:
while ($array mysql_fetch_array($result,MYSQL_ASSOC)) {
print 
"$array['row'] $array['otherrow'] $array['etc']";

That makes it a whole lot cleaner and I'd assume quicker (but I'm not positive). (Also, take a look at www.php.net/mysql_fetch_array to see what that MYSQL_ASSOC is about, if you're wondering. You don't really need it, I guess, but I always use it)
__________________
I'm a professional web developer. I'm good with PHP, Perl, Java/JSP, some RoR, XML, Javascript (AJAX as well), (x)HTML, CSS, etc.. Validated code is good; fully cross-browser code is better (you comply to your users and the software they use, not the other way around. Sorry!)
  #4   Spotlight this post!  
Unread 16-06-2004, 21:51
Unsung FIRST Hero
Nate Smith Nate Smith is offline
FRC Key Volunteer Trainer
AKA: CrazyNate
no team
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Old Town, Maine
Posts: 1,029
Nate Smith is a splendid one to beholdNate Smith is a splendid one to beholdNate Smith is a splendid one to beholdNate Smith is a splendid one to beholdNate Smith is a splendid one to beholdNate Smith is a splendid one to beholdNate Smith is a splendid one to beholdNate Smith is a splendid one to behold
Send a message via AIM to Nate Smith Send a message via Yahoo to Nate Smith
Re: MySQL Problem

PHP Code:
while ($array mysql_fetch_assoc($result)) {
print 
"$array['row'] $array['otherrow'] $array['etc']";

You can actually use this for the same effect as the mysql_fetch_array with MYSQL_ASSOC as the parameter. That's what I'm using in a script I'm writing for my church's web site...
__________________
Nate Smith
nsmith@smythsoft.com
12 seasons, 4 teams, and more time logged behind the scorekeeper's table than I care to remember...
returning for 2011? only time will tell...
  #5   Spotlight this post!  
Unread 17-06-2004, 00:35
Joshua May's Avatar
Joshua May Joshua May is offline
Go Bears!
FRC #1110 (Binary Bulldogs)
Team Role: College Student
 
Join Date: Nov 2003
Rookie Year: 2003
Location: Berkeley, CA
Posts: 1,306
Joshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond repute
Send a message via AIM to Joshua May
Re: MySQL Problem

Allright guys, thanks, I'll try these.
__________________
The FIRST Wiki - openFIRST - Ultimate Robot Challenge - URC Wiki
I currently have 50 GMail invites, PM or email me for one.
UC Berkeley Class of 2009

2005 Las Vegas Regional Autodesk Visualization Award
2005 Las Vegas Regional #8 Seeded Alliance with 988 and 1505
2006 Southern California Regional #15 seed
  #6   Spotlight this post!  
Unread 17-06-2004, 10:35
Joshua May's Avatar
Joshua May Joshua May is offline
Go Bears!
FRC #1110 (Binary Bulldogs)
Team Role: College Student
 
Join Date: Nov 2003
Rookie Year: 2003
Location: Berkeley, CA
Posts: 1,306
Joshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond repute
Send a message via AIM to Joshua May
Re: MySQL Problem

OK, I found the problem, but I didn't get a good error report until evulish suggested that line with the "or die()". The real problem was that my table was not named "contacts", it was contact. lol

Thanks alot guys.
__________________
The FIRST Wiki - openFIRST - Ultimate Robot Challenge - URC Wiki
I currently have 50 GMail invites, PM or email me for one.
UC Berkeley Class of 2009

2005 Las Vegas Regional Autodesk Visualization Award
2005 Las Vegas Regional #8 Seeded Alliance with 988 and 1505
2006 Southern California Regional #15 seed
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL on Windows Venkatesh IT / Communications 6 27-06-2004 19:12
Victor problem Andy Baker Electrical 15 24-06-2003 09:49
Ok one problem cantwell03 Programming 3 13-02-2003 07:28
The problem with scouting... archiver 2001 10 23-06-2002 23:49
Major problem with chipphua motors aka Scott White Motors 18 19-03-2002 19:44


All times are GMT -5. The time now is 00:36.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi