hello I am making a login/register system for my website
so far for the register php code i have:

<?php
include ("config.php");
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


$username = $_POST[username];
$password = $_POST[password];
$email = $_POST[email];
$conf_email = $_POST[confirm_email];

$query = "INSERT INTO site_users_info (username, password, email, confirm_email) VALUES('$username', '$password', '$email', '$conf_email')";
$stmt = $mysqli->prepare($query);
if(!$stmt){
    echo "Problem Preparing Query!";
}
$stmt->execute();

$validatequery = "SELECT * FROM site_users_info ";
$result = mysql_query($validatequery)  or die(mysql_error());;

$num_rows = mysql_num_rows($result);



?>

and here is the config file:

<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$mysqli = new mysqli("localhost", "root", "", "site_users");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
} 
?>

the problem is I want to create an error for someone who is registering with the same username, however i have tried using the mysql_num_rows() function and i used a mysql_error to see if there was an error with the sql, it said that no database had been selected, what is causing this problem and how can i fix it?

you have to select the data-base first to act on any of the tables in that.Then u can use the mysql_select_db() for that.

You didn't used the command to connect to database just use below syntax to connect to db
<?php
$username = "your_name";
$password = "your_password";
$hostname = "localhost";

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
?>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.