Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BASIC PHP - MYSQL CONNECTING TO A DATABASE 1

Status
Not open for further replies.

Evil8

MIS
Mar 3, 2006
313
0
0
US
I am expanding my skills by trying to learn php and mysql. I built the mysql db meetings and a php page. Playing with this for a couple hours I went from a blank page to getting my html and the php error message: "Unable to select database" at least to show up.

Can anyone help me find the error?

<?php

$username="me";
$password="*****";
$database="me-meetingSchedual";

mysql_connect(loccalhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query=("SELECT * FROM meetings");
$result=mysql_query($query);

?>

Thank you for any help.

 
Okay, I think I fixed the connection part...

I changed:
mysql_connect(loccalhost,$username,$password);

to:
mysql_connect("me-meetingSchedual.mysql.me.com:3306",$username,$password);

At least now, I'm not getting the die message. But I'm still not getting any sql data query results.

Thanks.
 
alright, I'm still crawling, but I'm almost walking...

I changed the sql query lines to:

$query=("SELECT * FROM meetings WHERE 1 LIMIT 0, 30");
$result=mysql_query($query);

while($row = mysql_fetch_array($result))
{
echo $row['day'] . " " . $row['day'] . " " . $row['sptime'];
echo "<br />";
}

One last question do I have to format the dates and times in the mysql table or can I change formats in the display php code?
 
You can change the date formats in PHP by using the date() function. Assuming you are storing your dates as timestamps.


If you are not storing your dates as timestamps, you can use the strtotime() function to change a date string into a timestamp, and then format it as you need to with the date function.


I recommend a stroll around the PHP online manual, its the bets resource you'll find.


Also posting in the forum434 may provide you with more punctual answers, than in the general Dreameaver forum.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Vacunita - I was storing the Dates as Dates, but they kept defaulting to YYYY-MM-DD format where I, for now want them formated at MM/DD/YYYY format. Later I would like to display them as December 17, 2010. I also have a time field where the default is HH:MM:SS. I would like to display this field eventually as 11:00 am or 12:00 pm. Just to get data up and easily seeable in testing I changed both fields into text.

I have so much to learn, but I'm getting there. I will very definatly look at your php.net resource and switch my posts to the php forum.

Again thank you very much for your time!
 
You can use the date function to format your dates as you need.

For instance:
Code:
$mdate="2010-05-30";

$newdate=strtotime($mdate);
 echo date("l F d, Y",$newdate);

would echo out: [blue]Sunday May 30 2010[/blue]




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Excellent! Thank you. At this moment I'm splitting the single table I created as a test into the 3 tables I'll need to get the real work going. If your interested in seeing what I'm working on you can go to That is the static page of information I'm working on databasing. My test php page is phpmeetings.php. The end result will let the user sort dynamically and I'll also need to set up some type of RSVP form that tracks number of seats at these meetings. Ah and to think I started out life as a hardware monkey...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top