Jump to content

This works...kinda


quiksilver02x

Recommended Posts

I have a script to check for duplicate username's on signup.  Even when there is no entry found and the script preforms the update statement, the error will come back indicating the requested name already exists.

 

#Check to see if requested name already exists
$name = $_POST['name'];
$siteid = $_POST['siteid'];
$checkname = mysql_query("SELECT * FROM projects WHERE url = '$name'");
$founduser = mysql_num_rows($checkname);

if ($founduser != 0) {
echo"$name already exists in the database.  Please select another name";}

if ($founduser == 0) {
mysql_query("UPDATE projects SET url = '$name' WHERE siteid = $siteid"); die; echo"URL updated successfully";}

 

If I remove the UPDATE statement and simply return an echo statement for each IF statement, everything works fine:

 

if ($founduser != 0) {
echo"$name already exists in the database.  Please select another name";}

if ($founduser == 0) {
echo"$name is available";}

 

So what's happening is, when $founduser == 0, the update script preforms just fine and the database is populated correctly, but then the entire script will then re-run itself and find the name that was just entered, resulting in $founduser != 0. 

:wtf:

 

How do I stop the script when it preforms the UPDATE statement?  I tried putting die; in after the UPDATE statement, but the entire script still re-runs itself.  I am pulling my hair out here...

Link to comment
https://forums.phpfreaks.com/topic/218466-this-workskinda/
Share on other sites

  • 2 weeks later...

When I saw your response I thought...Oh yeah!!  I figured it was the solution, but I am still having the same problem. 

 

I'm using jQuery to send the data to my PHP script...could there be something weird going on there?  I have tried everything possible to make the script work but have had no luck. 

Link to comment
https://forums.phpfreaks.com/topic/218466-this-workskinda/#findComment-1138776
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.