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 SQL (multiple) query error (https://gfy.com/showthread.php?t=1354956)

Publisher Bucks 05-20-2022 09:43 PM

SQL (multiple) query error
 
Any of the programmer types on here able to tell me why this is kicking out the following error?

Quote:

[20-May-2022 23:33:21 America/Chicago] PHP Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /blah/blah/domain.com/members/test/index.php on line 62
[20-May-2022 23:33:21 America/Chicago] PHP Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /blah/blah/domain.com/members/test/index.php on line 63
[20-May-2022 23:33:21 America/Chicago] PHP Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /blah/blah/domain.com/members/test/index.php on line 74
I've tried 2 different sets of php code and its still kicking errors out on me :Oh crap

Here was the original code:

Quote:

<?php

$con=mysqli_connect("localhost","db","pass","user" );

$result = mysqli_query($con,"SELECT * FROM Title WHERE Category REGEXP 'air' AND REGEXP 'fryer' ORDER BY Title ASC;");

echo "<table border='0'>

<tr>

</tr>";

while($row = mysqli_fetch_array($result))

{

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

echo "<tr>";

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

echo "</tr>";

}

echo "</table>";

mysqli_close($con);

?>
This is what I'm currently using (ditched regexp):

Quote:

<?php

$con=mysqli_connect("localhost","db","pass","user" );

$sql = "SELECT * FROM Recipe WHERE Title RLIKE 'fryer' AND RLIKE 'Air' ORDER BY Title ASC;";
$result = mysqli_query($con,$sql);
while($r = mysqli_fetch_array($result))
if (!$check1_res) {
printf("Error: %s\n", mysqli_error($con));
exit();
}
echo "<table border='0'>

<tr>

</tr>";

while($row = mysqli_fetch_array($result))

{

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

echo "<tr>";

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

echo "</tr>";

}

echo "</table>";

mysqli_close($con);

?>
Basically, I'm trying to get a set of recipes displayed where they contain 2 categories, in this instance 'air' and 'fryer' which should display any Air Fryer recipes, but it doesnt, any help would be greatly appreciated, this is my first time screwing with multipe queries to display results :helpme

Publisher Bucks 05-20-2022 09:46 PM

Oh, i should add, when using only 1 query, the code works perfectly :)

redwhiteandblue 05-21-2022 02:37 AM

Is this all of the code? What are lines 62, 63 and 74?

CurrentlySober 05-21-2022 07:12 AM

Quote:

Originally Posted by redwhiteandblue (Post 23002984)
Is this all of the code? What are lines 62, 63 and 74?

Easy, they are the lines that come between lines 61 and 64, plus the line between 73 & 75 respectively... come on... keep up :winkwink:

sarettah 05-21-2022 07:48 AM

Not sure how any of that code is running.

You mention 2 queries but you only have one query in there. It has 2 conditions, but it is one query.

Quote:

$sql = "SELECT * FROM Recipe WHERE Title RLIKE 'fryer' AND RLIKE 'Air' ORDER BY Title ASC;";
Needs to be:
$sql = "SELECT * FROM Recipe WHERE Title RLIKE 'fryer' AND Title RLIKE 'Air' ORDER BY Title ASC";

You have to have the field being interrogated listed in each condition.

I am not sure if that is your only problem.

Quote:

PHP Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /blah/blah/domain.com/members/test/index.php on line 62
This would indicate that you did not have a good connection. The first parameter on mysqli_query is the connection. The error message says that is null which would mean a bad connection.

The second set of code that was posted should not even run because of the errors in there. It shows 2 different wile loops but only one is closed. That doesn't matter though because the 2 different while loops make no sense. You are looping through the resuult and inside the loop you are looping through the results again. I don't think you want ot do that.

.

redwhiteandblue 05-21-2022 10:00 AM

Try replacing the line

Quote:

$con=mysqli_connect("localhost","db","pass","user" );
with

Quote:

$con=mysqli_connect("localhost","db","pass","user" ) or die("Error connecting to database");
and if you see the message "Error connecting to database"...
http://www.quickmeme.com/img/fb/fbdf...a8e23a6bd6.jpg

redwhiteandblue 05-21-2022 10:03 AM

BTW the parameters need to be in the order ("localhost", user, password, database_name)

But you said it works fine if you only have one query so it may be you had the correct code for connecting to the database. Try using the query Sarettah described, the ones you wrote don't make sense.

Publisher Bucks 05-21-2022 11:23 AM

i fixed it early this morning.

This issue was a missing Category as Sarettah mentioned above.

Quote:

SELECT * FROM Recipe WHERE Category RLIKE 'air' AND Category RLIKE 'fryer' ORDER BY Title ASC LIMIT 60
I appreciate all the responses :thumbsup

Must stop coding while drinking Jameson, that will solve most of the issues :1orglaugh


All times are GMT -7. The time now is 05:10 PM.

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