aramikgh Posted June 17, 2008 Share Posted June 17, 2008 can someone please let me know what im doing wrong? I thought this would be easy but i guess not... basically there are variables being posted to this page and I need it to look up in the database and get the catalog_ID for .... this is what i have so far... <? include 'config.php'; include 'opendb.php'; $DefCategory = $_POST['DefineCategory']; $DefCatalog = $_POST['DefineCatalog']; $DefPage = $_POST['DefinePage']; echo "Processing Page " .$DefPage ." in " .$DefCatalog ." under the " .$DefCategory ." category."; $result="SELECT Catagory_ID FROM a WHERE category_name = '{$_POST[DefineCategory]}' "; while($row = mysql_fetch_array($result)) { $CategoryIDfromDB = $row["Catagory_ID"]; echo $row['Catagory_ID']; } ?> Link to comment https://forums.phpfreaks.com/topic/110525-solved-mysql-select-data-where/ Share on other sites More sharing options...
trq Posted June 17, 2008 Share Posted June 17, 2008 You might try actually executing your query using mysql_query(). Link to comment https://forums.phpfreaks.com/topic/110525-solved-mysql-select-data-where/#findComment-567019 Share on other sites More sharing options...
aramikgh Posted June 17, 2008 Author Share Posted June 17, 2008 oops missed that...but for some reason i keep getting the same error... this is how my code looks now... <? include 'config.php'; include 'opendb.php'; $DefCategory = $_POST['DefineCategory']; $DefCatalog = $_POST['DefineCatalog']; $DefPage = $_POST['DefinePage']; echo "Processing Page " .$DefPage ." in " .$DefCatalog ." under the " .$DefCategory ." category."; $result = mysql_query("SELECT Catagory_ID FROM a WHERE category_name = $DefCategory"); while($row = mysql_fetch_array($result)) { $CategoryIDfromDB = $row["Catagory_ID"]; echo $row['Catagory_ID']; } ?> and this is the error i keep getting... Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/elemenu9/public_html/rexdist/processEntry.php on line 15 I thought that error for was when your not connected to a database but my config.php and opendb.php take care of that...right? Link to comment https://forums.phpfreaks.com/topic/110525-solved-mysql-select-data-where/#findComment-567022 Share on other sites More sharing options...
DarkWater Posted June 17, 2008 Share Posted June 17, 2008 No, you must have an error in your query. Add "or die(mysql_error());" to the end of it. Link to comment https://forums.phpfreaks.com/topic/110525-solved-mysql-select-data-where/#findComment-567024 Share on other sites More sharing options...
aramikgh Posted June 17, 2008 Author Share Posted June 17, 2008 cool...thanks. It points out the problem exactly now... I should have done that in the first place... Link to comment https://forums.phpfreaks.com/topic/110525-solved-mysql-select-data-where/#findComment-567026 Share on other sites More sharing options...
aramikgh Posted June 17, 2008 Author Share Posted June 17, 2008 ok another problem... i got it to move on without an error but i dont get a blank variable back...or just dont get anything back period... any advise? <? include 'config.php'; include 'opendb.php'; $DefCategory = $_POST['DefineCategory']; $DefCatalog = $_POST['DefineCatalog']; $DefPage = $_POST['DefinePage']; echo "Processing Page " .$DefPage ." in " .$DefCatalog ." under the " .$DefCategory ." category."; $result = mysql_query("SELECT Category_ID FROM a WHERE category_name = '$_POST[DefineCategory]' ") or die(mysql_error()); echo $result['Category_ID']; while($row = mysql_fetch_array($result)) { $CategoryIDfromDB = $row["Catagory_ID"]; echo "<br /> your Category ID is: " .$CategoryIDfromDB; } ?> anything is appreciated. Link to comment https://forums.phpfreaks.com/topic/110525-solved-mysql-select-data-where/#findComment-567030 Share on other sites More sharing options...
trq Posted June 17, 2008 Share Posted June 17, 2008 Your selecting Category_ID in your query then using $row["Catagory_ID"] to reference the field. Link to comment https://forums.phpfreaks.com/topic/110525-solved-mysql-select-data-where/#findComment-567032 Share on other sites More sharing options...
aramikgh Posted June 17, 2008 Author Share Posted June 17, 2008 wow thats two dumb mistake in a row...i think i need to call it a night.. thanks for all your help i love this site..just found it today Link to comment https://forums.phpfreaks.com/topic/110525-solved-mysql-select-data-where/#findComment-567039 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.