473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how can i verify my login name if exists

hi
how can i check my login name in database from php page if it already exists
. so that i should not allow the same login name for another user . can any on help me with simple code
Feb 5 '10 #1
8 2266
zorgi
431 Expert 256MB
If SQL command of similar structure as this one

"SELECT loogin_name FROM users_table WHERE loogin_name = '$entered_login_name' "

returns anything than the chosen name already exists. Table, table field and variable names should be those in your system. I just made them up for explaining purposes.

Hope this helps
Feb 5 '10 #2
Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query("select name from table where name = new_login_name");
  2. $row = mysql_fetch_array($result);
  3. if($row[0]) 
  4.       echo "Err: select different name";
  5. else 
  6.      echo "okay, no prob with login name";
  7.  
  8.  
I guess this could be a hint :)
Feb 5 '10 #3
thanx for your help but i am getting this error


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in


line 8
okay, no prob with login nameMail Sent.Error: Column count doesn't match value count at row 1
Feb 5 '10 #4
Atli
5,058 Expert 4TB
That was not a copy/paste-able code. You need to re-write the SQL query and add error checking before it can work.

Post your code here and we may be able to point you in the right direction.
Feb 5 '10 #5
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  include 'conifig.php';
  3.  
  4.  $pass=md5($_POST[password]);
  5. $sql="INSERT INTO meconzee1_user VALUES ('','$_POST[firstname]','$_POST[lastname]','$_POST[middlename]','$_POST[radio]' ,'$_POST[loginname]','$pass',
  6. '$_POST[dateofbirth]','$_POST[address1]','$_POST[address2]','$_POST[state]','$_POST[city]','$_POST[country]','$_POST[pincode]','$_POST[mailid]','$_POST[answer1]','$_POST[answer2]','$_POST[answer3]')";
  7.  $result = mysql_query("select name from table where name = new_$_POST[loginname]");
  8.  $row = mysql_fetch_array($result);
  9.  if($row[0]) 
  10.        echo "Err: select different name";
  11.  else 
  12.       echo "okay, no prob with login name";
  13.  
  14. $to = $_POST[mailid];
  15. $subject = "Test mail";
  16. $message = " Hello! This is a simple email message.
  17.                your account has been created with the following login credentials 
  18.                username ='$_POST[loginname]'
  19.                password ='$pass'";
  20. $from = "phanisundar_sanka@example.com";
  21. $headers = "From: $from";
  22. mail($to,$subject,$message,$headers);
  23. echo "Mail Sent.";
  24. if (!mysql_query($sql,$con))
  25.   {
  26.   die('Error: ' . mysql_error());
  27.   }
  28.  
  29. echo"1 record is added";
  30.  
  31. mysql_close($con);
  32.   ?>
this is my code
Feb 5 '10 #6
Atli
5,058 Expert 4TB
Ok. There are a lot of problems in that code.

For example:
  • The code shabinesh posted was NOT supposed to be just copied into the middle of your project, unaltered. It was an example, which you have to adapt to your own project. The way you use it will not work. (Not well, at least.)
  • All text values in SQL queries need to be quoted. If they are not, the query will fail. (See your SELECT query)
  • You should NEVER put raw user input into a SQL query. If you do, you open yourself up to an SQL Injection attack. - All data meant to be included in a MySQL query should be run through the mysql_real_escape_string function first. - This is PHP security 101; the #1 security threat a PHP application faces. It is the first thing a hacker will try to exploit when attacking your web, so you should ALWAYS keep this in mind.
  • Strings should always be quoted. This includes array element names:
    Expand|Select|Wrap|Line Numbers
    1. $stuff = $_POST[stuff]; // INCORRECT
    2. $stuff = $_POST['stuff']; // CORRECT
    3.  
    4. $string = "Stuff: $_POST[stuff]"; // This may work...
    5. $string = "Stuff: {$_POST['stuff']}"; // But this is better.
    6.  
Feb 5 '10 #7
Markus
6,050 Expert 4TB
Furthermore, you should be checking that your $result variable is valid, i.e., your query ran successfully.

Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query( ... );
  2. if ($result === FALSE) {
  3.     /** Query failed */
  4.     print mysql_error();
  5.     exit;
  6. }
  7. $row = mysql_fetch_array();
  8. /** ... */
  9.  
Sounds like you need to brush up on your PHP/MySQL skills.
Feb 5 '10 #8
yes! its mere a hint, not copy-paste code. :D
Feb 5 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: bsandell | last post by:
I need to write a stored procedure to verify that a table exists and also that the user executing the stored procedure has access to the specified table. Any user can call this publicly...
0
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) :...
0
by: Freddie | last post by:
this is surely the wrong group, but you guys have been so helpful in the past ... i want to use the new forms authentication in asp.net 2.0 with sql server 2005 dev edition so i created a...
0
bartonc
by: bartonc | last post by:
#Boa:Dialog:DBConnectDialog import wx ##"""Given a set if login specs, create a dbServer instance and ## ensure that there is a valid, open connection to the database. ## If not, set the...
2
by: SM | last post by:
Hello, I've created this 'wonderful' function the embeds a youtube video in a specified div section using the Javascript DOM. Everything works OK... until I realize how bad the logical programming...
30
by: diane | last post by:
I've got an application running with table-based security: i capture the user's windows login with fOsusername, then have them enter a password checked against their username/login in my own table....
12
by: Fareast Adam | last post by:
I want to make sure all users those login are different in a time either on the same or different computer or web browser. Following are sample of my program which consist 4 different pages; ...
3
by: satishknight | last post by:
Hi, Can some one tell me how to change the validation sequence for the code pasted below, actually what I want it when any one enters the wrong login information (already registered users) then it...
1
by: geetamadhavi | last post by:
Hi All, I have developed a php applciaiton where a new window is opening on checking the whether valid user orntot how to make that in same window after checking i have die(' not valid user ' ); i...
10
by: DavidPr | last post by:
When I logout as one user and log in under a different user, it opens with the last user's information. User 1 - Unsername: Davey Jones User 2 - Unsername: David Smith I log out from Davey...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.