randydings Posted August 8, 2007 Share Posted August 8, 2007 Below is the php script I have for a one of my pages on my website. http://www.greekcommonsense.com/category.php?table=products&title=Alpha%20Delta%20Chi The link above is the typical URL for this page. What I would like to do is figure out how to reference the $page_title to reference another table called organization and pull the oid from it. I entered the code below all the question marks everywhere I could possibly think of and I can get a resolution. Is there something wrong with the syntax? <?php include_once "sessioninfo.php"; $table = $_GET['table']; //"f_shirts"; $page_title = $_GET['title']; //For the page above it would be Alpha Delta Chi //$link = mysql_connect('XXXXXX', 'XXXX','XXXXX') $link = mysql_connect('XXXXXXXXXX', 'XXXXXXX','XXXXXXXXXXX') or die('Could not connect: ' . mysql_error()); //mysql_select_db('gcs') or die('Could not select database'); mysql_select_db('XXXXXXXXX') or die('Could not select database'); // Performing SQL query if (substr($_GET['table'],0,2) == "d_") { $sql = "SELECT * FROM ".$table." as i, drinkware as d WHERE d.id = i.id"; $imgdir = "images/drinkware/"; $type = "Drinkware"; } else { $sql = "SELECT * FROM ".$table." as i, products as p WHERE p.id = i.id"; $imgdir = "images/apparel/thumbs/"; $type = "Apparel"; } //echo $sql; $result = mysql_query($sql) or die('Query failed: ' . mysql_error()); ????????????????????????????????????????????????????????????????????????????????????????????????? $sql2 = "SELECT * FROM organization WHERE name =" . $page_title ; $result2 = mysql_query($sql2) or die('Query failed: ' . mysql_error()); $data = mysql_fetch_assoc($result2); $oid = $data['oid']; ?????????????????????????????????????????????????????????????????????????????????????????????????? I've even tried $oid = "Select oid From organization Where name = $page_title ; But is won't echo the $oid I hope someone can help Quote Link to comment https://forums.phpfreaks.com/topic/63943-should-be-a-quick-fix/ Share on other sites More sharing options...
nuttycoder Posted August 8, 2007 Share Posted August 8, 2007 try this $oid = "Select oid From organization Where name = '{$_GET['page_title']}' "; Quote Link to comment https://forums.phpfreaks.com/topic/63943-should-be-a-quick-fix/#findComment-318768 Share on other sites More sharing options...
cooldude832 Posted August 8, 2007 Share Posted August 8, 2007 that will work, however you run into a mysql injection issue that might cause you issues smarter idea is to make a list of safe words for it and say if its in the array it equals this else say error page title or something Quote Link to comment https://forums.phpfreaks.com/topic/63943-should-be-a-quick-fix/#findComment-318772 Share on other sites More sharing options...
randydings Posted August 8, 2007 Author Share Posted August 8, 2007 In my code right after $result = mysql_query($sql) or die('Query failed: ' . mysql_error()); from my original post I entered both the following: $sql2 = "SELECT * FROM organization WHERE name = '{$GET['page_title']}' "; $result2 = mysql_query($sql2) or die('Query failed: ' . mysql_error()); $data = mysql_fetch_assoc($result2); $oid = $data['oid']; and $oid = "SELECT oid FROM organization WHERE name = '{$_GET['page_title']}' "; My goal is to make the following line of code be an active link.// <//a href=//"http://www.greekcommonsense.com/organization.php?oid=<?php echo $oid; ?>"><?php echo $page_title; ?></a></div> PS. I add a few // because it won't show what I wanted to type. But this is how the link shows up from 4 lines of code added, with the following Query Failed http://www.greekcommonsense.com/organization.php?oid= Query failed: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 And this is how the link shows up from just the one line of code, with the following query Failed http://www.greekcommonsense.com/organization.php?oid=SELECT%20oid%20FROM%20organization%20WHERE%20name%20=%20'' Query failed: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT oid FROM organization WHERE name = \'\'' at line 1 Maybe I just didn't understand the previous instruction. Quote Link to comment https://forums.phpfreaks.com/topic/63943-should-be-a-quick-fix/#findComment-318893 Share on other sites More sharing options...
randydings Posted August 9, 2007 Author Share Posted August 9, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/63943-should-be-a-quick-fix/#findComment-319040 Share on other sites More sharing options...
teng84 Posted August 9, 2007 Share Posted August 9, 2007 we dont know where to start looking by that post please post the specific prob you have Quote Link to comment https://forums.phpfreaks.com/topic/63943-should-be-a-quick-fix/#findComment-319044 Share on other sites More sharing options...
pranav_kavi Posted August 9, 2007 Share Posted August 9, 2007 try this, while($data = mysql_fetch_assoc($result2)) { $oid = $data['oid']; echo $oid; } Quote Link to comment https://forums.phpfreaks.com/topic/63943-should-be-a-quick-fix/#findComment-319133 Share on other sites More sharing options...
randydings Posted August 9, 2007 Author Share Posted August 9, 2007 When I put in the following code I get the message below when I load the page. <?php include_once "sessioninfo.php"; $table = $_GET['table']; //"f_shirts"; $page_title = $_GET['title']; //$link = mysql_connect('localhost', 'gcs','temp') $link = mysql_connect('XXXXXXXXXX', 'XXXXXXXX','XXXXXXXXXXX') or die('Could not connect: ' . mysql_error()); //mysql_select_db('gcs') or die('Could not select database'); mysql_select_db('XXXXXXX') or die('Could not select database'); // Performing SQL query if (substr($_GET['table'],0,2) == "d_") { $sql = "SELECT * FROM ".$table." as i, drinkware as d WHERE d.id = i.id"; $imgdir = "images/drinkware/"; $type = "Drinkware"; } else { $sql = "SELECT * FROM ".$table." as i, products as p WHERE p.id = i.id"; $imgdir = "images/apparel/thumbs/"; $type = "Apparel"; } //echo $sql; $result = mysql_query($sql) or die('Query failed: ' . mysql_error()); $sql2 = "SELECT * FROM organization WHERE name = '{$GET['page_title']}' "; $result2 = mysql_query($sql2) or die('Query failed: ' . mysql_error()); while($data = mysql_fetch_assoc($result2)) { $oid = $data['oid']; echo $oid; } include "page_header.php"; ?> The following is what I'm trying to do with all the code. <title>GCS - <?php echo $type." - ".$page_title; ?></title> /// This all works <link href="menu.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="page_content"> <?php include "header_menu.php"; if (mysql_num_rows($result) > { ?> <div id="content_products_extend"> <?php } else { ?> <div id="content_products"> <?php } // else - if (mysql_num_rows($result) > ?> <div id="p_title"><?php echo $page_title; ?></div> ///it echos the page title I'm trying to have the very last line look like the following line of code, which will be able to match an oid to the <a href="http://www.greekcommonsense.com/orgainzation.php?oid=<?php echo $oid; ?>"><?php echo $page_title; ?></a> The problem is the URL that is generated is http://www.greekcommonsense.com/orgainzation.php?oid= and it won't pull the oid. Thank you so much for taking time to look at this. I really appreciate having a community to come to for help answer problem. Quote Link to comment https://forums.phpfreaks.com/topic/63943-should-be-a-quick-fix/#findComment-319344 Share on other sites More sharing options...
randydings Posted August 10, 2007 Author Share Posted August 10, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/63943-should-be-a-quick-fix/#findComment-320028 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.