Hi,

I wonder if someone could help me please.

I basically made a registration form and need to insert the data into the database.

I am not sure how i use the MySQL functions to do this,

I created a db connection file and included it on registration page but not sure if i first havew to query database then insert data etc, i am a little confused.

Before any data can be inserted it has to check if the email address and username already exist. Could someone plese give me the info on what order i do it?

here is what needs being added to database.

username, first_name, last_name, email, password

before it inserts the users data it needs to check to make sure the username and email does or does nto exist.

If someone could help me with this it would be much appreciated.

Here is my db connection file code in case it helps, this is included using the php include in the registration page. All i need help in how i got about checkning if username and email exists or not and if all ok put info in db or give an error to say it already exists.

<?php

// Database Connection Details

$host = "localhost"; // Usually Local Host
$user = "none"; // Database Username
$pass = "none"; // Database Password
$database = "usernone"; // Database Name

mysql_connect ($host, $user, $pass, $database);

?>

Thank you,
genieuk

In connection at localhost user is root and password is blank..

$con = mysql_connect("localhost","root","");
	if (!$con)
	  {
	  die('Could not connect: ' . mysql_error());
	  }
	  else
	  {
	 // echo('Connected with Mysql');
	  }
		@mysql_select_db("usernone", $con);

before inserting check data

$name=$_POST['username'];
$email=$_POST['email'];
$sql=mysql_query("select username from table where username=$name");
$num=mysql_num_rows($sql);
if($num>1)
{
echo "user already exists";
}

You can change query according to your problem defination..
hope this will help you..

Hi,

Thank you,

One question thou the first bit of code where it has mysql_connect , why do i need that? reason why i have that included with my db_connect.php file which i used an include on registration page, so i thought the whole point of that was to not have such information as db details actually on regsitration page but instead included from another file and use the php include function.

Also where do i actually put the code? i mean the first part of code not sure where that goes and does the second piece of code check both email and username? if i am rite it only checking for username not email aswell.

Thank you,
genieuk

Maybe it be better if i put my registration form on here so you could have a look it may make more sence.

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.