![]() |
![]() |
![]() |
||||
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. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
|
![]() Any programmers able to see what I'm fucking up?
This is for a personal project I'm working on. I should be able to open index.php to display a listing of 'recipes' in the database which will allow me to click through to viewmore.php where i have more information displayed on the page. PHP Code:
This is my viewmore.php page code... PHP Code:
Any help would be greatly appreciated. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
(>^_^)b
Industry Role:
Join Date: Dec 2011
Posts: 7,224
|
// change the user_name and password
$db = mysqli_connect("localhost", "dbuser", "dbpass"); // change the database_name mysqli_select_db("dbname",$db); Did you put in the right info?
__________________
![]() 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.. ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 | |
Confirmed User
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
|
Quote:
I do know my host just recently upgraded a bunch of php so I also have a ticket in with them to make sure they didn't fuck anything up (its Hostgator who I use for my personal stuff). |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
Industry Role:
Join Date: Mar 2007
Location: Phoenix, Arizona
Posts: 1,725
|
I don't think it is making the database connection in the viewmore.php or the index.php file.
I don't believe the $con has actually been defined for the db connection. Just my 2 cents. ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Confirmed User
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
Confirmed User
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,228
|
__________________
Mechanical Bunny Media Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
Confirmed User
Industry Role:
Join Date: Aug 2006
Location: Poland
Posts: 9,228
|
Nevermind, I just actually looked at your code.
You called your db connection $db but are called $con in your mysqli_query $con = mysqli_connect("localhost", "dbuser", "dbpass"); mysqli_select_db("dbname",$con); You also need to establish the db connection on the viewmore.php file
__________________
Mechanical Bunny Media Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,057
|
This is just wrong unless I am really missing something.
You select recipeid from the table but then you are trying to echo out variables before you have them. You are treating the href as if it is an include. while($row = mysqli_fetch_array($result)) { // Here you pull in the ID field. $id = $row['RecipeID']; echo "<tr>"; echo "<td>" . $row['RecipeID'] . "</td>"; //Everything is fine till here. // You attempt to build your href but it isnt going to work because // you attempt to echo out title when you don't have the title yet. echo "<td> <a href='viewmore.php?id=$id'>" . $row['Title'] . "</a> </td>"; // Then you attempt to echo out the other fields when, again, you don't have them yet. echo "<td>" . $row['Ingredients'] . "</td>"; echo "<td>" . $row['Method'] . "</td>"; echo "<td>" . $row['Keywords'] . "</td>"; echo "</tr>"; } echo "</table>"; .................................................. ...................... Try something like this instead: $result = mysqli_query($con,"SELECT RecipeID, Title FROM Recipes WHERE id = $id"); echo "<table width=100%> <tr> <th>ID</th> <th>Title</th> </tr>"; while($row = mysqli_fetch_array($result)) { $id = $row['RecipeID']; echo "<tr>"; echo "<td>" . $row['RecipeID'] . "</td>"; echo "<td> <a href='viewmore.php?id=$id'>" . $row['Title'] . "</a> </td>"; echo "</tr>"; } echo "</table>"; Then, in viewmore, as k0nr4d said, you need to establish a connection. Not sure I caught all of it but that is the way I see it, like I said, unless I missed something somewhere. . |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 |
Confirmed User
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
|
Appreciate the help guys, going to play around a little and see if I can put a working code together based on your feedback, thank you!
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 |
Industry Role:
Join Date: Aug 2006
Location: Little Vienna
Posts: 32,235
|
It seems i was too late on party :D Still, always check how your variables contain data/functions.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 | |
Confirmed User
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,123
|
Ive edited the code as suggested for both pages and now its throwing out a blank page with the 'ID' and 'Title' table but no data being inserted, i checked the error logs and its showing me this:
Quote:
index.php PHP Code:
PHP Code:
The url im using is: domain.com/index.php?id=X (where X is a valid RecipeID in the table) domain.com/viewmore.php?id=X (where X is a valid RecipeID in the table) I'm going to get a few hours sleep, but if ya'll happen to spot anything amiss it'd be appreciated. Thanks again for the help so far ![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#12 | |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,057
|
mysqli_select_db("dbname",$con);
Should be mysqli_select_db($con,"dbname"); PHP.net is your friend. https://www.php.net/manual/en/mysqli.select-db.php Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#13 | |
Monger Cash
Industry Role:
Join Date: Jul 2010
Posts: 2,773
|
Quote:
1. Your stated goal is to display a list of recipes on index.php with a link to the individual recipe info on viewmore.php. The problem is, your index.php script is expecting a recipe ID to be passed as a query string, ala index.php?id=123. 2. Your SELECT query on index.php only ever asks for 'ReceipID' from the db, but you're attempting to display other data. Not to mention, you're trying to get the ReceipID from the db while also telling the db what the RecipeID is. 3. Your output on index.php and viewmore.php are effectively the same, assuming the queries worked. 4. You're using <table> in 2021. At any rate, going by what your stated goal is, I think something like this is more in line with what you want: Code:
<?php /*** index.php ***/ // change hostname, username, password, and dbname $db = new mysqli( 'hostname', 'username', 'password', 'dbname'); if ($db->connect_errno) die("Connect failed: %s\n", $db->connect_error); $getRecipes = "SELECT ReceipID, Title FROM Recipes"; $response = $db->query($getRecipes); if ($response->num_rows) { echo "<table width=100%> <tr> <th>ID</th> <th>Title</th> </tr>"; $row = $db->get_results($response); foreach($row as $key => $value) { $id = $value->RecipeID; $title = $value->Title; echo "<tr>"; echo "<td>{$id}</td>"; // not sure why you want to display the recipe id, but okay. echo "<td> <a href=\"viewmore.php?id={$id}\">{$title}</a></td>"; echo "</tr>"; } echo "</table>"; } $db->close(); ?> Code:
<?php /*** viewmore.php ***/ // change hostname, username, password, and dbname $db = new mysqli( 'hostname', 'username', 'password', 'dbname'); if ($db->connect_errno) die("Connect failed: %s\n", $db->connect_error); $id = $_GET['id']; $getRecipe = "SELECT * FROM Recipes WHERE ReceipID = {$id}"; $response = $db->query($getRecipe); if ($response->num_rows) { echo "<table width=100%> <tr> <th>Title</th> <th>Ingredients</th> <th>Method</th> <th>Keywords</th> </tr>"; $row = $db->get_results($response); foreach($row as $key => $value) { echo "<tr>"; echo "<td>{$value->Title}</td>"; echo "<td>{$value->Ingredients}</td>"; echo "<td>{$value->Method}</td>"; echo "<td>{$value->Keywords}</td>"; echo "</tr>"; } echo "</table>"; } $db->close(); ?> |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#14 |
see you later, I'm gone
Industry Role:
Join Date: Oct 2002
Posts: 14,057
|
LOL, miss a lot of stuff when you move too fast.
. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#15 | |
Industry Role:
Join Date: Aug 2006
Location: Little Vienna
Posts: 32,235
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() ![]() |
|||||||
|
|||||||
Bookmarks |
Tags |
page, viewmore.php, data, sql, click, row, code, database, correct, information, displayed, link, viewmore.php?id=46, generate, programmers, web, dynamic, php, issues, displaying, fucking, index.php, display, listing, personal |