1

im new to php and mysql (using wamp)

im getting the following error when i run my script, any idea what to fix?

Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in C:\wamp64\www\web1\Register.php on line 79

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\wamp64\www\web1\Register.php on line 81

line 79 t0 83

 79   mysqli_select_db($database_localhost, $localhost);
 80   $query_Register = "SELECT * FROM mytable";
 81   $Register = mysqli_query($query_Register, $localhost) or die(mysql_error());
 82   $row_Register = mysql_fetch_assoc($Register);
 83   $totalRows_Register = mysql_num_rows($Register);

Here is the database connection:

<?php
# FileName="Connection_php_mysqli.htm"
# Type="mysqli"
# HTTP="true"
$hostname_localhost = "localhost";
$database_localhost = "mydatabase";
$username_localhost = "root";
$password_localhost = "";
$localhost = mysqli_connect($hostname_localhost, $username_localhost, $password_localhost) or trigger_error(mysql_error(),E_USER_ERROR); 
?>
Community
  • 1
  • 1
  • can you please keep your code where this error is getting.. – Soniya Basireddy Dec 16 '16 at 18:58
  • 1. where are you connecting to the database? 2. you really [shouldn't be using the mysql functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). – mister martin Dec 16 '16 at 18:59
  • Well the error says it all, the variable $localhost is not a mysql resource, so we need to see more of the code in order to help you out. By the way, you should consider upgrading to mysqli since mysql methods are deprecated as of php 5.5 – Andrew Larsen Dec 16 '16 at 18:59
  • you are using the mysql_* functions incorrectly, and furthermore, you shouldn't even be using mysql, use mysqli or pdo instead. see this link http://php.net/manual/en/intro.mysql.php and please include your image as an image and not as a link. –  Dec 16 '16 at 19:00
  • You are mixing up `mysqli_*` and `mysql_*`. http://stackoverflow.com/questions/16002342/mysql-select-db-expects-parameter-2-to-be-resource-object-given this might help – Sayantan Das Dec 16 '16 at 19:09
  • i have changed mysql_select_db() to mysqli_select_db() also ........... changed mysql_query() to mysqli_query() ....................now im getting this error Warning: mysqli_select_db() expects parameter 1 to be mysqli ........and mysqli_query() expects parameter 1 to be mysqli, string given in – Wisam Ghannoum Dec 16 '16 at 19:15
  • stackoverflow.com/questions/40122060/mysqli-select-db-expects-parameter-1-to-be-mysqli-string-given-mysqli-error – Sayantan Das Dec 16 '16 at 19:21
  • You also have to change the order of your parameters you are passing to `mysqli_query()`. So it would be like this: `$Register = mysqli_query($localhost, $query_Register) or die(mysql_error());` – EhsanT Dec 17 '16 at 01:05

2 Answers2

0

As Andrew noted in the comment, the mysql extension was deprecated in PHP 5.5.0 and removed in PHP 7.0.0. You should be using mysqli.

Nonetheless mysql expects the second parameter to be a database resource. You create a resource like this:

$dbResource = mysql_connect('localhost', 'mysql_user', 'mysql_password');

then you would select the database with something like

mysql_select_db('your_database_name', $dbResource);
Sayantan Das
  • 1,619
  • 4
  • 24
  • 43
instance
  • 72
  • 1
  • 6
0

i have changed the position of the connection link and database name from

    mysqli_select_db($database_localhost, $localhost);

to

    mysqli_select_db($localhost, $database_localhost);

the first error disappeared, but the second error still persist

forgot to mention that (html code) registration form is not showing