Seitan Posted December 7, 2006 Share Posted December 7, 2006 Im pretty new at this thing so I don't know what I'm doing wrong, I'm trying to make the fields in my table show up on my page. I can't get them to show up tho.....what am I doing wrong?[code]<? #recipes.php// Check for a valid user ID, through GET or POST.if ( (isset($_GET['id'])) ) { // Accessed through view_users.php $id = $_GET['id'];} elseif ( (isset($_POST['id'])) ) { // Form has been submitted. $id = $_POST['id'];} else { // No valid ID, kill the script. include ('../php/header.php'); echo '<h1 id="mainhead">Page Error</h1> <p class="error">This page has been accessed in error.</p><p><br /><br /></p>'; include ('../php/footer.php'); exit();}require_once ('../Can't tell!!/mysql_connect.php'); $query = "SELECT * FROM Recipes WHERE 'Recipe Number' = '$id'"; $result = @mysql_query ($query); $page_title = "Our Vegan Kitchen " . $result['Recipe Name']; $header = 'Category'; include ('../php/header.php'); ?> <div align="center"> <? echo 'Recipe Name'; ?></p> <p align="right">Submitted by<br> <?echo $result['Submitted_by'];?></p> <p align="left"> Ingredients:</p> <? while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) { echo $row['Ingredient 1'] ;?><br><? } ?><P><? echo 'Directions'; ?></p> <p align="left"> </p></div> <? include ('../php/footer.php'); ?>[/code] Link to comment https://forums.phpfreaks.com/topic/29749-what-am-i-doing-wrong/ Share on other sites More sharing options...
papaface Posted December 7, 2006 Share Posted December 7, 2006 [code] include ('../php/footer.php'); exit();}[/code]You are telling php to stop processing. So it never reaches the html. Link to comment https://forums.phpfreaks.com/topic/29749-what-am-i-doing-wrong/#findComment-136575 Share on other sites More sharing options...
Seitan Posted December 7, 2006 Author Share Posted December 7, 2006 that only happens if you access the page the wrong way, hence the if statement at the top Link to comment https://forums.phpfreaks.com/topic/29749-what-am-i-doing-wrong/#findComment-136580 Share on other sites More sharing options...
papaface Posted December 7, 2006 Share Posted December 7, 2006 Ah yes. So what do you actually get on the page when you run this? Link to comment https://forums.phpfreaks.com/topic/29749-what-am-i-doing-wrong/#findComment-136582 Share on other sites More sharing options...
Seitan Posted December 7, 2006 Author Share Posted December 7, 2006 I get [center]Recipe Name[/center]Submitted bySubmitted_byIngredients:Directions Link to comment https://forums.phpfreaks.com/topic/29749-what-am-i-doing-wrong/#findComment-136583 Share on other sites More sharing options...
btherl Posted December 7, 2006 Share Posted December 7, 2006 As a first step, replace [code=php:0]$result = @mysql_query ($query);[/code] with [code=php:0]$result = mysql_query ($query) or die("Query failed: $query with error " . mysql_error());[/code]Then you can see if the query failed."@" means "suppress errors", which also means you don't know what's going wrong with your script. It's usually a bad idea, and should only be used with a good reason. Link to comment https://forums.phpfreaks.com/topic/29749-what-am-i-doing-wrong/#findComment-136586 Share on other sites More sharing options...
Seitan Posted December 7, 2006 Author Share Posted December 7, 2006 I put that line in and it worked fine, so the query definitely worked. Link to comment https://forums.phpfreaks.com/topic/29749-what-am-i-doing-wrong/#findComment-136588 Share on other sites More sharing options...
papaface Posted December 7, 2006 Share Posted December 7, 2006 You should really keep this part:[code]<div align="center"> <? echo 'Recipe Name'; ?></p> <p align="right">Submitted by<br> <?echo $result['Submitted_by'];?></p> <p align="left"> Ingredients:</p> <? while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) { echo $row['Ingredient 1'] ;?><br><? } ?><P><? echo 'Directions'; ?></p> <p align="left"> </p></div>[/code]in php and echo the HTML out. The way you have done it above is confusing.e.g.[code]echo "<div align="center"> <? echo 'Recipe Name'; ?></p> <p align="right">Submitted by<br> <?echo $result['Submitted_by'];?></p> <p align="left"> Ingredients:</p> <? while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) { echo $row['Ingredient 1'] ;?><br><? } ?><P><? echo 'Directions'; ?></p> <p align="left"> </p></div>";[/code]^^ not a real example as the above wont pharse. Link to comment https://forums.phpfreaks.com/topic/29749-what-am-i-doing-wrong/#findComment-136590 Share on other sites More sharing options...
btherl Posted December 7, 2006 Share Posted December 7, 2006 Can you post your database structure? How do you list the ingredients in the database?You can't access [code=php:0]$result['Submitted_by'][/code]. Instead you need to fetch the [code=php:0]$row[/code] as you do later on, and use [code=php:0]$row['Submitted_by'][/code] Link to comment https://forums.phpfreaks.com/topic/29749-what-am-i-doing-wrong/#findComment-136597 Share on other sites More sharing options...
Seitan Posted December 7, 2006 Author Share Posted December 7, 2006 Here is my new SQL statement, I tried picking every field individually[code]$query = "SELECT `Recipe Number`,`Recipe Name`,`Submitted By`,`Ingredient 1`,`Ingredient 2`,`Ingredient 3`,`Ingredient 4`,`Ingredient 5`,`Ingredient 6`,`Ingredient 7`,`Ingredient 8`,`Ingredient 9`,`Ingredient 10`,`Ingredient 11`,`Ingredient 12`,`Ingredient 13`,`Ingredient 14`,`Ingredient 15`,`Ingredient 16`,`Ingredient 17`,`Directions`,`Category`,`email`,`source_from` FROM `Recipes` WHERE `Recipe Number` = '$id'";[/code]and here is what I have for my output part now[code]<div align="center"><? echo 'Recipe Name'; ?></p> <p align="right">Submitted by<br> <?echo 'Submitted_by';?></p> <p align="left"> Ingredients:</p> <?while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) { echo $row['Ingredient []'] ;?><br><? } ?><P><? echo 'Directions'; ?> <p align="left"> </p></div>[/code] Link to comment https://forums.phpfreaks.com/topic/29749-what-am-i-doing-wrong/#findComment-136604 Share on other sites More sharing options...
corbin Posted December 7, 2006 Share Posted December 7, 2006 try replaceing the [] in row['Ingredient []'] with an actual number to see if it works. Link to comment https://forums.phpfreaks.com/topic/29749-what-am-i-doing-wrong/#findComment-136606 Share on other sites More sharing options...
Seitan Posted December 7, 2006 Author Share Posted December 7, 2006 yep that works, I replaced it with the number one, and I got the first ingredient, but I only get the first ingredient Link to comment https://forums.phpfreaks.com/topic/29749-what-am-i-doing-wrong/#findComment-136607 Share on other sites More sharing options...
corbin Posted December 7, 2006 Share Posted December 7, 2006 replace echo $row['Ingredient []'] ; with $i = 1;while($i <= 17) {echo $row['Ingredient {$i}'];$i++;} Link to comment https://forums.phpfreaks.com/topic/29749-what-am-i-doing-wrong/#findComment-136615 Share on other sites More sharing options...
Seitan Posted December 7, 2006 Author Share Posted December 7, 2006 it doesn't work...I don't get anything now Link to comment https://forums.phpfreaks.com/topic/29749-what-am-i-doing-wrong/#findComment-136621 Share on other sites More sharing options...
Seitan Posted December 7, 2006 Author Share Posted December 7, 2006 Actually I got it working, but you guys helped......I put the while statement at the beginning and then just put everything like [font=Verdana]$row['Submitted by'] or $row['Directions'][/font] So thank you for your help. Link to comment https://forums.phpfreaks.com/topic/29749-what-am-i-doing-wrong/#findComment-136625 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.