php - Been looking at this for days, no idea. "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given -
this question has answer here:
okay, trying add user registration form site. i've been trying fix days , nothing i've tried seems work. i'm getting warning when fill in registration form , hit submit button.
warning: mysql_num_rows() expects parameter 1 resource, null given in /applications/xampp/xamppfiles/htdocs/tutorials/mysite/index.php on line 64
i have triple checked make sure syntax of database , rows same in script , in phpmyadmin, i'm lost , don't know here. have trouble connecting , doing queries/retrieving information phpmyadmin.
so far i've got (sorry code):
<?php $reg = $_post['reg']; // declaring variables prevent errors $fn = ""; //first name $ln = ""; //last name $un = ""; //username $em = ""; //email $em2 = ""; //email 2 $pswd = ""; //sign date $u_check = ""; //check if username exists //registration form $fn = strip_tags($_post['fname']); $ln = strip_tags($_post['lname']); $un = strip_tags($_post['username']); $em = strip_tags($_post['email']); $em2 = strip_tags($_post['email2']); $pswd = strip_tags($_post['password']); $pswd2 = strip_tags($_post['password2']); $d = date("y-m-d"); // year - month - day if ($reg) { if ($em == $em2) { //this block of code i'm having trouble at. // check if user exists $u_check = mysql_query("'select' username 'from' users 'where' username='$un'"); // count amount of rows username= $un $check = mysql_num_rows($u_check); //<<<<<<<<<<<<<<<<<<<<<<<<line 64 if ($check == 0) { //maybe should $u_check??\\ //check of fileds have been filled in if ($fn && $ln && $un && $em && $em2 && $pswd && $pswd2) { //check passwords match if ($pswd == $pswd2) { //check maximum length of username/first name/last name not exceed 25 characters. if (strlen($un) > 25 || strlen($fn) > 25 || strlen($ln) > 25) { echo "the maximum limit username/first name/ last name 25 characters!"; } else { //check see if password allowable length if (strlen($pswd) > 30 || strlen($pswd) < 5) { echo "your password must between 5 , 30 characthers long!"; } else { //encrypts password using md5 before sending database $pswd = md5($pswd); $pswd2 = md5($pswd2); $query = mysql_query("insert users values (' ', '$un', '$fn', '$ln', '$em', '$pswd', '$d', '0')"); die("<h2>welcome mysite</h2>login account started...."); } } } else { echo "your passwords don't match!"; } } else { echo "please fill in fields"; } } } } ?> once again, have been trying fixed days , still can't figure out going on.
use pdo
$sql= "select `username` `users` `username` = :username"; $stmt = $pdo->prepare($sql); $stmt->bindparam(':username', $un, pdo::param_str); $stmt->execute();
Comments
Post a Comment