Failing to query mysql using PHP

sosytee

I would like to use a form to query a mysql database in Ubuntu Server. The database is connecting but somehow the results are not being echoed as requested in the code. Here is my sample code

<?php
$var=$_REQUEST['IP'];
echo "$var";
mysql_connect('localhost','root','mysql','syslog')
or die("Unable to connect to the database");
$result=mysql_query("SELECT * FROM arp_table");
$row=mysql_fetch_row($result);
echo $row[0];
?>

I am sure it is connecting to the database because it is not displaying the die message, but it is not doing anything beyond dispaying the variable connected to the form.

Savindra

According to the code you have provided, the parameters you have passed to mysql_connect are wrong.

resource mysql_connect ([ string $server = ini_get("mysql.default_host") [, string $username = ini_get("mysql.default_user") [, string $password = ini_get("mysql.default_password") [, bool $new_link = false [, int $client_flags = 0 ]]]]] )

The 4th parameter is new_link not the name of the database. Try the following code -

<?php

    $var = $_REQUEST['IP'];    
    echo $var;

    mysql_connect( "localhost", "root", "mysql" ) or die("Unable to connect to the database");
    mysql_select_db( "syslog" );

    $result = mysql_query( "SELECT * FROM arp_table" );

    $row = mysql_fetch_row( $result );

    print_r( $row );

?>

Hope that helps :)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related