2

I am trying to access a mysql server on a remote machine using php. I tried viewing data in table, I am using below php script. Please let me know if I am missing something.

<?php
    $conn = mysql_connect("192.168.1.1","root","password");
    $db = mysql_select_db("charan", $conn);
?>

<?php 
   echo "<ul>";
   $sql = "select * from arista";
   $query = mysql_query($sql);

   while ($row = mysql_fetch_array($query)) {
         echo "<li>Username:$row[0]</li><li>DOB:</li><br/>";
   }
?>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
charan
  • 119
  • 8
  • missing a bracket here for one thing `$db = mysql_select_db("charan",$conn;` and a quote `echo "
  • Username:$row[0]
  • DOB:

  • ;` - parse errors. – Funk Forty Niner Dec 17 '15 at 16:40
  • Oh, sorry Fred that was a typo. I do have a bracket in my original script. – charan Dec 17 '15 at 16:41
  • edited my comment above, there's something else. reload it and missing closing ul – Funk Forty Niner Dec 17 '15 at 16:41
  • Add error reporting to the top of your file(s) right after your opening PHP tag for example ` – Funk Forty Niner Dec 17 '15 at 16:42
  • root user in mysql have password? I think that you use default setting and root user not set password – paranoid Dec 17 '15 at 16:43
  • You need to call SQL queries for creating table and editing table data. Where are they? – Somnath Muluk Dec 17 '15 at 16:43
  • Somnath, in above example I am trying to view data from the table. – charan Dec 17 '15 at 16:46
  • 3
    Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Dec 17 '15 at 16:47
  • @Fred-ii- I tried with above mentioned changes. I am getting below error. Fatal error: call to undefined function mysql_connect() in /var/www/sqlview.php on line 4. – charan Dec 17 '15 at 16:55
  • First of all, consider using MySQLi. `mysql_` are decaped. – Juanjo Salvador Dec 17 '15 at 16:59