Question by : How to fix php error Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given ?
I’m following a tutorial on php private messaging system.
On pm.inbox.php , I’m facing these errors.
Warning: mysql_num_rows() expects parameter 1 to be resource,
boolean given in C:\wamp\www\post\includes\pm_inbox.php on line 48
Warning: mysql_fetch_array() expects parameter 1 to be resource,
string given in C:\wamp\www\post\includes\pm_inbox.php on line 59
pm_inbox.php code is here.
session_start();
require_once 'connect_i.php';
/*$ email = $ _POST['email'];*/
$ myConnection = mysqli_connect("$ db_host",
"$ db_username","$ db_pass","$ db_name")
or die("Could Not Connect to MySQL");
$ sqlCommand = " SELECT id, email FROM users
WHERE email='" . $ _SESSION['email'] . "' ";
$ query = mysqli_query($ myConnection,
$ sqlCommand) or die (mysqli_error());
while ($ row = mysqli_fetch_array($ query)){
$ pid = $ row["id"];
$ email = $ row["email"];
}
mysqli_free_result($ query);
$ sqlCommand =
" SELECT COUNT(id) AS numbers FROM pm_inbox
WHERE userid = '$ pid' ";
$ query = mysqli_query($ myConnection, $ sqlCommand) or die (mysql_error());
$ result = mysqli_fetch_assoc($ query);
$ inboxMessages = $ result['numbers'];
?>
PHP Private message tutorial
Welcome back
Welcome back
require_once "connect.php";
$ sql = " SELECT * FROM pm_inbox WHERE userid =
'$ pid' ORDERED by DESC ";
$ result = mysql_query($ sql);
$ count = mysql_num_rows($ result);
?>
Please Login
Can Some one tell me what is the actual reason ?
I try to find in google but it tells that mysql query is failed.
If it is, then how to make a query working?
Best answer:
Answer by Ratchetr This call:
$ result = mysql_query($ sql);
is failing, and returning false. When you pass false (which is what will be in $ result to mysql_num_rows or mysql_fetch_array, you will get the error message you are seeing.
The reason it is failing is that this query is wrong:
SELECT * FROM pm_inbox WHERE userid =
‘$ pid’ ORDERED by DESC
Question by M: WebHosting Reseller?
I have two questions about webhosting reseller;s pro gramme
1- As a webhosting reseller, why the disk space is important for me?
2-What is the best webhosting company that offer competitive and affordable prices with WHM/cPanel control panel?
please advice
Best answer:
Answer by desertcities There are many web hosting reseller accounts out there. You need to shop around and see what each offers. Many resellers today are reselling other reseller services. If that makes sense. All using the same larger company’s hardware and bandwidth infastructure, but each having a little different look.
To answer your questions:
1. Disk space becomes important only if the reseller package you select gives you little hard drive space. Most give you enough space to accommodate the majority of your web hosting customers and more.
2. You really need to search and visit each site and see what you get for your money. You might find it advantageous to get your own dedicated server or a VPS server. Just make sure you get enough RAM on your machine and that it comes pre-installed with lots of software, if possible.
I use 1and1.com VPS plus Lypha.com and HostGater.com reseller services. I can share with you the things that are important to me and what to look for.
1. Make sure the web hosting reseller company is solid and that they have a good customer support program. If they don’t offer even a telephone number to call for help, find another.
2. Ask how many domains you can host and what they charge for dedicated IP addresses. Some can go up to $ 5.00 per dedicated IP per domain a month! You need a dedicated IP for any customer of yours who runs a SSL Certificate.
3. Ask how many concurrent TCP/IP connections you can have at any given time. I was in shock when one of my clients told me I could only have 10 simultaneous connections to their server, my server, at any given time. My own IP was being blacklisted to my own rented server when I went past 10 connections. How absurd is that?
4. Try to find a reseller that includes a nice billing system for you to use and to bill your clients.
5. Ask if their web servers are also the SQL and email servers too. If they are and if they oversell reseller packages using the same servers, your customers could be stuck with slowdowns and even crashes that close their sites. You might want to check to see how many other domains are on the same server you’re using and check to see if your server is overloaded and slow.
Most resellers include Plesk or Cpanel that includes lots of pre-loaded software for your customers to use. Hopefully they offer a demo test-drive so you can check things out.
Good Luck!
Know better? Leave your own answer in the comments!
That is all that shows up on the page when opened in a browser. Cutting off at the > in the if statement, which made me assume it is closing my PHP statement. What am I doing wrong here?
By index I am assuming you mean the table data.
It is done in PHPMyAdmin. This is the SQL code used to create the DB and table.
CREATE DATABASE testdb;
CREATE TABLE `symbols` (
`id` int(11) NOT NULL auto_increment,
`country` varchar(255) NOT NULL default ”,
`animal` varchar(255) NOT NULL default ”,
PRIMARY KEY (`id`)
) TYPE=MyISAM;
INSERT INTO `symbols` VALUES (1, ‘America’, ‘eagle’);
INSERT INTO `symbols` VALUES (2, ‘China’, ‘dragon’);
INSERT INTO `symbols` VALUES (3, ‘England’, ‘lion’);
INSERT INTO `symbols` VALUES (4, ‘India’, ‘tiger’);
INSERT INTO `symbols` VALUES (5, ‘Australia’, ‘kangaroo’);
INSERT INTO `symbols` VALUES (6, ‘Norway’, ‘elk’);
a table with 3 columns and 6 data entries.
I did try what you said, and changed it to:
” if (0 < mysql_num_rows($ result)) "
and got a slightly different, but equally confusing result:
".$ row[0].""; echo "".$ row[1].""; echo "".$ row[2].""; } } // free result set memory mysqli_free_result($ result); // close connection mysqli_close($ connection); ?>
Best answer:
Answer by voshii Hi, noBull
please put the main index as well to investigate the issue
it is just an output
also yourweb-serverr may not beconfiguredd well
thank you
Know better? Leave your own answer in the comments!
Question by 24JJ24: PhP – MySQL email validation issue?
Hi,
I am trying to get some code straight. I know this is a complete and utter mess, my apologies (newbie coder). The aim of the script is that if the email matches a regex expression (previously defined), then it checks the database to see if the email the user has entered is already there. If it is, it prints back a message telling the user to enter a new one.
The database field itself is unique, so technically there will be no other email that is the same, however for the sake of having to redirect the user back I’d like to just keep all the validation on one page.
However, when I enter an email that already exists in the database, it still lets me continue to the database page. Not sure why this is, can anyone help me out?
Would rather just keep it all validated in PhP incase someone has Javascript turned off.
Thanks again
Still not working :/ no idea what’s going on with this script, will try and re-write it differently perhaps.
Best answer:
Answer by Erato Why bother with the regex… Just do this
$ sql=”SELECT * FROM table_name WHERE customers_email_address=’”.$ _Post['Email1'].”‘ ”
if($ sql==null){
//No Email Exists
}
else{
//Email Exists
}
I would do the Regex validation in Javascript then only submit the form field when the script returns true otherwise clear the field and make it red or something. You could also use something like this for the validator.