Off-topic Talk Where overpaid, underworked S2000 owners waste the worst part of their days before the drive home. This forum is for general chit chat and discussions not covered by the other off-topic forums.

php and mysql

Thread Tools
 
Old May 22, 2003 | 11:17 AM
  #1  
AquilaEagle's Avatar
Thread Starter
Administrator
Gold Member (Premium)
20 Year Member
Liked
Loved
Community Favorite
 
Joined: Jan 2002
Posts: 95,183
Likes: 69
From: Heath & Reach, Beds, UK
Default php and mysql

I need a little bit of help on creating a webpage using php and mysql. I have a form on a webpage to organise the UK SuperMeet4 and i want the input on the form (which currently is emailed to 2 addresses using a php file) automatically displayed onto a table on another webpage. If anyone can help pls PM me or get me on any of the following:

msn messenger: ianeagle@hotmail.com
AOLim: EagsUK

Thanks
Reply
Old May 22, 2003 | 12:23 PM
  #2  
SteveUCI's Avatar
Registered User
 
Joined: Jan 2001
Posts: 6,455
Likes: 0
From: Glendale/Burbank/LA
Default

If your question is specifically how to access the MySQL data from PHP and display it, here's the basics:


Use the following functions:

connectionobject = mysql_connect(host, username, password)
mysql_select_db(database)
resultobject = mysql_query(SQL, connectionobject)
mysql_close(connectionobject)

At the bottom of this post are a few wrapper functions to make things more readable in your code:

call ConnectToDatabase, then call GetRecordset with the appropriate parameters. When you're done with using the database, call CloseConnection. I haven't provided a wrapper function for inserting/updating/deleting records, so you'll have to do that yourself. Basically, to save the values from a form to the database, just do this (assuming you have a table called tblParticipant):

mysql_query("INSERT INTO tblParticipant (field1, field2, field3, ...) VALUES (value1, value2, value3, ...)");

To retrieve this data and display it, you could do something like this:

$rstParticipants = GetRecordset("tblParticpant");

echo "<table border=1>n";
echo "<tr><td>Name</td><td>Email Address</td><td>Owner?</td></tr>n";
while ($myrow = mysql_fetch_array($rstParticipants))
{
printf("<tr><td>%s</td><td>%s</td><td>%s</td></tr>n", $myrow[prtFirstName] . $myrow[prtLastName], $myrow[prtEmailAddress], $myrow[prtOwnerOrNot]);
}
echo "</table>n";


Hope this helps!
-Steve




function ConnectToDatabase($host, $database, $username, $pwd)
{
global $objConnection;

if( $host == "" || $username == "" )
{
die('No hostname or username specified.');
}
else
{
if( $objConnection )
{
CloseConnection();
}

$objConnection = mysql_connect($host, $username, $pwd) or die('Unable to connect to database: ' . mysql_error());
mysql_select_db ($database);
echo "Connected to database.
";
}
}

function CloseConnection()
{
global $objConnection;

mysql_close( $objConnection );
}

function GetRecordset($table, $fieldlist = "*", $where = "", $orderby = "")
{
global $objConnection;

$strSQL = "SELECT $fieldlist FROM $table";
if( $where != "" )
{
$strSQL = $strSQL . " WHERE $where";
}
if( $orderby != "" )
{
$strSQL = $strSQL . " ORDER BY $orderby";
}
echo "GetRecordset SQL = $strSQL";
$result = mysql_query($strSQL, $objConnection);
if (!$result)
{
echo "GetRecordset failed for SQL = $strSQL - " . mysql_error();
exit;
}
return $result;
}
Reply
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
therookie
Off-topic Talk
0
Oct 27, 2005 06:20 AM
naomi-sarah
Off-topic Talk
2
May 11, 2005 12:16 PM
magician
Off-topic Talk
2
Oct 22, 2001 12:57 PM
saliv8
Off-topic Talk
3
Feb 15, 2001 09:15 AM




All times are GMT -8. The time now is 04:05 PM.