?
Solved

PHP MYSQL CONNECTION AND SENDING VARIABLES TO CREATE A DETAIL PAGE

Posted on 2004-09-28
21
Medium Priority
?
443 Views
Last Modified: 2010-04-25
my problem is that i need to create a master detail page using a tool that i picked up from www.dengjie.com that makes it possible to create a master detail page set in PHP.
my database schema is
ID: autonum
description: string
location: string
size: string
price: integer
code :string
comments string
thumbnail:string
alterpic :string

Masterpage = results cuprite
detailpage = infopage

the masterpage calls for all entries with the same name and when i click on a thumbnail of the product it must take me to the detail page.

code-results cuprite
-------------------------
<?php require_once('Connections/mysql.php'); ?> <?php

$colname_Recordset1 = "1";
$HTTP_Recordset1 = "cuprite";
if (isset($HTTP_SESSION_VARS['cuprite'])) {
  $HTTP_Recordset1 = (get_magic_quotes_gpc()) ? $HTTP_SESSION_VARS['cuprite'] : addslashes($HTTP_SESSION_VARS['cuprite']);
}
mysql_select_db($database_mysql, $mysql);
$query_Recordset1 = sprintf("SELECT * FROM cuprite WHERE Name = '%s' ORDER BY ID ASC", $HTTP_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $mysql) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

?>
<title>results for cuprite</title>
<body bgcolor="#f3eeab"><div align="center">
  <table width="75%" border="1">
   
    <tr>
      <td><div align="center"><font color="#990000" face="Arial, Helvetica, sans-serif"><strong><?php echo $row_Recordset1['Name']; ?></strong></font></div></td>
    </tr>
  </table>
  <table border="1" align="center" cellpadding="5" cellspacing="5">
    <tr>
      <td><div align="center">
          <?php
  do { // horizontal looper
?>

          <a href="infopage.php?id=<?php echo $row_Recordset1['CODE']; ?>"><img src="<?php echo $row_Recordset1['thumbnail']; ?>" width="100" border="0"></a>
          <?php
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    if (!isset($nested_Recordset1)) {
      $nested_Recordset1= 1;
    }
    if (isset($row_Recordset1) && is_array($row_Recordset1) && $nested_Recordset1++%4==0) {
      echo "<br>";
    }
  } while ($row_Recordset1); //end horizontal looper
?>
        </div></td>
    </tr>
  </table>
  <p>&nbsp;</p>
</div>
<?php
mysql_free_result($Recordset1);
?>


code- Infopage
----------------------
<?php require_once('Connections/mysql.php'); ?>
<?php

$colname_Recordset1 = "1";
if (isset($HTTP_SESSION_VARS['ID'])) {
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? $HTTP_SESSION_VARS['ID'] : addslashes($HTTP_SESSION_VARS['ID']);
}
mysql_select_db($database_mysql, $mysql);
$query_Recordset1 = sprintf("SELECT * FROM cuprite WHERE ID = %s", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $mysql) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);


?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>

<body onLoad="MM_preloadImages('Buttons/Buy%20me_ON.png','Buttons/buy%20me_on.gif')">
<table width="75%" height="567" border="1">
  <tr>
    <td height="39" colspan="3"><div align="center"><?php echo $row_Recordset1['Name']; ?></div></td>
  </tr>
  <tr>
    <td width="51%" rowspan="6"><div align="center"><img src="<?php echo $row_Recordset1['alterpic1']; ?>"></div></td>
    <td width="15%" height="33">
<div align="center">Description</div></td>
    <td width="34%"><?php echo $row_Recordset1['DESCRIPTION']; ?></td>
  </tr>
  <tr>
    <td height="32">
<div align="center">Location</div></td>
    <td height="32"><?php echo $row_Recordset1['LOCALITY']; ?></td>
  </tr>
  <tr>
    <td height="31">
<div align="center">Size</div></td>
    <td height="31"><?php echo $row_Recordset1['SIZE']; ?></td>
  </tr>
  <tr>
    <td height="30">
<div align="center">Price</div></td>
    <td height="30"><?php echo $row_Recordset1['PRICE']; ?></td>
  </tr>
  <tr>
    <td height="37">
<div align="center">Code</div></td>
    <td height="37"><?php echo $row_Recordset1['CODE']; ?></td>
  </tr>
  <tr>
    <td height="87" colspan="2">&nbsp;</td>
  </tr>
  <tr>
    <td height="122">
<div align="center"><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image1','','Buttons/buy%20me_on.gif',1)"><img name="Image1" border="0" src="Buttons/buy%20me.gif"></a></div></td>
    <td rowspan="2">
<div align="right">Comments:</div></td>
    <td rowspan="2"><?php echo $row_Recordset1['Comments']; ?></td>
  </tr>
  <tr>
    <td height="134">&nbsp;</td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

========================================
any assistance would be great
midian
0
Comment
Question by:MIDIAN6665
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 13
  • 8
21 Comments
 
LVL 10

Expert Comment

by:rockmansattic
ID: 12168573
So what is not working ? do you get errors? What is your question?

at first glance , it looks fine.

Rockman
0
 

Author Comment

by:MIDIAN6665
ID: 12168819
When i click on the thumbnail image that is drawn from the database it takes me to the detail page, But the master page is also supposed to send a variable (ID) to the detail page, but the detail page does not seem to pick it up, this variable is used in a recordset query to pick up all the data on the specific item that has the (ID) variable, I dont know what type of variable it is sending or how to pick it up, I thought it was a session variable but when i told the detail page to pick up a session variable called ID it does'nt and it displays the first record in the database, instead of the one with the matching ID, I need help to fix this up so that it displays the right record
midian
0
 
LVL 10

Expert Comment

by:rockmansattic
ID: 12169011
What is in your url when you click the image.?

I think it (your master page) may need to be changed from

       <a href="infopage.php?id=<?php echo $row_Recordset1['CODE']; ?>">
to
       <a href="infopage.php?id=<?php echo $row_Recordset1['ID']; ?>">

this is becasue your detail page is asking for the id and looking for it in the url, but the master page is sending the "CODE" whatever that is.

Rockman
0
[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

 
LVL 10

Expert Comment

by:rockmansattic
ID: 12169050
No, I am wrong about the last sentence, it is not looking for it there, (although that is the most used method)
Ill get back to you.
Rockman
0
 
LVL 10

Expert Comment

by:rockmansattic
ID: 12169116
OK , Ithink two different things are being mixed up here.  the first page is passing "code" in the url and the detail page is asking for a session['id'] which may not be set.

Try this to bypass this problem and let me know.

change
       <a href="infopage.php?id=<?php echo $row_Recordset1['CODE']; ?>">
to
       <a href="infopage.php?id=<?php echo $row_Recordset1['ID']; ?>">

And

change
$colname_Recordset1 = "1";
if (isset($HTTP_SESSION_VARS['ID'])) {
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? $HTTP_SESSION_VARS['ID'] : addslashes($HTTP_SESSION_VARS['ID']);
}
to
$colname_Recordset1 = "1";
if (isset($_GET['id'])) {
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? $$_GET['id'] : addslashes($_GET['id']);
}

Now when you click the image ont he master page, it should take you to the detail page and pass the id of the image in the url and should look like this

infopage.php?id=45

Rockman
0
 

Author Comment

by:MIDIAN6665
ID: 12169343
OKAY CHANGED EVERYTHING
WHEN I CLICK ON AN IMAGE THE URL IS http://mineral_matrix.com/HOG/infopage.php?ID=493

and now i get this error:
You have an error in your SQL syntax near '' at line 1

not very clear on where so im goin to have to look.
0
 

Author Comment

by:MIDIAN6665
ID: 12169351
"mineral-matix" not "mineral matrix"
0
 

Author Comment

by:MIDIAN6665
ID: 12169373
0
 
LVL 10

Expert Comment

by:rockmansattic
ID: 12169399
odd..

change this and see what happens

$query_Recordset1 = sprintf("SELECT * FROM cuprite WHERE ID = %s", $colname_Recordset1);
to
$query_Recordset1 = ("SELECT * FROM cuprite WHERE ID = $colname_Recordset1");

rockman
0
 
LVL 10

Expert Comment

by:rockmansattic
ID: 12169429
also, while using APACHE, it is case sensitive, so make sure all id and ID are not the same thing

0
 
LVL 10

Expert Comment

by:rockmansattic
ID: 12169450
This will look just like a previous post, but the IDs should be similar

change
       <a href="infopage.php?ID=<?php echo $row_Recordset1['CODE']; ?>">
to
       <a href="infopage.php?ID=<?php echo $row_Recordset1['ID']; ?>">

And

change
$colname_Recordset1 = "1";
if (isset($HTTP_SESSION_VARS['ID'])) {
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? $HTTP_SESSION_VARS['ID'] : addslashes($HTTP_SESSION_VARS['ID']);
}
to
$colname_Recordset1 = "1";
if (isset($_GET['ID'])) {
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? $$_GET['ID'] : addslashes($_GET['ID']);
}


Sorry just bad habit of typing in lowercase.

Rockman
0
 
LVL 10

Expert Comment

by:rockmansattic
ID: 12169491
I see my error

$colname_Recordset1 = "1";
if (isset($_GET['ID'])) {
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['ID'] : addslashes($_GET['ID']);
}


also change BACK this

$query_Recordset1 = ("SELECT * FROM cuprite WHERE ID = $colname_Recordset1");
to
$query_Recordset1 = sprintf("SELECT * FROM cuprite WHERE ID = %s", $colname_Recordset1);

Have I thoughouly confused you?



Also looks like you are changing from asp to php.
I had to do a couple of sites that way myself.  took awhile.


rockman

0
 

Author Comment

by:MIDIAN6665
ID: 12169505
in dreamweaver when i look at what the if (isset($_GET['id'])) {
is it shows that it is an entered value, if the master page is sending an ID in the URL should the detail page be looking for a url parameter?
I.E.
$colname_Recordset1 = "1";
if (isset($HTTP_GET_VARS['$_GET['id']'])) {
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['$_GET['id']'] : addslashes($HTTP_GET_VARS['$_GET['id']']);
}
0
 
LVL 10

Expert Comment

by:rockmansattic
ID: 12169556
yes, but make sure that you are useing ID and not id, which will keep it the same. sorry for that.
Also, I think you can often exchange $_GET.. and $HTTP_GET_VARS.. depending on your settings.
my last post, along with your last one, should fix it.

Rockman
0
 
LVL 10

Expert Comment

by:rockmansattic
ID: 12169576
<?php require_once('Connections/mysql.php'); ?>
<?php

$colname_Recordset1 = "1";
if (isset($HTTP_GET_VARS['$_GET['ID']'])) {
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['$_GET['ID']'] : addslashes($HTTP_GET_VARS['$_GET['ID']']);
}
mysql_select_db($database_mysql, $mysql);
$query_Recordset1 = sprintf("SELECT * FROM cuprite WHERE ID = %s", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $mysql) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);


?>

should work
0
 

Author Comment

by:MIDIAN6665
ID: 12169621
and this will be the masterpage code?

<a href="infopage.php?ID=<?php echo $row_Recordset1['ID']; ?>">
0
 
LVL 10

Expert Comment

by:rockmansattic
ID: 12169630
yep.
should do it
0
 

Author Comment

by:MIDIAN6665
ID: 12169651
Ok now when i click on the thumbnail i get this error for the detail page
Parse error: parse error, unexpected T_STRING, expecting ']' in /usr/www/users/mineral/HOG/infopage.php on line 5

if (isset($HTTP_GET_VARS['$_GET['ID']'])) {    <--line5
0
 
LVL 10

Accepted Solution

by:
rockmansattic earned 1000 total points
ID: 12169722
This may becasue you may be using PHP4.2*+

change once again

colname_Recordset1 = "1";
if (isset($_GET['ID'])) {
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? '$_GET['ID'] : addslashes($_GET['ID']);
}

Settings in your php.ini would tell you if you can use HTTP_GET VARS
that is mainly use for previous version of php, but some still work depending on your server and such. TMK

Rockman(fingers crossed)
0
 

Author Comment

by:MIDIAN6665
ID: 12169787
crossing them fingers worked a dream dude!!!!!!!!!
im going to add 50 points!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
thank you!!!!!!!!!!!!!!!!!!!!!!!!!
midian
0
 
LVL 10

Expert Comment

by:rockmansattic
ID: 12169820
Thanks
Just glad you (we) finally got it.
sorry if i confused you along the way.

This is a rather easy thing to accomplish, but starting with someone elses code makes it a little more difficult more me to 'see' what is going on sometimes.

Rockman
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those who don't know, Adobe Dreamweaver is a popular commercial web editor that enables you to design, build and manage complex websites. The editor is a WYSIWYG (What You See Is What You Get) web editor, which means that you can create your web…
Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question