Help - Search - Members - Calendar
Full Version: Php & Mysql Help Needed!
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
LadyYepperz
I included a script on my newaccounts.php that will check to see if a screen name is already in use so that there are no dublicate entries.

If the screen name [scname] is found I want to close the DB. But instead Im getting this error
"Warning: Wrong parameter count for mysql_close() in /accounts/newaccts.php on line 27"

and the print statement for a successfully entry.
"Only one more step to complete registration. Please check your email for further instructions."

The submission IS NOT being received by the DB but my script is saying it is and sending the email.

My questions are.
1. Why does it have a problem with me closing the DB at this point? If I remove the close() the submission is entered into the DB.
2. Why is it continuing after the if statement? How do I stop this? Can I use break; inside an if statement?
3. How do i set up my if statements so that so that its not including the "confirmation of submission" print statement and sending out the email?

My whole script:
CODE
switch($_GET[action]){
    case "check"; //checks for blank fields
        if(strlen($_POST[scname])>0 && strlen($_POST[email])>0 && strlen($_POST[password])>0
&& strlen($_POST[passw2])>0 && $_POST[password] == $_POST[passw2]){

        // Connect to server, select database and table.
        $con = mysql_connect("$host", "$username", "$password")or die("cannot connect server" . mysql_error());
        mysql_select_db("$db_name")or die("cannot select DB" . mysql_error());
        $sql=("SELECT scname FROM $tbl")or die("cannot select tbl" . mysql_error());

        //screen name check
        $result=mysql_query($sql);
            while($rows=mysql_fetch_array($result)){    
            if($rows[scname] == $_POST[scname])
                print "<font color='#D5C513'><b>Submission Incomplete!</b><hr>$_POST[scname] is already in use. Chose another screen name and try again. You may try including the underscore, period, or dash in your choice.</font><hr>";

             mysql_close($sql, $con); //THIS IS THE LINE MY ERROR IS BEING REPORTED
             }
            
        $datetime=date("m/d/y, h:m"); //date time
        $sql="INSERT INTO $tbl (scname, password, datetime, email, code)
VALUES('$_POST[scname]', '$_POST[password]', '$datetime', '$_POST[email]', '$_POST[code]')";
            mysql_close($con);    
        //send email
        $body="Welcome and thank you for becoming a part of iEroticXpressions.com.  
Your screen name has been successfully created.  After you have confirmed your account you may begin posting.  Click on the link and use the activation key provided to complete your account registration. \n
http://www.ieroticxpressions.com/accounts/active.php \n\n";
        $body.="Screen Name: $_POST[scname]\n";
        $body.="Activation Key: $_POST[code]\n";
        $body.="Password: $_POST[password]\n";
        mail("$_POST[email]","IEX Mail",$body);
        print "Only one more step to complete registration.  Please check your email for further instructions.";
         }
    else {
        print "<font color='#D5C513'><b>Submission error!</b> Please try again.<hr>
1) Check to make sure you've filled out all of the fields.<br/>2) Make sure your passwords match and that you've used only<br />  alphanumeric characters (A-Z and/or 0-9).<br/>3) In all fields you may also use the underscore, period, or dash.<hr></font><br />";
        include("includes/newaccounts.inc.php");
    }
    break;
            
    default:
        include("includes/newaccounts.inc.php");
        break;
         }

If you like to see this mess in action you can find it here. Click Here
use the screen name: LadyYepperz

Pretty Please HELP Me!! wacko.gif
swordz
Look here. mysql_close expects 0 or 1 variables. You're giving it 2. So it's failing.

swordz
LadyYepperz
After changing that to mysql_close($con), it generated this error:

Warning: mysql_close(): 2 is not a valid MySQL-Link resource in /accounts/newaccts.php on line 27

its still hating that close command.
Jetteh22
Not sure if this is possible, havn't really ever used it..

What about just mysql_close();
swordz
That would probably work, but it is always better to specify, even if you only have one connection.

swordz
LadyYepperz
Thanx Guys!!

I was able to get the script to work as I needed it to.

Ok, I dont know how to close a thread... so, someone take care of that for me... thanx again

*** OK. Done. swordz ***
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.