limiting account names

Reply

Join Date: Apr 2004
Posts: 759
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Solved Threads: 35
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

limiting account names

 
0
  #1
Jun 15th, 2004
ive been working on my login script, and ive come to a halt. i need some help with writing somthing that will check if the name has already been used

like



if ( $current_Username = $Database_username)
echo "sorry user name taken";

else
{
continue with rest of functions
}

where current_username = $_POST[username] (from the form)
and
Database_username = "SELECT * FROM reg_info WHERE name = '$current_Username')

ive tried things along those lines, but i always get errors. Does anyone know how to correctly do it??

thanks for any help that anyone can offer
Dont forget to spread the reputation to those that deserve!
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 118
Reputation: Arizona Web is an unknown quantity at this point 
Solved Threads: 2
Arizona Web's Avatar
Arizona Web Arizona Web is offline Offline
Junior Poster

Re: limiting account names

 
0
  #2
Jun 15th, 2004
If you don't post the errors and the code we can't help. There are too may things that could possibly hose your script up.
Need a website designer? arizona web design : phoenix web design : MCP Media intelligent web design and web development solutions. MCP Media is owned and operated by Chris Hooley - who happens to be a real nerd... on purpose :-)
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 759
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Solved Threads: 35
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: limiting account names

 
0
  #3
Jun 15th, 2004
so does that mean that im heading in the right direction with my code?
Dont forget to spread the reputation to those that deserve!
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 118
Reputation: Arizona Web is an unknown quantity at this point 
Solved Threads: 2
Arizona Web's Avatar
Arizona Web Arizona Web is offline Offline
Junior Poster

Re: limiting account names

 
-1
  #4
Jun 15th, 2004
No, that means I didn't look at it because you didn't post the errors.
Need a website designer? arizona web design : phoenix web design : MCP Media intelligent web design and web development solutions. MCP Media is owned and operated by Chris Hooley - who happens to be a real nerd... on purpose :-)
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 759
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Solved Threads: 35
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: limiting account names

 
0
  #5
Jun 15th, 2004
i was asking for you to look for errors, i wanted to know if that was on the right track.
Dont forget to spread the reputation to those that deserve!
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 118
Reputation: Arizona Web is an unknown quantity at this point 
Solved Threads: 2
Arizona Web's Avatar
Arizona Web Arizona Web is offline Offline
Junior Poster

Re: limiting account names

 
0
  #6
Jun 16th, 2004
I understand that Killer_Typo. PHP and MySQL both spit out error messages when you have an error. That makes debugging buggy code easier. That's why I showed you how to echo a mysql error after you try running a query. PHP errors stop the page and tell you which line you have a problem on. AT this point, I don't know if you have a PHP problem, a SQL logic problem, a problem with your form, or a SQL statement problem, or other.

Although I could read your code and likely debug it from just reading it, it would take ME, the guy who is attempting to help you with your code problem, one tenth the time to debug your code if I knew exactly what errors where being thrown. It would take YOU the same amount of time to copy and paste the error onto the page and post it as it does to type "I have an error". If you really don't want to explain the error, why would I want to try and debug it for you?
Need a website designer? arizona web design : phoenix web design : MCP Media intelligent web design and web development solutions. MCP Media is owned and operated by Chris Hooley - who happens to be a real nerd... on purpose :-)
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 759
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Solved Threads: 35
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: limiting account names

 
0
  #7
Jun 16th, 2004
lol meant to say wasnt asking for you to look for errors, but ill post the code in a minute when i get back up to my computer (downstairs right now). im sorry if i have to double post, but it wont let me edit my posts after i finish posting them.

EDIT:

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<a rel="nofollow" class="t" href="http://www.w3.org/TR/html4/loose.dtd" target="_blank">http://www.w3.org/TR/html4/loose.dtd</a>">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  5. <title>Register!</title>
  6. </head>
  7. <body>
  8. <table bordercolor="000000" border="1" cellpadding="0" cellspacing="0">
  9. <tr bgcolor="#C8D6E0">
  10. <td colspan="2" align="center" height="180">
  11. This will be the location of any banners and such
  12. </td>
  13. </tr>
  14. <tr>
  15. <td height="800" width="150" bgcolor="C8D6E0">
  16. This will Contain Information pertaining to the site (IE SITE NAV)
  17. </td>
  18. <td valign="top" width="800" bgcolor="#70899f">
  19. <form method="post" action="new_user.php">
  20. <input type="hidden" name="id" id="id" value="null">
  21. <table width="800" border="0" cellpadding="0" cellspacing="0">
  22. <tr>
  23. <td colspan="2" align="center" bgcolor="#535d6f">
  24. <font size="+1" color="ffffff">
  25. <p align="left"><b>Registration Info:</b>
  26. <font size="-">
  27. &nbsp;&nbsp;All feilds required except those marked with an *
  28. </font></p>
  29. </font>
  30. </td>
  31. </tr>
  32. <tr>
  33. <td align="left" bgcolor="70899f">
  34. <font color="#ffffff">
  35. <p><b>User Name:</b></p>
  36. </font>
  37. </td>
  38. <td align="left" bgcolor="70889f">
  39. <input type="text" name="usr_name" id="usr_name">
  40. </td>
  41. </tr>
  42. <tr>
  43. <td align="left" bgcolor="70899f">
  44. <font color="ffffff">
  45. <b>Password:</b>
  46. </font>
  47. <font size="-1" color="ffffff">passwords are case sensative:</font>
  48. </td>
  49. <td align="left" bgcolor="70889f">
  50. <input type ="password" name="usr_pass" id="usr_pass">
  51. </td>
  52. </tr>
  53. <tr>
  54. <td align="left" bgcolor="70899f">
  55. <font color="ffffff">
  56. <b>Confirm Password:</b>
  57. <font size="-1" color="ffffff">passwords are case sensative:</font>
  58. </font>
  59. </td>
  60. <td align="left" bgcolor="70889f">
  61. <input type ="password" name="con_usr_pass" id="con_usr_pass">
  62. </td>
  63. </tr>
  64. <tr>
  65. <td align="left" bgcolor="70899f">
  66. <font color="#ffffff">
  67. <p><b>E-Mail:</b></p>
  68. </font>
  69. </td>
  70. <td align="left" bgcolor="70889f">
  71. <input type="text" name="email" id="email">
  72. </td>
  73. </tr>
  74. <tr>
  75. <td align="left" bgcolor="70899f">
  76. <font color="#ffffff">
  77. <p><b>Confirm E-Mail:</b></p>
  78. </font>
  79. </td>
  80. <td align="left" bgcolor="70889f">
  81. <input type="text" name="con_email" id="con_email">
  82. </td>
  83. </tr>
  84. <tr>
  85. <td align="left" bgcolor="70889f">
  86. <font color="#ffffff">
  87. <p><b>Gender:</b></p>
  88. </font>
  89. </td>
  90. <td align="left" bgcolor="70889f">
  91. <select name="gender" id="gender">
  92. <option id="unknown">Unknown</option>
  93. <option id="male">Male</option>
  94. <option id="female">Female</option>
  95. </select>
  96. </td>
  97. </tr>
  98. <tr>
  99. <td align="left" bgcolor="70899f">
  100. <font color="#ffffff">
  101. <p><b>DOB:</b></p>
  102. </font>
  103. </td>
  104. <td align="left" bgcolor="70889f">
  105. <select name="month" id="month">
  106. <option id="1">Jan</option>
  107. <option id="2">Feb</option>
  108. <option id="3">Mar</option>
  109. <option id="4">Apr</option>
  110. <option id="5">May</option>
  111. <option id="6">Jun</option>
  112. <option id="7">Jul</option>
  113. <option id="8">Aug</option>
  114. <option id="9">Sep</option>
  115. <option id="10">Oct</option>
  116. <option id="11">Nov</option>
  117. <option id="12">Dec</option>
  118. </select>
  119. <select name="day" id="day">
  120. <option id="1">1</option>
  121. <option id="2">2</option>
  122. <option id="3">3</option>
  123. <option id="4">4</option>
  124. <option id="5">5</option>
  125. <option id="6">6</option>
  126. <option id="7">7</option>
  127. <option id="8">8</option>
  128. <option id="9">9</option>
  129. <option id="10">10</option>
  130. <option id="11">11</option>
  131. <option id="12">12</option>
  132. <option id="13">13</option>
  133. <option id="14">14</option>
  134. <option id="15">15</option>
  135. <option id="16">16</option>
  136. <option id="17">17</option>
  137. <option id="18">18</option>
  138. <option id="19">19</option>
  139. <option id="20">20</option>
  140. <option id="21">21</option>
  141. <option id="22">22</option>
  142. <option id="23">23</option>
  143. <option id="24">24</option>
  144. <option id="25">25</option>
  145. <option id="26">26</option>
  146. <option id="27">27</option>
  147. <option id="28">28</option>
  148. <option id="29">29</option>
  149. <option id="30">30</option>
  150. <option id="31">31</option>
  151. </select>
  152. <input type="text" name="year" id="year" maxlength="4" size="4">
  153. </td>
  154. </tr>
  155. <tr>
  156. <td align="left" bgcolor="70889f">
  157. <font color="#ffffff">
  158. <p><b>Alternate E-Mail:<i>*</i></b></p>
  159. </font>
  160. </td>
  161. <td align="left" bgcolor="70889f">
  162. <input type="text" name="alt_email" id="alt_email">
  163. </td>
  164. </tr>
  165. <tr>
  166. <td align="left" valign="top" bgcolor="70889f">
  167. <font color="ffffff">
  168. <p><b>Interests:*</b></p>
  169. </font>
  170. </td>
  171. <td align="left" bgcolor="70889f">
  172. <textarea rows="5" cols="20" name="interests" id="interests">200 character max</textarea>
  173. </td>
  174. </tr>
  175. <tr>
  176. <td align="left" valign="top" bgcolor="70889f">
  177. <font color="ffffff">
  178. <p><b>Hobbies:*</b></p>
  179. </font>
  180. </td>
  181. <td align="left" bgcolor="70889f">
  182. <textarea rows="5" cols="20" name="hobbies" id="hobbies">200 charcater max</textarea>
  183. </td>
  184. </tr>
  185. <tr>
  186. <td colspan="2" align="center" valign="top" bgcolor="70889f">
  187. <input type="submit">
  188. </td>
  189. </tr>
  190. </table>
  191. </form>
  192. </td>
  193. </tr>
  194. </table>
  195. </body>
  196. </html>

heres the PHP that submits into the database, but is supposed to first check to see if the name has already or not already been used. ive left that part in the comment.
[php]
<?php
$DBhost = "localhost";//location of mySQL on server/site
$DBuser = "michael";//User name for logging onto mySQL
$DBpass = "";//Password for logging onto mySQL
$DBName = "registration";//Name of the databse for logging into
$Table = "reg_info";//Name of the Table to be used steps to create are included
$usr_name = "$_POST[usr_name]";//Name that the person gave on the form
$usr_pass = "$_POST[usr_pass]";//Password use uses
$con_usr_pass = "$_POST[con_usr_pass]";//confirmation of the password
$email = "$_POST[email]";//users email
$con_email = "$_POST[con_email]";//confirmation of the email
$gender = "$_POST[gender]";//their gender
$month = "$_POST[month]";//month they were born
$day = "$_post[day]";//day they were born
$year = "$_POST[year]";//year they were born
$alt_email = "$_POST[alt_email]";//any alternate emails they might use
$interests = "$_POST[interests]";//their interests
$hobbies = "$_POST[hobbies]";//their hobbies

mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); //connecting to the database using the variable set
@mysql_select_db("$DBName") or die("Unable to select database $DBName"); //at connection to the databse select DBNAME (phpforms) or tell that it couldnt connect
$sqlquery = "SEARCH * FROM $Table WHERE usr_name = '$_POST[usr_name]'";
$results = mysql_query($sqlquery);
if ($results = $usr_name)
//(!$results)
echo "sorry that user name has been taken! please use your browsers back button and try a different one!";
//echo (mysql_error());
else
{
mysql_close();
if ($usr_pass != $con_usr_pass)
echo "sorry the passwords to not match, please use your browsers back button to fix this error";
else
{
if ($email != $con_email)
echo "sorry the Emails you provided do not match, please use your browsers back button to fix this error";
else
{
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); //connecting to the database using the variable set
@mysql_select_db("$DBName") or die("Unable to select database $DBName"); //at connection to the databse select DBNAME (phpforms) or tell that it couldnt connect
$sqlquery = "INSERT INTO $Table VALUES('$id','$usr_name','$usr_pass','$email','$gender','$month','$_POST[day]','$year','$alt_email','$interests','$hobbies')";

$results = mysql_query($sqlquery); //query the results
mysql_close();


echo "Information has been submitted into the database!";
}
}
}
?>
[/php]

i dont get any errors, i always get the if in the first if statment, saying that the username is taken when in fact its not. ive tried swaping the Search for Select in the mysql part.
Dont forget to spread the reputation to those that deserve!
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 118
Reputation: Arizona Web is an unknown quantity at this point 
Solved Threads: 2
Arizona Web's Avatar
Arizona Web Arizona Web is offline Offline
Junior Poster

Re: limiting account names

 
0
  #8
Jun 16th, 2004
If you are doing a comparison you need to use "==" instead of "="

if ($results = $usr_name)

is always true.
Need a website designer? arizona web design : phoenix web design : MCP Media intelligent web design and web development solutions. MCP Media is owned and operated by Chris Hooley - who happens to be a real nerd... on purpose :-)
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 759
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Solved Threads: 35
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: limiting account names

 
0
  #9
Jun 16th, 2004
another problem solved, thank sir!

NOOOOO spoke too soon. now it submits it, even if the name is in there twice. maybe my SQL formatting is off? maybe?

lol i do have an error in my syntax, now its about finding what it is and the correct syntax to use. to the mysql manual!
Dont forget to spread the reputation to those that deserve!
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 118
Reputation: Arizona Web is an unknown quantity at this point 
Solved Threads: 2
Arizona Web's Avatar
Arizona Web Arizona Web is offline Offline
Junior Poster

Re: limiting account names

 
0
  #10
Jun 16th, 2004
not to be a jerk... but I am trying to help you, and I have helped you solve two programming problems since yesterday, and I see in my control panel that you gave me a negative reputation thing. What's up with that Killer_Typo?
Need a website designer? arizona web design : phoenix web design : MCP Media intelligent web design and web development solutions. MCP Media is owned and operated by Chris Hooley - who happens to be a real nerd... on purpose :-)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC