xem
November 29, 2011, 6:48pm
1
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.";
}
}
?>
Gman
November 29, 2011, 9:07pm
2
Change line 12 to $query = mysql_query($sql);
Remove mysql_query() from num_rows and add $query
xem
November 30, 2011, 7:14am
3
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.";
}
}
?>
Gman
November 30, 2011, 12:08pm
4
$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]);
xem
November 30, 2011, 6:13pm
6
@StarLion & @Gman : did both , new error shows up now!
here it goes:
Error: with query SELECT * FROM tbl_info_admin
WHERE u_name
<?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.";
}
}
?>
xem
November 30, 2011, 6:16pm
7
StarLion:
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]);
Please check above post, forgot to tag ur quotes above! NEW ERROR
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 . “'”;
Gman
November 30, 2011, 7:28pm
9
Change, if($_POST[‘submit’])
To
if(isset($_POST[‘submit’]) )
Also put a or die mysql_error at the end of your mysql_query statement
xem
December 1, 2011, 6:06pm
10
Gman:
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
Gman
December 1, 2011, 8:20pm
11
Post your code again please
xem
December 2, 2011, 6:02am
12
<?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.";
}
}
?>
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’]) )
xem
December 2, 2011, 3:57pm
14
guido2004:
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