Jump to content

Checking if username exists in database


mikebyrne

Recommended Posts

At present Im trying to get my for to check if the username already exists in the database and if it does throws back an error

 

The SQL for my table is

 

CREATE TABLE `adminusers` (

  `name` varchar(255) collate latin1_general_ci default NULL,

  `address` varchar(255) collate latin1_general_ci default NULL,

  `address1` varchar(255) collate latin1_general_ci default NULL,

  `address2` varchar(255) collate latin1_general_ci default NULL,

  `address3` varchar(255) collate latin1_general_ci default NULL,

  `address4` varchar(255) collate latin1_general_ci default NULL,

  `county` varchar(255) collate latin1_general_ci default NULL,

  `zip` varchar(255) collate latin1_general_ci default NULL,

  `telephone` decimal(10,0) default NULL,

  `email` varchar(255) collate latin1_general_ci default NULL,

  `username` varchar(255) collate latin1_general_ci default NULL,

  `password` varchar(255) collate latin1_general_ci default NULL,

  `usertype` decimal(10,0) default NULL

) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

 

If I have Michael in username it echos Michael and also echo's 0 for $num

 

 

 

<?PHP

$name = $_POST['name'];
$address = $_POST['address'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$address3 = $_POST['address3'];
$address4 = $_POST['address4'];
$county = $_POST['county'];
$zip = $_POST['zip'];
$telephone = $_POST['telephone'];
$email = $_POST['email'];
$password =$_POST['password'];
$username = $_POST['username'];
$num =$_POST ['num'];

include('adminconnect.php');


			$sql =  "SELECT name FROM adminusers WHERE name ='$username'";
                                $result = mysql_query($sql);
                                $num = mysql_numrows($result);
							echo $_POST['username'];
							echo $num;
                                if ($num > 0) {
                                
                                $valid=0; 
                                $error_username = "Username is already taken<br>";
                                $style_username = "background-color:#FF5959";
                                
                                }         
                   
}
?>

 

The form looks like

 

<form name="form" method="post" action="adminreg.php">
  <table align="center" width="546">
    <tr valign="baseline">
      <td nowrap align="right" width="95">Name:</td>
      <td nowrap align="right">
      <input name="name" type="text" size="32" style="font-size: 8pt; $style_name; float:left" value="<?php echo $name; ?>"></td>
      <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_name; ?></font></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" width="95">Address:</td>
      <td nowrap align="right">
<input name="address" type="text" size="32" style="font-size: 8pt; $style_address; float:left" value="<?php echo $address; ?>"></td>
      <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_address; ?></font></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" width="95">Address1:</td>
      <td nowrap align="right">
      <input name="address1" type="text" size="32" style="font-size: 8pt; $style_address1; float:left" value="<?php echo $address1; ?>"></td>
      <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_address1; ?></font></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" width="95">Address2:</td>
      <td nowrap align="right">
   <input name="address2" type="text" size="32" style="font-size: 8pt; $style_address2; float:left" value="<?php echo $address2 ;?>"></td>
      <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_address2; ?></font></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" width="95">Address3:</td>
      <td nowrap align="right">
   	<input name="address3" type="text" size="32" style="font-size: 8pt; $style_address3; float:left" value="<?php echo $address3; ?>"></td>
      <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_address3; ?></font></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" width="95">Address4:</td>
      <td nowrap align="right">
      <input name="address4" type="text" size="32" style="font-size: 8pt; $style_address4; float:left" value="<?php $address4; ?>"></td>
      <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_address4;?></font></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" width="95">County:</td>
      <td nowrap align="right">
   <input name="county" size="32" style="font-size: 8pt; $style_county; float:left" value="<?php echo $county; ?>"></td>
      <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_county ?></font></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" width="95">Zip:</td>
      <td nowrap align="right">
  <input name="zip" size="32" style="font-size: 8pt; $style_zip; float:left" value="<?php echo $zip; ?>"></td>
      <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_zip;?></font></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" width="95">Telephone:</td>
      <td nowrap align="right">
      <input name="telephone" size="32" style="font-size: 8pt; $style_telephone; float:left" value="<?php $telephone; ?>"></td>
      <td width="269"><font color="#FF0000" style="font-size: 8pt"><? echo $error_telephone; ?></font></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" width="95">Email:</td>
      <td nowrap align="right">
      <input name="email" size="32" style="font-size: 8pt; $style_email; float:left" value="<?php $email;?>"></td>
      <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_email;?></font></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" width="95">Username:</td>
      <td nowrap align="right">
    <input name="username" size="32" style="font-size: 8pt; $style_username; float:left"></td>
      <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_username; ?></font></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" width="95">Password:</td>
      <td nowrap align="right">
     <input name="password" size="32" style="font-size: 8pt; $style_password; float:left"type="password"></td>
      <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_password; ?></font></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" width="95"> </td>
      <td nowrap align="right">
        <input type=hidden name=action value="signup">
        <input type="submit" value="Insert record" style="float: left"> </td>
      <td width="269"> </td>
    </tr>
  </table>
</form>  

 

 

 

Link to comment
Share on other sites

The code would look like this  : (I have used a code for determining if an email address already exists but you could change this to check any data)

 

//This part of the code will check to see if the data your using already exists (in your case the name)

 

$query = "SELECT user_id FROM users WHERE email='$e'";

$result = mysql_query($query);

if (mysql_num_rows($result) == 0) {

 

//this code will then report an error if it does exist

 

} else {

echo 'h1 id="mainhead">error !

</h1>

<p class="error"> The Email address already exists

</p>

 

 

Link to comment
Share on other sites

I'm guesing that there must be something wrong with my SQL. It looks ok to me though??

 

Hence you should always check your query succeeds prior to attempting to use any result it may have produced.

 

<?php

if (isset($_POST['submit'])) {
 $name = $_POST['name'];
 $address = $_POST['address'];
 $address1 = $_POST['address1'];
 $address2 = $_POST['address2'];
 $address3 = $_POST['address3'];
 $address4 = $_POST['address4'];
 $county = $_POST['county'];
 $zip = $_POST['zip'];
 $telephone = $_POST['telephone'];
 $email = $_POST['email'];
 $password =$_POST['password'];
 $username = $_POST['username'];
 $num = $_POST ['num'];

 include 'adminconnect.php';

 $sql =  "SELECT name FROM adminusers WHERE name ='$username'";
 if ($result = mysql_query($sql)) {
   if (mysql_num_rows($result)) {
     echo "$username available";
   } else {                                
     echo "$username exists";
   }
 } else {
   echo "Query failed<br />$sql<br />" . mysql_error();
 }
}

?>

Link to comment
Share on other sites

I did that with the username as Michael but the echo is echo "root exists" insteasd of the expected Michael exists

 

Now I think the problem is with adminconnect because within that because i have $username="root";

 

Will I just rename username witihn the validation to sometihng else??

Link to comment
Share on other sites

Sounds like you would be better changing the code to the below, Only a slight change but I have used this way many times and it seems to work ok .

 

<?php
require_once("adminconnect.php");

if (isset($_POST['submit'])) {
  $name = $_POST['name'];
  $address = $_POST['address'];
  $address1 = $_POST['address1'];
  $address2 = $_POST['address2'];
  $address3 = $_POST['address3'];
  $address4 = $_POST['address4'];
  $county = $_POST['county'];
  $zip = $_POST['zip'];
  $telephone = $_POST['telephone'];
  $email = $_POST['email'];
  $password =$_POST['password'];
  $username = $_POST['username'];
  $num = $_POST ['num'];

  

Link to comment
Share on other sites

Yeah I've used it on most of my php pages so far. If I wanted to keep it what would you recommend I do to the code to stop the conflict?

 

I would recommend you change your adminconnect.php script to use constants. These will not conflict. eg;

 

adminconnect.php

<?php

 define('DBUSERNAME','yourusername');
 define('DBPASSWORD','yourpassword');
 define('DBNAME','yourdatabase');
 define('DBHOST','yourhost');

 mysql_connect(DBHOST,DBUSERNAME,DBPASSWORD) or die(mysql_error());
 mysql_select_db(DBNAME) or die(mysql_error());

?>

Link to comment
Share on other sites

My adminconnect.php looks like ths

<?php

$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="admin"; // Database name


//Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");

?>

 

How do I amend it to use constants as suggested

 

I also dont really want to use the require once statement because when I get the validation working I want to connect again to insert all the records into the database

Link to comment
Share on other sites

require_once is usually a better call than include. It simply stops things being included more than is needed.

 

As for how to change your code to use constants, I already gave you an example here, its pretty straight forward.

Link to comment
Share on other sites

Im with Thorpe on this, i would never normally use 'include' unless its really needed. require_once is always better.

 

Also are we not going of track a bit with the question here, Did my code below work for cheking if the name already exists in the database  ?

 


$query = "SELECT user_id FROM users WHERE email='$e'";
$result = mysql_query($query);
if (mysql_num_rows($result) == 0) {

} else {
echo 'h1 id="mainhead">error !
</h1>
<p class="error"> The Email address already exists
</p>


Link to comment
Share on other sites

the code

 

$user = mysql_real_escape_string(htmlspecialchars($_POST['name']));

$sql =  "SELECT name FROM adminusers WHERE name ='$user'";
$result = mysql_query($sql) or die("Error in SQL: ".mysql_error());
$row = mysql_fetch_array($result);
$count = mysql_num_rows($result);

$name = $row['name'];


if ($count == 1) { // username should only exist once.
echo "Error! The username " . $name . " already exists in the database.";
}
else {
echo "Success! The username " .$user . " does not already exist in the database.";
}

 

As for the constants you can use instead of

 

$username = "root";

$password = "";

 

use

 

define('_USER', 'root');

define('_PASS', 'password');

 

then

 

mysql_connect("127.0.0.1", _USER, _PASS) or die("Cannot connect to server");

 

that way $username is not used and will not conflict.

 

In theory, that should work.

 

Sam

Link to comment
Share on other sites

Also are we not going of track a bit with the question here

 

No, were not going off track at all. We have established the fact that the op's connection details are being overridden. Besides that, in your example you don't check the query for success before using it. This is always a bad idea, and a bad habit to teach newcomers.

Link to comment
Share on other sites

Having problems connecting to the database now

 

My adminconnect looks like

 

<?

define('_USER', 'root');
define('_PASS', '');
define('_ADMIN','admin'); 

//Connect to server and select database.
mysql_connect("127.0.0.1",'_USER','_PASS')or die("cannot connect to server");
mysql_select_db('_ADMIN')or die("cannot select DB");

?>

 

My code for adminreg looks like this

 

<?php

$name = $_POST['name'];
$address = $_POST['address'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$address3 = $_POST['address3'];
$address4 = $_POST['address4'];
$county = $_POST['county'];
$zip = $_POST['zip'];
$telephone = $_POST['telephone'];
$email = $_POST['email'];
$password =$_POST['password'];
$username = $_POST['username'];
$num =$_POST ['num'];




if($_POST["action"] == "signup"){

        $valid=1;

                if ($_POST['name']=="") {
			echo 'got no name<br>';
                $valid=0;
                $style_name = "background-color:#FF5959";
                $error_name = "Your name seems to be mising?<br>";
                                }

			if ($address == "" || strlen($address) < 2) {
    			echo 'got no address1<br>';//added by me to denote failure in this statement 
  		 		$valid=0;
   				$style_address = "background-color:#FF5959";
  				$error_address = "There is a problem with the address field?<br>";
							}


			if ($address1 == "" || strlen($address1) < 2) {
    			echo 'got no address1<br>';//added by me to denote failure in this statement 
  		 		$valid=0;
   				$style_address = "background-color:#FF5959";
  				$error_address1 = "There is a problem with the address field?<br>";
							}

			if ($address2 == "" || strlen($address2) < 2) {
    			echo 'got no address2<br>';//added by me to denote failure in this statement 
  		 		$valid=0;
   				$style_address = "background-color:#FF5959";
  				$error_address2 = "There is a problem with the address field?<br>";
							}

			if ($address3 == "" || strlen($address3) < 2) {
    			echo 'got no address3<br>';//added by me to denote failure in this statement 
  		 		$valid=0;
   				$style_address = "background-color:#FF5959";
  				$error_address3 = "There is a problem with the address field?<br>";
							}

			if ($address4 == "" || strlen($address4) < 2) {
    			echo 'got no address4<br>';//added by me to denote failure in this statement 
  		 		$valid=0;
   				$style_address = "background-color:#FF5959";
  				$error_address4 = "There is a problem with the address field?<br>";
							}
			if ($county == "" || strlen($county)<2) {
			echo 'got no county<br>';
                $valid=0;
                $style_county = "background-color:#FF5959";
                $error_county = "The County field is blank?<br>";
        						} 
			if ($zip == "" || strlen($zip)<2) {
			echo 'got no zip<br>';
                $valid=0;
                $style_zip = "background-color:#FF5959";
                $error_zip = "Theres a problem with the zip code?<br>";
        						}   
			if (!eregi("^[0-9]+",$telephone)) {
			echo 'got no phone<br>';
                $valid=0;
                $style_telephone = "background-color:#FF5959";
                $error_telephone = "Theres a problem with the telephone number?<br>";
        						}   
			  if (!eregi("^[A-Za-z0-9.-]+",$email)) {
			echo 'got no mail';
                $valid=0;
                $style_email = "background-color:#FF5959";
                $error_email = "Theres a problem with the email address?<br>";
       						 	}
        
        		if ($password == "" || strlen($password)<7) {
			echo 'got no password';
                $valid=0;
                $style_password = "background-color:#FF5959";
                $error_password = "Theres a problems with your password?<br>";
       							 }      


$user = mysql_real_escape_string(htmlspecialchars($_POST['name']));

$sql =  "SELECT name FROM adminusers WHERE name ='$user'";
$result = mysql_query($sql) or die("Error in SQL: ".mysql_error());
$row = mysql_fetch_array($result);
$count = mysql_num_rows($result);

$name = $row['name'];


if ($count == 1) { // username should only exist once.
echo "Error! The username " . $name . " already exists in the database.";
}
else {
echo "Success! The username " .$user . " does not already exist in the database.";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>e-commerce admin page sample |item</title>
<link href="/Admin_files/admin.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript" src="file:///C|/Users/Mike/Documents/Admin_files/wrapper.js"></script>
</head>
<body>
<div id="Box">
  <div id="logoBox"><a href="http://www.btrax.com/" target="_blank"><img src="file:///C|/Users/Mike/Documents/Admin_files/logo.gif" width="51" height="125" border="0" /></a></div>
  <div id="contentBox">

      <!-- logo start -->
      <div id="container">
        <div class="padTop28">
          <!-- -->
        </div>
        <div class="clr">
          <!-- -->
        </div>
      </div>

      <div class="clr">
        <!-- -->
      </div>
      <!-- logo finish -->
      <!-- menu start -->
      <div id="container">
                                                                <div id="menu1">
                                                <div id="menu_off"><!-- --></div>
                                                <div id="menu_text_off"><a href="file:///C|/Users/Mike/Documents/admin_files/new.php" class="black">
                                                                Order</a></div>
                                                <div id="menu_space1"><!-- --></div>
                                                <div id="menu_off"><!-- --></div>

                                                <div id="menu_text_off"><a href="file:///C|/Users/Mike/Documents/admin_files/sales.php" class="black">
                                                                Sales</a></div>
                                                <div id="menu_space1"><!-- --></div>
                                                <div id="menu_off"><!-- --></div>
                                                <div id="menu_text_on"><a href="file:///C|/Users/Mike/Documents/admin_files/list.php" class="black">
                                                                Edit item</a></div>
                                                <div id="menu_space1"><!-- --></div>
                                                <div id="menu_off"><!-- --></div>
                                                <div id="menu_text_off"><a href="file:///C|/Users/Mike/Documents/shipping/current.php" class="black">
                                                                Postage fee</a></div>
            <div id="menu_space1"><!-- --></div>
                                                <div id="menu_on"><!-- --></div>
            <div id="menu_text_off"><a href="file:///C|/Users/Mike/Documents/shipping/current.php" class="black_on">
                                                                Add User</a></div>
            <div id="menu_space1"><!-- --></div>
                                                <div id="menu_off"><!-- --></div>
            <div id="menu_text_off"><a href="file:///C|/Users/Mike/Documents/shipping/current.php" class="black">
                                                                Add Product</a></div>
                                                <div id="menu_space1"><!-- --></div>
                                </div>
                                <div class="clr"><!-- --></div>        <div class="clr">
          <!-- -->
        </div>
        <div class="padTop5">
          <!-- -->
        </div>

        <div class="clr">
          <!-- -->
        </div>
        <div id="dotted">
          <!-- -->
        </div>
        <div class="clr">
          <!-- -->
        </div>

        <div class="padTop5">
          <!-- -->
        </div>
        <div class="clr">
          <!-- -->
        </div>
        <div id="menu2">
          <div id="menu_hide">
            <!-- -->

          </div>
          <div id="menu_text_off"> </div>
          <div id="menu_space1">
            <!-- -->
          </div>
          <div class="clr">
            <!-- -->
          </div>
        </div>

        <div class="clr">
          <!-- -->
        </div>
        <div class="padTop38">
          <!-- -->
        </div>
        <div class="clr">
          <!-- -->
        </div>

      </div>
      <div class="clr">
        <!-- -->
      </div>
      <!-- menu finish -->
      <!-- top start -->
      <div id="container">
        <div id="line">
          <!-- -->

        </div>
      </div>
      <div class="clr">
        <!-- -->
      </div>
      <div id="containerBg1">
        <div class="padTop15">
          <!-- -->
        </div>

        <div class="clr">
          <!-- -->
        </div>
        <div id="titleText">REGISTER EMPLOYEE</div>
        <div class="clr">
          <!-- -->
        </div>
        <div class="padTop15">

          <!-- -->
        </div>
        <div class="clr">
          <!-- -->
        </div>
      </div>
      <div class="clr">
        <!-- -->
      </div>

      <!-- top finish -->
      <!-- data title start -->
      <div id="containerBg2">
        <div class="padTop2">
          <!-- -->
        </div>
        <div class="clr">
    <!-- -->
</div>
<form name="form" method="post" action="adminreg.php">
  <table align="center" width="546">
    <tr valign="baseline">
      <td nowrap align="right" width="95">Name:</td>
      <td nowrap align="right">
      <input name="name" type="text" size="32" style="font-size: 8pt; $style_name; float:left" value="<?php echo $name; ?>"></td>
      <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_name; ?></font></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" width="95">Address:</td>
      <td nowrap align="right">
<input name="address" type="text" size="32" style="font-size: 8pt; $style_address; float:left" value="<?php echo $address; ?>"></td>
      <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_address; ?></font></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" width="95">Address1:</td>
      <td nowrap align="right">
      <input name="address1" type="text" size="32" style="font-size: 8pt; $style_address1; float:left" value="<?php echo $address1; ?>"></td>
      <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_address1; ?></font></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" width="95">Address2:</td>
      <td nowrap align="right">
   <input name="address2" type="text" size="32" style="font-size: 8pt; $style_address2; float:left" value="<?php echo $address2 ;?>"></td>
      <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_address2; ?></font></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" width="95">Address3:</td>
      <td nowrap align="right">
   	<input name="address3" type="text" size="32" style="font-size: 8pt; $style_address3; float:left" value="<?php echo $address3; ?>"></td>
      <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_address3; ?></font></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" width="95">Address4:</td>
      <td nowrap align="right">
      <input name="address4" type="text" size="32" style="font-size: 8pt; $style_address4; float:left" value="<?php $address4; ?>"></td>
      <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_address4;?></font></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" width="95">County:</td>
      <td nowrap align="right">
   <input name="county" size="32" style="font-size: 8pt; $style_county; float:left" value="<?php echo $county; ?>"></td>
      <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_county ?></font></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" width="95">Zip:</td>
      <td nowrap align="right">
  <input name="zip" size="32" style="font-size: 8pt; $style_zip; float:left" value="<?php echo $zip; ?>"></td>
      <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_zip;?></font></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" width="95">Telephone:</td>
      <td nowrap align="right">
      <input name="telephone" size="32" style="font-size: 8pt; $style_telephone; float:left" value="<?php $telephone; ?>"></td>
      <td width="269"><font color="#FF0000" style="font-size: 8pt"><? echo $error_telephone; ?></font></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" width="95">Email:</td>
      <td nowrap align="right">
      <input name="email" size="32" style="font-size: 8pt; $style_email; float:left" value="<?php $email;?>"></td>
      <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_email;?></font></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" width="95">Username:</td>
      <td nowrap align="right">
    <input name="username" size="32" style="font-size: 8pt; $style_username; float:left"></td>
      <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_username; ?></font></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" width="95">Password:</td>
      <td nowrap align="right">
     <input name="password" size="32" style="font-size: 8pt; $style_password; float:left"type="password"></td>
      <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_password; ?></font></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" width="95"> </td>
      <td nowrap align="right">
        <input type=hidden name=action value="signup">
        <input type="submit" value="Insert record" style="float: left"> </td>
      <td width="269"> </td>
    </tr>
  </table>
</form>  

  </div>
    <!-- btm start -->
     <div id="containerBg1">
           <div class="padTop15"><!-- --></div>
              <div class="clr"><!-- --></div>
                </div>
                <div class="clr"><!-- --></div>
                <div id="container">
                   <div id="line"><!-- --></div>
                </div>
             <!-- btm finish -->
         </div>
      </div>
  </body>
</html>

 

The errors im getting now are

 

got no name

got no address1

got no address1

got no address2

got no address3

got no address4

got no county

got no zip

got no phone

got no mailgot no password

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\Admin_files\adminreg.php on line 99

 

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\xampp\htdocs\Admin_files\adminreg.php on line 99

 

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\Admin_files\adminreg.php on line 102

 

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\xampp\htdocs\Admin_files\adminreg.php on line 102

Error in SQL: Access denied for user 'ODBC'@'localhost' (using password: NO)

Link to comment
Share on other sites

You must have missed my example. Constants are not strings (ie, no quotes required).

 

<?php

define('_USER', 'root');
define('_PASS', '');
define('_ADMIN','admin'); 

//Connect to server and select database.
mysql_connect("127.0.0.1",_USER,_PASS)or die("cannot connect to server");
mysql_select_db(_ADMIN)or die("cannot select DB");

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.