0

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?

3
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by rajesh205
0

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.

0

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>";
?>

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.