Thread: MySQL Problem
View Single Post
  #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