Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 10-02-2021, 08:52 AM   #1
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,125
Why is this Kicking out an Error?

Quote:
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /blah/blah/domain.com/test/index.php on line 45

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /blah/blah/domain.com/test/index.php on line 48
I'm pretty sure I have the mysqli query setup correctly (was originally using REXEGP but swapped it out for LIKE as REGEXP wasn't working either):

Quote:
$result = mysqli_query($con,"SELECT * FROM Recipe WHERE Ingredients REGEXP 'cat|dog';");
Quote:
// query of fetching posts
$query = mysqli_query($con,"SELECT * FROM Recipe WHERE Title LIKE '%dog%' OR WHERE Title LIKE '%cat%' ORDER BY id LIMIT $page_limit OFFSET $page_offset");

// check database is not empty
if(mysqli_num_rows($query) > 0){
Any ideas?
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-02-2021, 09:27 AM   #2
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,125
Line 45 appears to have been a misplaced mysqli_close($con); which I just moved to the end of the page.

Line 48 is still showing an error though.
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-02-2021, 12:57 PM   #3
k33n
Confirmed User
 
Join Date: Feb 2009
Posts: 201
Most likely your query is failing. Test it in phpmyadmin or in mysql server and see if you get results.
k33n is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-02-2021, 01:05 PM   #4
k0nr4d
Confirmed User
 
k0nr4d's Avatar
 
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,228
That error indicates your query is wrong.

I don't want to know what you are cooking that has cat or dog as ingredient.
k0nr4d is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-02-2021, 01:08 PM   #5
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,125
Thanks.

I'll redo it and try again.

k0nr4d - Korean food
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-02-2021, 01:34 PM   #6
Colmike9
(>^_^)b
 
Colmike9's Avatar
 
Industry Role:
Join Date: Dec 2011
Posts: 7,223
Quote:
Originally Posted by Publisher Bucks View Post
Thanks.

I'll redo it and try again.

k0nr4d - Korean food
Ah, that makes sense now
__________________
Join the BEST cam affiliate program on the internet!
I've referred over $1.7mil in spending this past year, you should join in.
I make a lot more money in the medical field in a lab now, fuck you guys. Don't ask me to come back, but do join Chaturbate in my sig, it still makes bank without me touching shit for years..
Colmike9 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-02-2021, 02:35 PM   #7
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,125
Okay so I had a play around and now I'm getting even more errors.

The data that I want to display is showing what it needs to however, it isn't splitting the results across multiple pages of 10 like its supposed to.

These are the errors I'm getting, which I assumed are related to a misplaced mysqli_close statement somewhere (?) however, I don't see where that close statement can be causing an issue:

Quote:
Warning: mysqli_query() expects at least 2 parameters, 1 given in /blah/blah/domain.com/test/index.php on line 47

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /blah/blah/domain.com/test/index.php on line 48

Warning: mysqli_query() expects at least 2 parameters, 1 given in /blah/blah/domain.com/test/index.php on line 52

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /blah/blah/domain.com/test/index.php on line 53
This is the code I'm using for the pagination, it displays the navigation on the bottom of the page with no issue, but only has a single page showing, even if there are supposed to be 5 or 6:

Quote:
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
}
$no_of_records_per_page = 10;
$offset = ($pageno-1) * $no_of_records_per_page;

mysqli_connect("localhost","username","password"," database");
// Check connection
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}

$total_pages_sql = "SELECT COUNT(*) FROM Recipe";
$result = mysqli_query($total_pages_sql);
$total_rows = mysqli_fetch_array($result)[0];
$total_pages = ceil($total_rows / $no_of_records_per_page);

$sql = "SELECT * FROM Recipe LIMIT $offset, $no_of_records_per_page";
$res_data = mysqli_query($sql);
while($row = mysqli_fetch_array($res_data)){
//here goes the data
}
Below that I have this in the HTML in order to display the correct results, which it is doing:

Quote:
<?php

$con=mysqli_connect("localhost","databse","passwor d","username");
$result = mysqli_query($con,"SELECT * FROM Recipe WHERE Ingredients REGEXP 'salt';");

echo "<table border='0'>

<tr>

</tr>";

while($row = mysqli_fetch_array($result))

{

$link = "/test/recipes.php?id=".$row['RecipeID'];

echo "<tr>";

echo "<a href = ". $link . ">" . $row['Title'] . "</a><br>";

echo "</tr>";

}

echo "</table>";
?>
Any ideas what I should be looking for error wise? From what I'm seeing online it appears to be something relating to either the mysqli close statement or something to do with global $con, which I know nothing about

Initially I thought it may have been an issue with the variable naming but that does not seem to be the case.

I'm at a loss, any pointers in the right direction would be appreciated.
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-02-2021, 03:55 PM   #8
plsureking
bored
 
plsureking's Avatar
 
Industry Role:
Join Date: Aug 2003
Location: Metaverse
Posts: 4,675
hmm can i auto reply to this guy with the stackoverflow search results?



use your brain a little bit. we all spent lots of sleepless nights figuring shit out.



#
__________________
#
plsureking is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-02-2021, 11:02 PM   #9
k33n
Confirmed User
 
Join Date: Feb 2009
Posts: 201
Quote:
Warning: mysqli_query() expects at least 2 parameters, 1 given
It is saying right there, solve this and the mysqli_fetch_array one will go away too, assuming that the query will not fail. Here is a hint to put you on the right track:

You are using mysqli_query correctly in other part of your script.

Quote:
$con=mysqli_connect("localhost","databse","passwor d","username");
$result = mysqli_query($con,"SELECT * FROM Recipe WHERE Ingredients REGEXP 'salt';");
k33n is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-03-2021, 11:02 AM   #10
fuzebox
making it rain
 
fuzebox's Avatar
 
Industry Role:
Join Date: Oct 2003
Location: seattle
Posts: 22,026
Quote:
Originally Posted by plsureking View Post
hmm can i auto reply to this guy with the stackoverflow search results?



use your brain a little bit. we all spent lots of sleepless nights figuring shit out.
Can GFY admins merge all his beginner php questions into one thread?
fuzebox is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-03-2021, 02:05 PM   #11
plsureking
bored
 
plsureking's Avatar
 
Industry Role:
Join Date: Aug 2003
Location: Metaverse
Posts: 4,675
Quote:
Originally Posted by fuzebox View Post
Can GFY admins merge all his beginner php questions into one thread?
i thought there used to be a nube forum? i lurked at cozyfrog a lot in my nube days lol

#
__________________
#
plsureking is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-03-2021, 02:18 PM   #12
Colmike9
(>^_^)b
 
Colmike9's Avatar
 
Industry Role:
Join Date: Dec 2011
Posts: 7,223
Quote:
Originally Posted by plsureking View Post
i thought there used to be a nube forum? i lurked at cozyfrog a lot in my nube days lol

#
There's the Educational Series subforum on here, but I think those OPs are mostly people explaining things as a tutorial and less people asking questions.

My noob days were me riding a bus downtown to the library and checking out books for C64 BASIC then always coming home with a bunch of sesame chicken.
__________________
Join the BEST cam affiliate program on the internet!
I've referred over $1.7mil in spending this past year, you should join in.
I make a lot more money in the medical field in a lab now, fuck you guys. Don't ask me to come back, but do join Chaturbate in my sig, it still makes bank without me touching shit for years..
Colmike9 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-04-2021, 01:20 AM   #13
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,125
Quote:
Originally Posted by k33n View Post
It is saying right there, solve this and the mysqli_fetch_array one will go away too, assuming that the query will not fail. Here is a hint to put you on the right track:

You are using mysqli_query correctly in other part of your script.
Thanks, I'll play with that tomorrow, just got out of the ER (12 fucking hours) and headed to bed.
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 10-08-2021, 12:23 AM   #14
zerovic
Confirmed User
 
zerovic's Avatar
 
Industry Role:
Join Date: Apr 2010
Posts: 1,087
Hey,

Open up a new PHP file and do it like this

Quote:
$mysqli = new mysqli("localhost","username","password","database ");

if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}

$data = mysqli_query($mysqli, "SELECT * FROM Recipe WHERE Ingredients REGEXP 'salt';");
while($result = mysqli_fetch_array($data)) {
//here goes the data
}
Let me know if this works. The main difference is how you connect to your db.

I just tried this on one of my scripts and it works like charm.

Also, in my case, using

Quote:
LIKE '%salt%'
was faster then

Quote:
REGEXP 'salt';
Tried it on a POS script I wrote for a few bars and restaurants in my town and here's the result

Quote:
SELECT * FROM `orders` WHERE `ordered_item` REGEXP 'cola';
Showing rows 0 - 24 (4683 total, Query took 0.0010 seconds.)

SELECT * FROM `orders` WHERE `ordered_item` LIKE '%cola%'
Showing rows 0 - 24 (4683 total, Query took 0.0007 seconds.)
Cheers,
z
zerovic is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks

Tags
null, mysqli, line, mysqli_query$con, select, query, regexp, title, recipe, warning, expects, parameter, %cat%, %dog%, $query, fetching, cat|dog;;, ingredients, posts, database, ifmysqli_num_rows$query, empty, ideas, crap, check, limit



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.