-1

SO I am trying to connect to my MySQL database using php in my html document. When I upload it to the web it does not seem to work! Here is my code:

<?php
    $con = mysql_connect("localhost","dbuser","dbpass");
    mysql_selectdb("DB",$con);
    $sql = "SELECT * FROM Table";
    $mydata = mysql_query($sql,$con);

Thanks in advance!

Bob
  • 11
  • 1
  • 1
    What happens? do you get any error? – Xatenev Sep 09 '14 at 15:00
  • 3
    sigh... `mysql_*`...... – John Ruddell Sep 09 '14 at 15:00
  • 2
    *PSA:* The `mysql_*` functions are [deprecated in PHP 5.5](http://php.net/manual/en/faq.databases.php#faq.databases.mysql.deprecated). It is not recommended for writing new code as it will prevent you from upgrading in the future. Instead, use either [MySQLi](http://php.net/manual/en/book.mysqli.php) or [PDO](http://php.net/manual/en/book.pdo.php) and [be a better PHP Developer](http://jason.pureconcepts.net/2012/08/better-php-developer/). – Jason McCreary Sep 09 '14 at 15:00
  • localhost would be for your local machine – meda Sep 09 '14 at 15:00
  • I see this question a lot. Please read [common database debugging for PHP and MySQL](http://jason.pureconcepts.net/2013/04/common-debugging-php-mysql/). – Jason McCreary Sep 09 '14 at 15:01
  • 4
    localhost is your local machine | it is `mysql_select_db` instead of `mysql_selectdb` – Xatenev Sep 09 '14 at 15:01
  • My page appears blank @Xatenev – Bob Sep 09 '14 at 15:01
  • It's blank because you're not querying anything. Well, you are in a way, but you're not fetching anything from it/not echoing, just selecting from table. – Funk Forty Niner Sep 09 '14 at 15:02
  • I am I just have not displayed this code – Bob Sep 09 '14 at 15:04
  • Plus, as already stated, it's `mysql_select_db` and not `mysql_selectdb` - Add error reporting to the top of your file(s) right after your opening ` – Funk Forty Niner Sep 09 '14 at 15:04
  • 1
    Like i said, you have an error in your syntax which should stop PHP from doing anything: `mysql_select_db` | If your server is just for test purposes, you might display errors on your live server so you see what is going wrong :). – Xatenev Sep 09 '14 at 15:05
  • 1
    you should not use mysql_* you should either use PDO or MySQLi... see my post here for a more appropriate way to do that. http://stackoverflow.com/questions/25410358/mysql-isnt-adding-info-to-my-database/25410388#25410388 – John Ruddell Sep 09 '14 at 15:08
  • @Xatenev you should post your comment as an answer, it'll get you some extra rep :) – John Ruddell Sep 09 '14 at 15:09
  • @JohnRuddell How do I use your example for displaying data and then linking it to a more detailed page? – Bob Sep 09 '14 at 15:13
  • @bob my example is for how to correctly use a query and not use mysql_*... not for fixing your entire problem but rather just helping with sql injection and not using deprecated stuff – John Ruddell Sep 09 '14 at 15:17

1 Answers1

1

You should try uploading it as connection.php rather than connection.html

I hope this helps!

littleswany
  • 473
  • 2
  • 6
  • 18