Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

what's wrong with my code?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

what's wrong with my code?

Postby ImanLlusion » Tue Dec 04, 2012 8:49 pm

<?php
defined('__NOT_DIRECT') || define('__NOT_DIRECT',1);
include 'xxx-xxx.php';
if(isset($_POST)){
mysql_connect("xxx","xxx","xxx");
mysql_select_db("xxx");
if($_POST['xxx'] != $_POST['xxx']){
echo 'xxx';
}else if(!$_POST['xxx']){
echo 'xxx';
}else if(mysql_num_rows(mysql_query("select * from xxx where xxx='".mysql_real_escape_string($_POST['user_id'])."'"))){
echo 'xxx';
}else{
mysql_query("insert into xxx (xxx,xxx,xxx,xxx) values
('".mysql_real_escape_string($_POST['xxx'])."','".mysql_real_escape_string($_POST['xxx'])."',
'".md5($_POST['xxx'])."','xxx')");
echo "xxx";
}
}
?>

This error "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\test\php\multi-login\xxx.php on line 11"

what should i do? i'm running code in php 5.4.4... anyone help me?
ImanLlusion
New php-forum User
New php-forum User
 
Posts: 4
Joined: Tue Dec 04, 2012 8:38 pm

Re: what's wrong with my code?

Postby simplypixie » Wed Dec 05, 2012 9:18 am

I am not sure why you can't show your post data names or table and column names in your query as it won't hurt and can help people help you.

Anyway, the error is telling you that the value in your query is missing or incorrect (in this case the $_POST['user_id'] is either empty or an incorrect format). The first thing to do is dump your posted data to check the values are there
Code: Select all
var_dump($_POST);


I would also separate your mysql_num_rows from your mysql_query (in fact I have never seen this done before but there you go) to make error checking easier for one
Code: Select all
else {
var_dump($_POST);
$sql = "select * from xxx where xxx='".mysql_real_escape_string($_POST['user_id'])."'";
// If your posted data is correct echo your query to check and run in phpmyadmin
echo $sql;
$query = mysql_query($sql);
$num_rows = mysql_num_rows($query);
if ($num_rows > 0) {
echo 'xxx';
}
User avatar
simplypixie
php-forum Active User
php-forum Active User
 
Posts: 300
Joined: Sun Dec 11, 2011 12:51 am
Location: Shrewsbury, Shropshire

Re: what's wrong with my code?

Postby ImanLlusion » Wed Dec 05, 2012 5:55 pm

ok thank you to your respond on my post... ^_^
ImanLlusion
New php-forum User
New php-forum User
 
Posts: 4
Joined: Tue Dec 04, 2012 8:38 pm


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron