GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Tech Why is this Kicking out an Error? (https://gfy.com/showthread.php?t=1348817)

Publisher Bucks 10-02-2021 08:52 AM

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? :Oh crap

Publisher Bucks 10-02-2021 09:27 AM

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.

k33n 10-02-2021 12:57 PM

Most likely your query is failing. Test it in phpmyadmin or in mysql server and see if you get results.

k0nr4d 10-02-2021 01:05 PM

That error indicates your query is wrong.

I don't want to know what you are cooking that has cat or dog as ingredient.

Publisher Bucks 10-02-2021 01:08 PM

Thanks.

I'll redo it and try again.

k0nr4d - Korean food :1orglaugh

Colmike9 10-02-2021 01:34 PM

Quote:

Originally Posted by Publisher Bucks (Post 22920234)
Thanks.

I'll redo it and try again.

k0nr4d - Korean food :1orglaugh

Ah, that makes sense now

Publisher Bucks 10-02-2021 02:35 PM

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.

plsureking 10-02-2021 03:55 PM

hmm can i auto reply to this guy with the stackoverflow search results?

:1orglaugh

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

:2 cents:

#

k33n 10-02-2021 11:02 PM

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';");

fuzebox 10-03-2021 11:02 AM

Quote:

Originally Posted by plsureking (Post 22920302)
hmm can i auto reply to this guy with the stackoverflow search results?

:1orglaugh

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? :helpme

plsureking 10-03-2021 02:05 PM

Quote:

Originally Posted by fuzebox (Post 22920556)
Can GFY admins merge all his beginner php questions into one thread? :helpme

i thought there used to be a nube forum? i lurked at cozyfrog a lot in my nube days lol

#

Colmike9 10-03-2021 02:18 PM

Quote:

Originally Posted by plsureking (Post 22920608)
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.

Publisher Bucks 10-04-2021 01:20 AM

Quote:

Originally Posted by k33n (Post 22920411)
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.

zerovic 10-08-2021 12:23 AM

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


All times are GMT -7. The time now is 07:55 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123