Jump to content

Recommended Posts

I'm have a page that lists all the items that the user has. That works and everything, now I'm trying to make it that when they click on the details button the new window pops up with the item name and other info from the database. I've got the window to pop up but it doesn't reconize the item. How do I make it send the item's name or ID number to the second page? ???
  • Replies 71
  • Created
  • Last Reply

Top Posters In This Topic

[b]$_POST['var'][/b]
Can be use when submitting a form.

[b]$_GET['var'][/b]
Can be use when submitting a form and URL.
Example: index.php?var=something

[b]$_SESSION['var'][/b] and [b]$_COOKIE['var'][/b]
It just temporarily stored, try yahoo search about it.
if you are using a form that people fill in and are passing that information between pages then the method of the form dictates which method you use to retrieve that data..

<form action"script.php" method="get".....

will send info via the url - which will look like http://www.here.com/script.php?foo=a&bar=b

<form action"script.php" method="post".....

will leave a clean ulr (no ?foo=a...)

in the script that is recieving these varaibles you can either use

$_GET['foo'] to get foo from the url

or $_POST['foo'] from the headers...

finally if you have the info you can simply put it in the a tag <a href="script.php?foo=a">

then get it using $_GET['foo']
Then you can make use of $_GET['var']
Let's say, you put this on the items.php
[code]<?php
$item = $_GET['item'];

// MySQL Connection
$host = "";
$username = "";
$password = "";
$db = "";
mysql_connect($host,$username,$password) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());

$query = "SELECT * FROM item WHERE name ='$item' LIMIT 1";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($result);
echo $row['name'] . "<br>";
echo $row['ect'];
?>[/code]

This is just an example, don't use it as it is not secure to use.
So it just like when people go to item.php?item=NAME then it will show them all the informations.
I tried that and it still isn't working. here's the whole code for the second page (that displays al the info), let me know if you need to see any of my other codes.

[code]<?
session_start();
$session=session_id( );

$_SESSION['itemName'] = "$itemName";
$itemName = $_GET['itemName'];

include ("secure/config3.php");

$SQL = "SELECT * FROM myitemschibi";

  $result = mysql_query($SQL,$connection);
$query_data = mysql_fetch_array($result);
$type = $query_data['food'];
$description = $query_data['description'];
$itemName = $query_data['itemName'];

$image = str_replace(" ", "", $itemName);

$spacedname = str_replace(" ", "&nbsp;", $itemName);

?>

<html>

<head>

<title><? print $itemName; ?></title>

</head>

<body>

<BR>
<table width="227" border="0" cellspacing="0" cellpadding="0" height="104" style="border-collapse: collapse" bordercolor="#111111">

  <tr>

    <td height="104" valign="top" width="227" bordercolorlight="#000080">

      <table width="200" border="1" cellspacing="0" cellpadding="0" bgcolor="#6699FF" bordercolor="#000066">

        <tr>

          <td align=center>

            <table width="200" border="0" cellspacing="0" cellpadding="0">

              <tr align=center bgcolor="blue">

                <td align=center bgcolor="blue">

                  <div align="center"><font face=Arial, Helvetica, sans-serif size=3 color="blue"><b>

                    <? print "$spacedname"; ?>

                    </b></font></div>

                </td>

              </tr>

              <tr bgcolor="#FFFFFF" align="center">

<img src="../images/items/<?echo$image;?>.jpg">



<br>

              </tr>

            </table>

          </td>

        </tr>

      </table><BR>

      <table width="205" border="1" cellspacing="0" cellpadding="0" bordercolor="#000099">
        <tr>

          <td><table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
            <tr bgcolor="#FFCCFF">
              <td height="20" colspan="2" bgcolor="#0000FF" bordercolor="navy"><div align="center">
              <font face="Arial, Helvetica, sans-serif" size="2" color="#FFFFFF"><b>Item Info:</b></font></div></td>
            </tr>
            <tr>
              <td width="99" height="10" bordercolor="navy"><font face="Arial, Helvetica, sans-serif" size="1">&nbsp;Type:</font></td>
              <td width="101" height="10" bordercolor="navy"><font face="Arial, Helvetica, sans-serif" size="1"><? print "$type"; ?>
</font></td>
            </tr>
            <tr>
              <td height="19" bordercolor="navy"><font face="Arial, Helvetica, sans-serif" size="1">Use:</font></td>
              <td height="19" bordercolor="navy"><font face="Arial, Helvetica, sans-serif" size="1">&nbsp; </font>                        </tr>
          </table></td>
        </tr>
      </table><br>

    </td>

   

</table>


   

</html>[/code]
What is going on with your variable $itemName.

First, it's mis-declared as a session variable
Then it's declared as passed in the $_GET array

And then it's retrieved from the database!!

Who knows what that's all supposed to mean.

As for the database query, if you added error display you would know if the query was working ..

change
[code]$result = mysql_query($SQL,$connection);[/code]

to
[code]$result = mysql_query($SQL,$connection) or die("Error ". mysql_error(). " with query ". $SQL);[/code]
If that's the error message, then $itemName is obviously absent from the query.

Please post the complete, current, version of what you are using for the script for your 'second' page.

Also, please post enough of the first(?) page so we can see HOW the value of itemName (or anything else) is being passed to the second page.
The entire first page (before the changes) is posted. The whole second page is:

[code]<?
session_start();
$session=session_id( );

$_SESSION['itemName'] = "$itemName";
$itemName = $_GET['itemName'];

include ("secure/config3.php");

$SQL = "SELECT * FROM myitemschibi WHERE itemName ='$itemName'";

$result = mysql_query($SQL,$connection) or die("Error ". mysql_error(). " with query ". $SQL);
$query_data = mysql_fetch_array($result);
$type = $query_data['food'];
$description = $query_data['description'];
$itemName = $query_data['itemName'];

$image = str_replace(" ", "", $itemName);

$spacedname = str_replace(" ", "&nbsp;", $itemName);

?>

<html>

<head>

<title><? print $itemName; ?></title>

</head>

<body>

<BR>
<table width="227" border="0" cellspacing="0" cellpadding="0" height="104" style="border-collapse: collapse" bordercolor="#111111">

  <tr>

    <td height="104" valign="top" width="227" bordercolorlight="#000080">

      <table width="200" border="1" cellspacing="0" cellpadding="0" bgcolor="#6699FF" bordercolor="#000066">

        <tr>

          <td align=center>

            <table width="200" border="0" cellspacing="0" cellpadding="0">

              <tr align=center bgcolor="blue">

                <td align=center bgcolor="blue">

                  <div align="center"><font face=Arial, Helvetica, sans-serif size=3 color="blue"><b>

                    <? print "$spacedname"; ?>

                    </b></font></div>

                </td>

              </tr>

              <tr bgcolor="#FFFFFF" align="center">

<img src="../images/items/<?echo$image;?>.jpg">



<br>

              </tr>

            </table>

          </td>

        </tr>

      </table><BR>

      <table width="205" border="1" cellspacing="0" cellpadding="0" bordercolor="#000099">
        <tr>

          <td><table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
            <tr bgcolor="#FFCCFF">
              <td height="20" colspan="2" bgcolor="#0000FF" bordercolor="navy"><div align="center">
              <font face="Arial, Helvetica, sans-serif" size="2" color="#FFFFFF"><b>Item Info:</b></font></div></td>
            </tr>
            <tr>
              <td width="99" height="10" bordercolor="navy"><font face="Arial, Helvetica, sans-serif" size="1">&nbsp;Type:</font></td>
              <td width="101" height="10" bordercolor="navy"><font face="Arial, Helvetica, sans-serif" size="1"><? print "$type"; ?>
</font></td>
            </tr>
            <tr>
              <td height="19" bordercolor="navy"><font face="Arial, Helvetica, sans-serif" size="1">Use:</font></td>
              <td height="19" bordercolor="navy"><font face="Arial, Helvetica, sans-serif" size="1">&nbsp; </font>                        </tr>
          </table></td>
        </tr>
      </table><br>

    </td>

   

</table>


   

</html>[/code]
I can't see the first page, and I don't know how/why you try to get itemName from two different places - a session and passed via the $_GET array

[b]$_SESSION['itemName'] = "$itemName";[/b]  (which should have been = $itemName without the quotes)

[b]$itemName = $_GET['itemName'];[/b]

So, my question is - how did you code so that $itemName gets in a session variable and/or code so that it gets into the $_GET array
oh sorry, they're both the second page. It shows every item in the database and under it is a button which links to the 2nd page.

<form action=../reg/secure/itemdetails.php method=post>

<input type=hidden name=$itemName value=$itemName ID=$itemName>

<input type=image src=../images/details.jpg></FORM>
[quote author=Pi_Mastuh link=topic=106645.msg427143#msg427143 date=1157296675]
<form action=../reg/secure/itemdetails.php method=post>
<input type=hidden name=$itemName value=$itemName ID=$itemName>
[/quote]

That's for each product, right?

Change name=$itemname to name='itemName' - you don't want the name of the variable passed to be different each time, you want the [b]value[/b] of the variable to be what's passed.  Then the way to retrieve that value - which comes from a form using the post method is going to be $_POST['itemname'].  So your second page out to look like this:

[code]<?php
$itemName = $_POST['itemName'];
include ("secure/config3.php");
$SQL = "SELECT * FROM myitemschibi WHERE itemName ='$itemName'";[/code]

Check the generated html for the first page to make sure the form really does have a value for the itemname field, and that should work.
ok, now it sends it but only as the first word. I'm using

$image = str_replace(" ", "", $itemName);

$spacedname = str_replace(" ", "&nbsp;", $itemName);

because most of the items have spaces in their names. It's not working though.
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.