Jump to content

Displaying MySQL [5.1] data with a PHP table


iwalkonstars

Recommended Posts

I am a recent grad who has worked with SQL a bit, so I have my simple table all set with some sample data filled in.  I am doing my first bit of coding "in real life" for a start-up business.  I know I need PHP to display the information.  It's simple - a table showing the info from the four columns in the MySQL table.  PHP is something I haven't worked with, but I did have a little practice with programming [in general - the logic, etc.] in college.  I would really appreciate some direction on how I go about doing this.  All I need it a little success with my results... I've Googled away and nothing works for me.  :shrug:

 

I've done my best, but I'm spending hours and getting nowhere.  My process:

 

Type code in notepad --> FTP to server --> test in browser

 

I haven't installed anything on my PC... should I?

 

This would be pretty big for my career, so thank you to anyone that can help  :D

Link to comment
Share on other sites

This site is geared more toward helping people with code they've already written, not teaching php from step one. You'd seriously be better off to buy a book and start going through it rather than attempting to learn by whatever bits and pieces of information you'd get on a forum or from a tutorial on the internet. At least a book would start with what you need to know first and build on it so you can actually understand what you're doing.

Link to comment
Share on other sites

This site is geared more toward helping people with code they've already written, not teaching php from step one. You'd seriously be better off to buy a book and start going through it rather than attempting to learn by whatever bits and pieces of information you'd get on a forum or from a tutorial on the internet. At least a book would start with what you need to know first and build on it so you can actually understand what you're doing.

 

I have been playing around with it, and the PHP codes I use seem to work fine.  But when trying to connect to my MySQL database, I get a blank page.  I guess that is my primary issue.  I have a block of code that *should* be working right, but I'm stuck.  I suppose the better question would be "how do I know if I'm connecting to my database?" 

 

I have been doing my best to find the info myself though online tutorials, I'm hesitant to buy books at their costs with no idea of how well the content will match my needs.  Could you at least recommend a good site for MySQL/PHP?

Link to comment
Share on other sites

If you get no errors with this code you are connected to your database.

 

<?php
mysql_connect('localhost', 'username', 'password') or die (mysql_error());
mysql_select_db('database') or die (mysql_error());
?>

 

I didn't get any errors - all I got was a blank page.  This is the same thing I get when I try connecting.  PHP in general is working fine for me, so it would seem that this is an issue with connecting to MySQL specifically.  For the record, I used a sample database and block of PHP code to try it out, and I got the same error.  If it's not syntax related, is there anything else that would be causing the connection issue?

Link to comment
Share on other sites

Your host should provide you with access to the error log file, where you will find clues to the problem.

 

Also try adding this to top of your script to show errors directly on the page for debugging:

 


error_reporting(E_ALL);
ini_set('display_errors', '1');

Link to comment
Share on other sites

Your host should provide you with access to the error log file, where you will find clues to the problem.

 

Also try adding this to top of your script to show errors directly on the page for debugging:

 


error_reporting(E_ALL);
ini_set('display_errors', '1');

 

Thanks - I finally got something on the page:

 

Fatal error: Call to undefined function mysql_connect() in /var/www/html/test.php.txt on line 13

 

Link 13 reads:

 

mysql_connect('localhost', 'myusername', 'mypass') or die (mysql_error());

 

Looking into this, I concluded that I needed to check phpinfo, which I did.  I found '--without-mysql' and, from what I read, this is incorrect.  The explanations I could find for changing this was a little vague - do I change it through putty?  Thanks for all the help so far  :)

Link to comment
Share on other sites

The server belongs to the IT consultation firm that I am working with.  Any PHP installation was done prior to my involvement.  It is a Linux server, and I'm not sure about the installation, and the server owner is tinkering now trying to get it to with mysql.  If you have any ideas on how to do this, we would appreciate it :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.