So Now What?

He has: 688 posts

Joined: Feb 2001

I got my data into a mySQL database table. I have phpMyAdmin to administer changes to the data, but now I'm inerested in adding my database to my website. It doesn't matter at this point whether it can add/edit/delete, but I want to be able to display the data to my site visitors in a nice way, and must be able to be searched (so web users can find the data they're looking for without going thru 200 rows). (This is just one table full of people and contact information.)

Does anybody have advice on a particular script for the purpose of facilitating the public web interface for browsing and searching the data? (I can use other programs for admin purposes). Thanks.

P.S. Prefer free, and either php or perl.

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

Here's a link to a sample select using PHP: http://www.mysql.com/articles/ddws/23.html

He has: 688 posts

Joined: Feb 2001

I went to that page and tried to follow it (not knowing what everything meant). I copied the last area of code into a page and altered what I thought were things I had to alter. Here's what I wrote in my page....

(with "pstvalu_directory" being the mySQL database, "pstvalu_director" being my mySQL username, "alumni" being the table, and "MYPASSWORD" representing my actual database password)

Quote:

Test

<?php
 
// Connect to the database server
$dbcnx = @mysql_connect("localhost",
          
"pstvalu_director", "MYPASSWORD");
  if (!
$dbcnx) {
    echo(
"<P>Unable to connect to the " .
         
"database server at this time.</P>" );
    exit();
  }

 
// Select alumni database
 
if (! @mysql_select_db("alumni") ) {
    echo(
"<P>Unable to locate the alumni " .
         
"database at this time.</P>" );
    exit();
  }
?>
Here are all alumni in our database:

<?php
 
// Request the listing of all alumni
 
$result = mysql_query(
           
"SELECT alumni FROM pstvalu_directory");  if (!$result) {
    echo(
"<P>Error performing query: " .
        
mysql_error() . "</P>");
    exit();
  }

 
// Display the listing of all alumni in a paragraph
 
while ( $row = mysql_fetch_array($result) ) {
    echo(
"<P>" . $row["alumni"] . "</P>");
  }
?>

and when I called this page I got this message...

Quote:
Here are all alumni in our database:

Error performing query: " . mysql_error() . "

"); exit(); } // Display the listing of all alumni in a paragraph while ( $row = mysql_fetch_array($result) ) { echo("
" . $row["alumni"] . "

"); } ?>

nike_guy_man's picture

They have: 840 posts

Joined: Sep 2000

Try this :

<?php
<HTML>
<
HEAD>
<
TITLE>Test</TITLE>
<
HEAD>
<
BODY>



// Connect to the database server
$dbcnx = @mysql_connect(\"localhost\",\"pstvalu_director\", \"MYPASSWORD\");
if (!
$dbcnx) {
print \"<P>Unable to connect to the database server at this time.</P>\";
exit();
}

// Select alumni database
if (! @mysql_select_db(\"alumni\") ) {
print \"Unable to connect to the DB\";
}

<P> Here are all alumni in our database: </P>
<BLOCKQUOTE>



// Request the listing of all alumni
$query = \"SELECT alumni FROM pstvalu_directory \";
$result = mysql_query($query);
if (
$result) {
// Display the listing of all alumni in a paragraph
while (
$row = mysql_fetch_array($result) ) {
print \"<P>
$row[alumni]</P>\";
}
} else {
echo \"MySQL Error: \";
echo mysql_error();
print \"</P>\";
exit();
}




</BLOCKQUOTE>
</BODY>
</HTML>
?>

Laughing out loud

He has: 688 posts

Joined: Feb 2001

Thanks. I tried your code (replacing the password) and the errors went away. But nothing else happened either. Perhaps I'm expecting something that I shouldn't. Should it list all the table data? (Should it have any browse,search, or sort functions?)

Here's a link to the page I'm experimenting with:

** removed for security reasons**

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

Mike,

I'm not a PHP expert but I think something is definitely wrong. The PHP code was showing up when I viewed the source of your page. Because of this I have removed the URL because your database credentials were exposed. PHP is a server-side language and should not show up on the client-side.

Are you sure PHP is running on your server?
Does your table have data in it?
Is your SQL statement correct?

PJ | Are we there yet?
pjboettcher.com

nike_guy_man's picture

They have: 840 posts

Joined: Sep 2000

Sounds like you don't have PHP installed
try running

<?php
phpinfo
();
?>
'
Have you run PHP scripts before?

He has: 688 posts

Joined: Feb 2001

I definitely have php. I put in your code, nike_guy_man and it says php 4.2.2

Peter, I changed the extention from .shtml to .php and now it doesn't list my code (ie. password). But now it says no database. I know there's a database with info on it because I can get to all of it thru phpMyAdmin. Referring to the code above by nike_guy_man, that's exactly what I have in my php file except with the password changed. To double check, "pstvalu_directory" is the mySQL database name (with a "y"), "pstvalu_director" is the mySQL username (without a "y"), and "alumni" is the name of the table that is inside the database "pstvalu_directory"

Since it isn't listing code, here's my test link again:
pstvalumni.com/test2.php
And here's the php test that nike_guy_man suggested, which lists a whole lot of stuff I don't understand.
pstvalumni.com/testphp.php

Thanks.

P.S. Is it causing a problem that my .php file starts off with ...?

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

Looks like you fixed your problem? I get a page listing a bunch of different links, no errors.

Starting with won't effect PHP, it is an inline language so it can be interspersed with html.

PJ | Are we there yet?
pjboettcher.com

nike_guy_man's picture

They have: 840 posts

Joined: Sep 2000

I'm getting a 'coming soon' page...
If your server allows .shtml as PHP parsed... then that should have worked, but not a lot of servers allow that
There was your problem!

Are you on an intranet where you are viewing this and it's working or what?

Laughing out loud

He has: 688 posts

Joined: Feb 2001

Dear nike_guy_man
Dear Peter J. Boettcher
Dear Abhishek Reddy

Sorry for whatever was going on with my site. Short answer was that my domain was hijacked and redirected by a company I never heard of before - but that's for another thread. Basically I'm back and I'd like to revive this thread and hopefully get my database display worked out. I'd appreciate if you gave it another look (and if you're still seeing that "coming soon" screen, just wait another day for further DNS propgation back to my real website)

Thanks.

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

Looks like it can't connect to the db. Is the db on the same server as your web? Are you connecting by machine name? Maybe try putting the IP number instead.

PJ | Are we there yet?
pjboettcher.com

He has: 688 posts

Joined: Feb 2001

Here's the code I got from here (minus my password). It gives me a database error (pstvalumni.com/test2.php)

Quote:

<?php


// Connect to the database server
$dbcnx = @mysql_connect("localhost","pstvalu_director", "PASSWORD");
if (!
$dbcnx) {
print
"<P>Unable to connect to the database server at this time.</P>";
exit();
}

// Select alumni database
if (! @mysql_select_db("alumni") ) {
print
"Unable to connect to the DB";
}
?>
Here are all alumni in our database:

<?php


// Request the listing
$query = "SELECT alumni FROM pstvalu_directory ";
$result = mysql_query($query);
if (
$result) {
// Display the listing of all alumni in a paragraph
while ($row = mysql_fetch_array($result) ) {
print
"<P>$row[alumni]</P>";
}
} else {
echo
"MySQL Error: ";
echo
mysql_error();
print
"</P>";
exit();
}
?>

I contacted my host tech support to double check the names of my databases and they were nice enough to "fix" the code. It gets rid of the errors but I still see no output. (pstvalumni.com/support.php)

Quote:

<?php


// Connect to the database server
$dbcnx = @mysql_connect("localhost","pstvalu_director", "PASSWORD");
if (!
$dbcnx) {
print
"<P>Unable to connect to the database server at this time.</P>";
exit();
}

// Select alumni database
if (! @mysql_select_db("pstvalu_directory") ) {
print
"Unable to connect to the DB";
}
?>
Here are all alumni in our database:

<?php


// Request the listing
$query = "SELECT * FROM alumni";
$result = mysql_query($query);
if (
$result) {
// Display the listing of all alumni in a paragraph
while ($row = mysql_fetch_array($result) ) {
print
"<P>$row[alumni]</P>";
}
} else {
echo
"MySQL Error: ";
echo
mysql_error();
print
"</P>";
exit();
}
?>

I see a few differences but I don't know enough to which is correct. Other than giving me another suggestion to try out, can anybody also show me a working example of what this code is even supposed to look like (on somebody else's database), once it finally works?

Thanks.

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

Mike,

It looks like you had your database name and table name mixed up, that's what support fixed for you so you're able to connect. Are you 100% sure that the Alumni table has data in it?

Maybe you should do a little more reading so you understand the basics a little better, check out this tutorial on webmonky: http://hotwired.lycos.com/webmonkey/programming/php/tutorials/tutorial4.html

PJ | Are we there yet?
pjboettcher.com

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.