HoTDaWg Posted March 15, 2007 Share Posted March 15, 2007 what is wrong with this code...its been driving me NUTS! <?php if(!empty($username)&&($email)){ $check1= "SELECT username FROM users WHERE username='".$username."'"; $sql1= mysql_query($check1,$c0nn); if(mysql_num_rows($check1) > 0 ){ $arrErrors['username_already_exists'] = 'The Username you Chose is Already Being used by another person.'; } $check2= "SELECT email FROM users WHERE email='".$email."'"; $sql1= mysql_query($check2,$c0nn); if(mysql_num_rows($check2) > 0 ){ $arrErrors['email_already_exists'] = 'The E-mail you Entered Already Exists in our Records.'; } } ?> i keep on getting the following error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/mediacir/public_html/validateme/submit.php on line 52 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/mediacir/public_html/validateme/submit.php on line 57 thanks HoTDaWg Quote Link to comment https://forums.phpfreaks.com/topic/42909-grrrmysql_num_rows/ Share on other sites More sharing options...
aebstract Posted March 15, 2007 Share Posted March 15, 2007 What do you want this code to do and what is it doing? We need some information to be able to help. Quote Link to comment https://forums.phpfreaks.com/topic/42909-grrrmysql_num_rows/#findComment-208397 Share on other sites More sharing options...
per1os Posted March 15, 2007 Share Posted March 15, 2007 if(mysql_num_rows($check1) > 0 ){ SHOULD BE if(mysql_num_rows($sql1) > 0 ){ Quote Link to comment https://forums.phpfreaks.com/topic/42909-grrrmysql_num_rows/#findComment-208399 Share on other sites More sharing options...
HoTDaWg Posted March 15, 2007 Author Share Posted March 15, 2007 <?php if(!empty($username)&&($email)){ $check1= "SELECT username FROM users WHERE username='".$username."'"; $sql1= mysql_query($check1,$c0nn); if(mysql_num_rows($sql1) > 0 ){ $arrErrors['username_already_exists'] = 'The Username you Chose is Already Being used by another person.'; } $check2= "SELECT email FROM users WHERE email='".$email."'"; $sql12= mysql_query($sql2,$c0nn); if(mysql_num_rows($sql2) > 0 ){ $arrErrors['email_already_exists'] = 'The E-mail you Entered Already Exists in our Records.'; } } ?> i am still getting the error message: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/mediacir/public_html/validateme/submit.php on line 57 :s wonder whats happening HoTDaWg Quote Link to comment https://forums.phpfreaks.com/topic/42909-grrrmysql_num_rows/#findComment-208410 Share on other sites More sharing options...
aebstract Posted March 15, 2007 Share Posted March 15, 2007 So much for knowing what it is you are trying to achieve vs what the code is doing. *shrugs* Quote Link to comment https://forums.phpfreaks.com/topic/42909-grrrmysql_num_rows/#findComment-208412 Share on other sites More sharing options...
per1os Posted March 15, 2007 Share Posted March 15, 2007 $sql12= mysql_query($sql2,$c0nn); if(mysql_num_rows($sql12) > 0 ){ $arrErrors['email_already_exists'] = 'The E-mail you Entered Already Exists in our Records.'; } } Changed $sql1 to $sql12 in the if statement. Quote Link to comment https://forums.phpfreaks.com/topic/42909-grrrmysql_num_rows/#findComment-208413 Share on other sites More sharing options...
HoTDaWg Posted March 15, 2007 Author Share Posted March 15, 2007 So much for knowing what it is you are trying to achieve vs what the code is doing. *shrugs* im sorry aebstract, this code is part of a registration form im making, it checks in the database if the email or username is already in the database. thanks for your help guys but i now my whole registration form is messed up grr... lol brb in 20 min while i ATTEMPT to figure it out myself :S thanks HoTDaWg Quote Link to comment https://forums.phpfreaks.com/topic/42909-grrrmysql_num_rows/#findComment-208431 Share on other sites More sharing options...
HoTDaWg Posted March 15, 2007 Author Share Posted March 15, 2007 alright, so, this script was functioning fully until i added in the following code. It works fine when i call upon it. <?php if(!empty($username)&&($email)){ $check1= "SELECT username FROM users WHERE username='".$username."'"; $checkit1= mysql_query($check1,$c0nn); if(mysql_num_rows($checkit1) > 0 ){ $arrErrors['username_already_exists'] = 'The Username you Chose is Already Being used by another person.'; } $check2= "SELECT email FROM users WHERE email='".$email."'"; $checkit2= mysql_query($check2,$c0nn); if(mysql_num_rows($checkit2) > 0 ){ $arrErrors['email_already_exists'] = 'The E-mail you Entered Already Exists in our Records.'; } } ?> The success message is echoed, but the email is not sent. This is the registration form: <?php /*Begin the long awaited profile.php. Copright (C) March 12th 2007. comon man i spent a long time on this:P*/ //It Begins. $c0nn = mysql_connect("localhost","*****","********")or die(mysql_error()); mysql_select_db("********"); define('******',true); include "functions.php"; //Get it, get it now. $arrErrors = array(); if(isset($_POST['submit'])){ $username = $_POST['username']; $password = $_POST['password']; $email = $_POST['email']; $submit = $_POST['submit']; $ip= $_SERVER['REMOTE_ADDR']; $date = date('d m Y @ h:i:s A'); //Empty?! I THINK NOT! if(empty($username)){ $arrErrors['username_left_blank'] = 'The Username Field was left blank'; } if(empty($password)){ $arrErrors['password_left_blank'] = 'The Pasword Field was left blank'; } if(empty($email)){ $arrErrors['email_left_blank'] = 'The E-Mail Field was left blank'; } //Too Long?! I THINK NOT! if(strlen($username) > 12){ $arrErrors['user_too_long'] = 'The Username Field exeeds the limit of <b>12</b> characters'; } if(strlen($password) > 14){ $arrErrors['pass_too_long'] = 'The Password Field exeeds the limit of <b>14</b> characters'; } if(strlen($email) > 50){ $arrErrors['email_too_long'] = 'The Email Field exeeds the limit of <b>50</b> characters'; } //Invalid characters...grr... if (preg_match('|[^-_a-z\d]|i', $username)) { $arrErrors['user_invalid_charcters'] = 'The Username Field has (an) invalid character(s).'; } if (preg_match('|[^-_a-z\d]|i', $password)) { $arrErrors['pass_invalid_characters'] = 'The Password Field has (an) invalid character(s).'; } //Just a minute, dear $username = mysql_real_escape_string($username); $email = mysql_real_escape_string($email); //Check it if(!empty($username)&&($email)){ $check1= "SELECT username FROM users WHERE username='".$username."'"; $checkit1= mysql_query($check1,$c0nn); if(mysql_num_rows($checkit1) > 0 ){ $arrErrors['username_already_exists'] = 'The Username you Chose is Already Being used by another person.'; } $check2= "SELECT email FROM users WHERE email='".$email."'"; $checkit2= mysql_query($check2,$c0nn); if(mysql_num_rows($checkit2) > 0 ){ $arrErrors['email_already_exists'] = 'The E-mail you Entered Already Exists in our Records.'; } } //FINALLY! if(count($arrErrors) < 1){ //Secure the variables $password = mysql_real_escape_string($password); $email=strip_tags($email); $username=strip_tags($username); $password=strip_tags($password); $email=addslashes($email); $username=addslashes($username); $password=addslashes($password); //Create the display name $displayname =&$username; $username=strtolower($username); $displayname = mysql_real_escape_string($displayname); //final filter $password = md5($password); //Insert now $emailcode = rand(0,100000000); $status = "incomplete"; $sql = "INSERT INTO `users` (`id`,`displayname`,`username`,`password`, `email`,`usercode`,`status`,`date`,`ip`) VALUES (' ', '$displayname', '$username', '$password', '$email', ' ', '$status', '$date', '$ip')"; $result=mysql_query($sql,$c0nn); if($result){ mysql_close(); successmail(); echo "Your registration is almost complete, please check your email which you provided us with in order to verify your email address. If you do not recieve your email within the next 24 hours this is an error with your email service provider. Thank you for registrating!"; }else{ errormail(); echo "An unexpected error has occurred. Your registration was not complete."; } }else{ $strError = 'Please check the following and try again:<br>'; // Get each error and add it to the error string // as a list item. foreach ($arrErrors as $key => $value){ $strError .="<li><b>Error Type:</b>{$key} <b>Error message:</b> {$value}</li>"; } echo $strError; ?> <form name="hey" action="<?php echo $_SERVER[php_SELF];?>" method="POST"> <input type="text" maxlength="12" name="username" value="<?php echo $_POST['username']; ?>"><br> <input type="text" name="password" value="<?php echo $_POST['password']; ?>" maxlength="14"><br> <input type="text" maxlength="80" name="email" value="<?php echo $_POST['email']; ?>"><br> <input type="submit" name="submit" value="submit"></form> <?php } }else{ echo form(); } ?> functions.php <?php /* begin*/ if(!defined('*******')){ echo "You accessed this page incorrectly."; exit(); }else{ function form(){ $submit = $_GET['submit']; if(!isset($submit)){ echo '<form name="hey" action="'.$_SERVER[php_SELF].'" method="POST"><input type="text" maxlength="12" name="username" value=""><br><input type="text" name="password" value="" maxlength="50"><br><input type="text" maxlength="80" name="email" value=""><br><input type="submit" name="submit" value="submit">'; } } function successmail(){ $message="Thanks for registering on our website! Open a new window and go to http://www.mediacircus.yurx.com/validateme/index.php?email=$email&emailcode=$emailcode&mode=verify to complete your registration. thanks."; $to = &$email; $subject = 'Validate Yourself'; $headers = 'From: *******@****.com' . "\r\n" . 'Reply-To: *******@****.com' . "\r\n" . //This statement helps out with spam filters 'X-Mailer: PHP/' . phpversion(); //Send the email mail($to, $subject, $message, $headers); } function errormail(){ $browser = $_SERVER['HTTP_USER_AGENT']; $to = '*******@****.com'; $message = "Userip: $ip Date: $date Username: $username Password: $password Email: $email Browser: $browser"; $subject = "Registration Form Error"; $headers = 'From: *******@****.com' . "\r\n" . 'Reply-To: *******@****.com' . "\r\n" . //This statement helps out with spam filters 'X-Mailer: PHP/' . phpversion(); //Send the email mail($to, $subject, $message,$headers); } } ?> to sum up, in the registration form itself, the success message is echoed. the email however (which is in functions.php) does not send. thanks, HoTDaWg Quote Link to comment https://forums.phpfreaks.com/topic/42909-grrrmysql_num_rows/#findComment-208465 Share on other sites More sharing options...
HoTDaWg Posted March 16, 2007 Author Share Posted March 16, 2007 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/42909-grrrmysql_num_rows/#findComment-208500 Share on other sites More sharing options...
per1os Posted March 16, 2007 Share Posted March 16, 2007 I do not see how $to = &$email; is equal to anything, $email is not global and no parameters are being passed in, perhaps that is where you are going wrong? Quote Link to comment https://forums.phpfreaks.com/topic/42909-grrrmysql_num_rows/#findComment-208575 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.