Jump to content


Photo

How do I send data from 1 page to another?


  • Please log in to reply
71 replies to this topic

#1 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 02 September 2006 - 06:31 PM

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? ???
Schroedinger's Cat walks into a bar.
And doesn't.

#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 02 September 2006 - 07:24 PM

Several ways
POST
GET
SESSION
COOKIE

I recommend post, or maybe get, if post is unavailable
Tell me the problem, I will try tell you the solution

#3 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 03 September 2006 - 01:15 AM

How though? 1 word really doesn't tell me anything  :-\

I'm very new at PHP and I really don't know what I'm doing.
Schroedinger's Cat walks into a bar.
And doesn't.

#4 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 03 September 2006 - 01:31 AM

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

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

$_SESSION['var'] and $_COOKIE['var']
It just temporarily stored, try yahoo search about it.

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#5 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 03 September 2006 - 01:33 AM

Where do I put it? What do I do with it?
Schroedinger's Cat walks into a bar.
And doesn't.

#6 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 03 September 2006 - 01:38 AM

Hmm.. Is this what you are doing..
When a user clicked on an item, it will show the details from database ?

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#7 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 03 September 2006 - 01:39 AM

Yes, it takes them to another page with a table showing a bunch of data fetched from the database.
Schroedinger's Cat walks into a bar.
And doesn't.

#8 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 03 September 2006 - 01:42 AM

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/...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']
follow me on twitter @PHPsycho

#9 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 03 September 2006 - 01:44 AM

They don't enter anything in. It just sends the name of the item they click on. $itemName
Schroedinger's Cat walks into a bar.
And doesn't.

#10 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 03 September 2006 - 01:46 AM

Then you can make use of $_GET['var']
Let's say, you put this on the items.php
<?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'];
?>

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.

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#11 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 03 September 2006 - 01:50 AM

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.

<?
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>

Schroedinger's Cat walks into a bar.
And doesn't.

#12 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 03 September 2006 - 01:53 AM

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

You need to change itemName to your correct table.

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#13 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 03 September 2006 - 01:55 AM

Still didn't work  :-\
Schroedinger's Cat walks into a bar.
And doesn't.

#14 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 03 September 2006 - 01:57 AM

Try going to that page using URL, because I think you didn't set the session correctly.

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#15 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 03 September 2006 - 02:00 AM

Still not working
Schroedinger's Cat walks into a bar.
And doesn't.

#16 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 03 September 2006 - 02:08 AM

Check your query again, I think you do it wrongly.

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#17 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 03 September 2006 - 02:12 AM

I dunno what you mean ???
Schroedinger's Cat walks into a bar.
And doesn't.

#18 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 03 September 2006 - 02:31 AM

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
$result = mysql_query($SQL,$connection);

to
$result = mysql_query($SQL,$connection) or die("Error ". mysql_error(). " with query ". $SQL);

Legend has it that reading the manual never killed anyone.
My site

#19 Pi_Mastuh

Pi_Mastuh
  • Members
  • PipPipPip
  • Advanced Member
  • 233 posts
  • LocationMN

Posted 03 September 2006 - 02:17 PM

It says

Error with query SELECT * FROM myitemschibi WHERE itemName =''
Schroedinger's Cat walks into a bar.
And doesn't.

#20 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 03 September 2006 - 02:22 PM

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.
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users