INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

BASIC PHP - MYSQL CONNECTING TO A DATABASE

BASIC PHP - MYSQL CONNECTING TO A DATABASE

(OP)
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.

 

RE: BASIC PHP - MYSQL CONNECTING TO A DATABASE

(OP)
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.

RE: BASIC PHP - MYSQL CONNECTING TO A DATABASE

(OP)
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?

RE: BASIC PHP - MYSQL CONNECTING TO A DATABASE

You can change the date formats in PHP by using the date() function. Assuming you are storing your dates as timestamps.

http://php.net/manual/en/function.date.php

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.

http://php.net/manual/en/function.strtotime.php

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

http://www.php.net

Also posting in the forum434: PHP 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.
http://behindtheweb.blogspot.com/
 

RE: BASIC PHP - MYSQL CONNECTING TO A DATABASE

(OP)
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!

RE: BASIC PHP - MYSQL CONNECTING TO A DATABASE

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: Sunday May 30 2010


 

----------------------------------
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.
http://behindtheweb.blogspot.com/
 

RE: BASIC PHP - MYSQL CONNECTING TO A DATABASE

(OP)
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 www.mediqwest.com/meetings.html.  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...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close