Jump to content

[SOLVED] $sqlcheckn = mysql_query help


NSW42

Recommended Posts

Heya all, what im trying to do and without success is to get my nickname change script to detect the nickname is available or taken, it updates the nick fine but i need it to say nick in use try again, ive tried playing around with it but im still very new to all this, my coding posted below and any help is appreciated, thanks...

 

<? 

include("config.php");

 

include("user_check.php");

 

print("<left><a href='$PHP_SELF?action=pass'><a href='$PHP_SELF?action=profile'><font color=red></a></center><BR><BR>");

$sql = mysql_query("SELECT * FROM users WHERE username = '$_COOKIE[username]'");

$row = mysql_fetch_array($sql);

 

 

if($action==update)

{

$update4 = mysql_query("UPDATE users SET nickname = '$_POST[nickname]' WHERE username = '$_COOKIE[username]'");

print("Your information is now updated.");

}

 

 

 

{

print("

<table>

<tr><td align=center><font color=ffffcc><b>Nickname Information</b></td></tr>

 

 

<form action=$PHP_SELF?action=update method=post>

<tr>

  <td><font color=red>Current NickName</td>

  <td><input type=text name=nickname value='$row[nickname]' size=25 maxlength=60></td>

 

</tr>

<tr>

 

 

</td>

</tr>

<tr>

 

</tr>

<tr>

<tr><td align=center><input type=submit value='Click To Update'></td></tr>

</form>

</table>

 

 

this is the $sqlcheckn that works fine for new signups that ive been trying to add into the above script with no luck..

 

 

$sqlcheckn = mysql_query("SELECT * FROM users WHERE nickname = '$_POST[nickname]'");

$checkn = mysql_num_rows($sqlcheckn);

 

if((!$nickname) || ($checkn > 0))

 

if($checkn > 0)

{

print("Nickname already in use!<BR>");

unset($nickname);

}

 

 

 

Link to comment
Share on other sites

Instead of

 

$update4 = mysql_query("UPDATE users SET nickname = '$_POST[nickname]' WHERE username = '$_COOKIE[username]'");

 

use

 

$sql = "UPDATE users SET nickname = '$_POST[nickname]' WHERE username = '$_COOKIE[username]'";
$update4 = mysql_query($sql) or die("Mysql error in $sql\nError: " . mysql_error());

 

Make that change to each mysql_query() call.  Otherwise you will not be notified of errors.

Link to comment
Share on other sites

it updates the nickname without a hiccup now, but if someone puts in the same nick it adds it to the db, thats where i need the sqlcheck so it can say no nickname taken or if its not, then just update it, sorry if  I may have gotten your reply wrong as im still very new to this and trying very hard to learn it as i go along...

Link to comment
Share on other sites

ok i kinda worked out what you were saying and added in this below, it now detects if nickname is taken, but it wont halt and inserts the nickname, half way there i guess, anymore ideas so i can finsih it off would be good thanks...

 

 

<? 

include("config.php");

 

include("user_check.php");

 

print("<left><a href='$PHP_SELF?action=pass'><a href='$PHP_SELF?action=profile'><font color=red></a></center><BR><BR>");

$sql = mysql_query("SELECT * FROM users WHERE username = '$_COOKIE[username]'");

$row = mysql_fetch_array($sql) or die("Mysql error in $sql\nError: " . mysql_error());

$sqlcheckn = mysql_query("SELECT * FROM users WHERE nickname = '$_POST[nickname]'");

$checkn = mysql_num_rows($sqlcheckn);

 

if((!$nickname) || ($checkn > 0))

 

if($checkn > 0)

{

print("Nickname already in use!<BR>");

unset($nickname);

}

if($action==update)

{

$sql = "UPDATE users SET nickname = '$_POST[nickname]' WHERE username = '$_COOKIE[username]'";

$update4 = mysql_query($sql) or die("Mysql error in $sql\nError: " . mysql_error());

print("Your information is now updated.");

}

 

 

 

{

print("

<table>

<tr><td align=center><font color=ffffcc><b>Nickname Information</b></td></tr>

 

Link to comment
Share on other sites

<?
include("config.php");

include("user_check.php");

print("<left><a href='$PHP_SELF?action=pass'><a href='$PHP_SELF?action=profile'><font color=red>[/url]</center><BR><BR>");
$sql = mysql_query("SELECT * FROM users WHERE username = '$_COOKIE[username]'");
$row = mysql_fetch_array($sql) or die("Mysql error in $sql\nError: " . mysql_error());
$sqlcheckn = mysql_query("SELECT * FROM users WHERE nickname = '$_POST[nickname]'");

if($action==update) {
if(mysql_num_rows($sqlcheckn) > 0)
{
print("Nickname already in use!<BR>");
unset($nickname);
} else {
$sql = "UPDATE users SET nickname = '$_POST[nickname]' WHERE username = '$_COOKIE[username]'";
$update4 = mysql_query($sql) or die("Mysql error in $sql\nError: " . mysql_error());
print("Your information is now updated.");
        }
}
?>

Link to comment
Share on other sites

i tried that and got errors everywhere  :-\ heres the complets script if u could look at it and see whats going on, sorry to be a pain and thanks agian..

 

<H3>Edit Your Nickname</H3>

 

<td width='240'>

 

<? 

include("config.php");

 

include("user_check.php");

 

print("<left><a href='$PHP_SELF?action=pass'><a href='$PHP_SELF?action=profile'><font color=red></a></center><BR><BR>");

$sql = mysql_query("SELECT * FROM users WHERE username = '$_COOKIE[username]'");

$row = mysql_fetch_array($sql) or die("Mysql error in $sql\nError: " . mysql_error());

$sqlcheckn = mysql_query("SELECT * FROM users WHERE nickname = '$_POST[nickname]'");

$checkn = mysql_num_rows($sqlcheckn);

 

if((!$nickname) || ($checkn > 0))

 

if($checkn > 0)

{

print("Nickname already in use!<BR>");

unset($nickname);

}

if($action==update)

{

$sql = "UPDATE users SET nickname = '$_POST[nickname]' WHERE username = '$_COOKIE[username]'";

$update4 = mysql_query($sql) or die("Mysql error in $sql\nError: " . mysql_error());

print("Your information is now updated.");

}

 

 

 

{

print("

<table>

<tr><td align=center><font color=ffffcc><b>Nickname Information</b></td></tr>

 

 

<form action=$PHP_SELF?action=update method=post>

<tr>

  <td><font color=red>Current NickName</td>

  <td><input type=text name=nickname value='$row[nickname]' size=25 maxlength=60></td>

 

</tr>

<tr>

 

 

</td>

</tr>

<tr>

 

</tr>

<tr>

<tr><td align=center><input type=submit value='Click To Update'></td></tr>

</form>

</table>

 

");

}

 

 

{

 

include("$sitepath/html/footer.php");

exit;

 

}

include("$sitepath/html/footer.php");

?>

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.