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:

<?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.";
			}
	}
?>

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

<?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.";
			}
	}
?>

$query = mysql_query($sql) is missing the ;

Incidentally,


$num=mysql_num_rows($query) or die("Error: ". mysql_error(). " with query ". $query);[B]<----Line 14[/B]

$query isnt going to tell you anything.


$num=mysql_num_rows($query) or die("Error: ". mysql_error(). " with query ". [B]$sql[/B]);

@StarLion & @Gman: did both , new error shows up now!

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

&lt;?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&gt;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.";
			}
	}
?&gt;

Please check above post, forgot to tag ur quotes above! NEW ERROR :frowning: :frowning:

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 . “'”;

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

Post your code again please

&lt;?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&gt;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.";
			}
	}
?&gt;

The ‘or die’ on mysql_num_rows() doesn’t make much sense. Change the one on mysql_query() to give more info:


$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):

$sql="SELECT * FROM `tbl_info_admin` WHERE u_name = '" . mysql_real_escape_string($u_name) . "'"; 

And you should put all these lines:

$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