SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL Query Error

    Hello, can anyone help with the mysql error I'm having!
    Error message :

    SELECT * FROM `tbl_info_admin` WHERE u_name=''
    Warning: Wrong parameter count for mysql_query() in /home/foodecrp/public_html/beta2/register.php on line 12
    Error: with query


    Here is the code:

    Code PHP:
    <?php
    session_start();
    include "config.php";
    $fullname=$_POST['f_name'].$_POST['l_name'];
    $email=$_POST['email'];
    $u_name=$_POST['u_name'];
    $u_pass=$_POST['pass'];
    $user_type=$_POST['u_type'];
     
    $sql="SELECT * FROM `tbl_info_admin` WHERE u_name='$u_name'";
    echo $sql;
    mysql_query(); <-----Line 12 ------->
    echo mysql_error();  
    $num=mysql_num_rows(mysql_query($sql)) or die("Error: ". mysql_error(). " with query ". $query);
     
    if($_POST['submit'])
    	{
    		if($u_pass==$_POST['re_pass'])
    			{
    				if($num>0)
    					{
    						$msg="UserName Already Exist.";
    					}
    					else
    					{
    						$query="INSERT INTO `tbl_info_admin` VALUES
    														(
    														 	'$fullname',
    															'$email',
    															'$u_name',
    															'$u_pass',
    															'$user_type'
    													)";
    						if(mysql_query($query))
    							{
    								$con_msg="Congragulations, $fullname. You are successfully registered.";
    							}
    					}
    			}
    			else
    			{
    				$msg_match="Password does not match.";
    			}
    	}
    ?>

  2. #2
    SitePoint Zealot Gman's Avatar
    Join Date
    Jan 2002
    Location
    Sarasota, FL
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change line 12 to $query = mysql_query($sql);

    Remove mysql_query() from num_rows and add $query

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Gman View Post
    Change line 12 to $query = mysql_query($sql);

    Remove mysql_query() from num_rows and add $query

    Did that! New error shows up now!

    Parse error: syntax error, unexpected T_VARIABLE in /home/foodecrp/public_html/beta2/register.php on line 14



    Code PHP:
    <?php
    session_start();
    include "config.php";
    $fullname=$_POST['f_name'].$_POST['l_name'];
    $email=$_POST['email'];
    $u_name=$_POST['u_name'];
    $u_pass=$_POST['pass'];
    $user_type=$_POST['u_type'];
     
    $sql="SELECT * FROM `tbl_info_admin` WHERE u_name".$u_name;
    $query=mysql_query($sql)
     
     
    $num=mysql_num_rows($query) or die("Error: ". mysql_error(). " with query ". $query);[B]<----Line 14[/B]
     
    if($_POST['submit'])
    	{
    		if($u_pass==$_POST['re_pass'])
    			{
    				if($num>0)
    					{
    						$msg="UserName Already Exist.";
    					}
    					else
    					{
    						$query="INSERT INTO `tbl_info_admin` VALUES
    														(
    														 	'$fullname',
    															'$email',
    															'$u_name',
    															'$u_pass',
    															'$user_type'
    													)";
    						if(mysql_query($query))
    							{
    								$con_msg="Congragulations, $fullname. You are successfully registered.";
    							}
    					}
    			}
    			else
    			{
    				$msg_match="Password does not match.";
    			}
    	}
    ?>

  4. #4
    SitePoint Zealot Gman's Avatar
    Join Date
    Jan 2002
    Location
    Sarasota, FL
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $query = mysql_query($sql) is missing the ;

  5. #5
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    Incidentally,
    PHP Code:
    $num=mysql_num_rows($query) or die("Error: "mysql_error(). " with query "$query);[B]<----Line 14[/B
    $query isnt going to tell you anything.
    Code:
    $num=mysql_num_rows($query) or die("Error: ". mysql_error(). " with query ". $sql);
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  6. #6
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @StarLion & @Gman: did both , new error shows up now!

    here it goes:
    Error: with query SELECT * FROM `tbl_info_admin` WHERE u_name

    Code PHP:
    <?php
    session_start();
    include "config.php";
    $fullname=$_POST['f_name'].$_POST['l_name'];
    $email=$_POST['email'];
    $u_name=$_POST['u_name'];
    $u_pass=$_POST['pass'];
    $user_type=$_POST['u_type'];
     
    $sql="SELECT * FROM `tbl_info_admin` WHERE u_name".$u_name;
    $query=mysql_query($sql);
     
     
    $num=mysql_num_rows($query) or die("Error: ". mysql_error(). " with query ". $sql);
     
    if($_POST['submit'])
    	{
    		if($u_pass==$_POST['re_pass'])
    			{
    				if($num>0)
    					{
    						$msg="UserName Already Exist.";
    					}
    					else
    					{
    						$query="INSERT INTO `tbl_info_admin` VALUES
    														(
    														 	'$fullname',
    															'$email',
    															'$u_name',
    															'$u_pass',
    															'$user_type'
    													)";
    						if(mysql_query($query))
    							{
    								$con_msg="Congragulations, $fullname. You are successfully registered.";
    							}
    					}
    			}
    			else
    			{
    				$msg_match="Password does not match.";
    			}
    	}
    ?>

  7. #7
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    Incidentally,
    PHP Code:
    $num=mysql_num_rows($query) or die("Error: "mysql_error(). " with query "$query);[B]<----Line 14[/B
    $query isnt going to tell you anything.
    Code:
    $num=mysql_num_rows($query) or die("Error: ". mysql_error(). " with query ". $sql);
    Quote Originally Posted by Gman View Post
    $query = mysql_query($sql) is missing the ;
    Please check above post, forgot to tag ur quotes above! NEW ERROR

  8. #8
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,254
    Mentioned
    113 Post(s)
    Tagged
    1 Thread(s)
    You changed your query.

    $sql="SELECT * FROM `tbl_info_admin` WHERE u_name".$u_name;
    should be
    $sql="SELECT * FROM `tbl_info_admin` WHERE u_name = '".$u_name . "'";
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style

  9. #9
    SitePoint Zealot Gman's Avatar
    Join Date
    Jan 2002
    Location
    Sarasota, FL
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change, if($_POST['submit'])

    To

    if(isset($_POST['submit']) )

    Also put a or die mysql_error at the end of your mysql_query statement

  10. #10
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DaveMaxwell View Post
    You changed your query.

    $sql="SELECT * FROM `tbl_info_admin` WHERE u_name".$u_name;
    should be
    $sql="SELECT * FROM `tbl_info_admin` WHERE u_name = '".$u_name . "'";
    Quote Originally Posted by Gman View Post
    Change, if($_POST['submit'])

    To

    if(isset($_POST['submit']) )

    Also put a or die mysql_error at the end of your mysql_query statement

    Same error! See the error yourself: Visit beta2.foodiecorp.com & click Registration link

  11. #11
    SitePoint Zealot Gman's Avatar
    Join Date
    Jan 2002
    Location
    Sarasota, FL
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Post your code again please

  12. #12
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Gman View Post
    Post your code again please
    Code PHP:
    <?php
    session_start();
    include "config.php";
    $fullname=$_POST['f_name'].$_POST['l_name'];
    $email=$_POST['email'];
    $u_name=$_POST['u_name'];
    $u_pass=$_POST['pass'];
    $user_type=$_POST['u_type'];
     
    $sql="SELECT * FROM `tbl_info_admin` WHERE u_name = '".$u_name . "'"; 
    $query=mysql_query($sql) or die("Could nor select from table");
     
     
    $num=mysql_num_rows($query) or die("Error Error: ". mysql_error(). " with query ". $sql);
     
    if(isset($_POST['submit']) )
    	{
    		if($u_pass==$_POST['re_pass'])
    			{
    				if($num>0)
    					{
    						$msg="UserName Already Exist.";
    					}
    					else
    					{
    						$query="INSERT INTO `tbl_info_admin` VALUES
    														(
    														 	'$fullname',
    															'$email',
    															'$u_name',
    															'$u_pass',
    															'$user_type'
    													)";
    						if(mysql_query($query))
    							{
    								$con_msg="Congragulations, $fullname. You are successfully registered.";
    							}
    					}
    			}
    			else
    			{
    				$msg_match="Password does not match.";
    			}
    	}
    ?>

  13. #13
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    The 'or die' on mysql_num_rows() doesn't make much sense. Change the one on mysql_query() to give more info:
    PHP Code:
    $query=mysql_query($sql) or die("Error: "mysql_error(). " with query "$sql);
      
    $num=mysql_num_rows($query); 
    And before using user input in a query, sanitize it with mysql_real_escape_string (if it's a string, like in this case):
    PHP Code:
    $sql="SELECT * FROM `tbl_info_admin` WHERE u_name = '" mysql_real_escape_string($u_name) . "'"
    And you should put all these lines:
    PHP Code:
    $fullname=$_POST['f_name'].$_POST['l_name'];
    $email=$_POST['email'];
    $u_name=$_POST['u_name'];
    $u_pass=$_POST['pass'];
    $user_type=$_POST['u_type'];
     
    $sql="SELECT * FROM `tbl_info_admin` WHERE u_name = '" mysql_real_escape_string($u_name) . "'"
    $query=mysql_query($sql) or die("Error: "mysql_error(). " with query "$sql);
      
    $num=mysql_num_rows($query); 
    inside the if(isset($_POST['submit']) )
    Last edited by guido2004; Dec 2, 2011 at 01:02. Reason: added another consideration

  14. #14
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    The 'or die' on mysql_num_rows() doesn't make much sense. Change the one on mysql_query() to give more info:
    PHP Code:
    $query=mysql_query($sql) or die("Error: "mysql_error(). " with query "$sql);
      
    $num=mysql_num_rows($query); 
    And before using user input in a query, sanitize it with mysql_real_escape_string (if it's a string, like in this case):
    PHP Code:
    $sql="SELECT * FROM `tbl_info_admin` WHERE u_name = '" mysql_real_escape_string($u_name) . "'"
    And you should put all these lines:
    PHP Code:
    $fullname=$_POST['f_name'].$_POST['l_name'];
    $email=$_POST['email'];
    $u_name=$_POST['u_name'];
    $u_pass=$_POST['pass'];
    $user_type=$_POST['u_type'];
     
    $sql="SELECT * FROM `tbl_info_admin` WHERE u_name = '" mysql_real_escape_string($u_name) . "'"
    $query=mysql_query($sql) or die("Error: "mysql_error(). " with query "$sql);
      
    $num=mysql_num_rows($query); 
    inside the if(isset($_POST['submit']) )
    Thankyou so much!!! it worked at last


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •