Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/63943-should-be-a-quick-fix/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/63943-should-be-a-quick-fix/#findComment-318893
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/63943-should-be-a-quick-fix/#findComment-319344
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.