Jump to content


Photo

How do I send data from 1 page to another?


  • Please log in to reply
71 replies to this topic

#21 Pi_Mastuh

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

Posted 03 September 2006 - 02:35 PM

The entire first page (before the changes) is posted. The whole second page is:

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

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

#22 AndyB

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

Posted 03 September 2006 - 03:12 PM

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

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

$itemName = $_GET['itemName'];

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

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

#23 Pi_Mastuh

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

Posted 03 September 2006 - 03:17 PM

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

#24 AndyB

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

Posted 03 September 2006 - 03:37 PM

<form action=../reg/secure/itemdetails.php method=post>
<input type=hidden name=$itemName value=$itemName ID=$itemName>


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 value 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:

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

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

#25 Pi_Mastuh

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

Posted 03 September 2006 - 03:45 PM

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

#26 AndyB

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

Posted 03 September 2006 - 04:09 PM

That's pretty much what I was afraid of  ;D

I'd change the FORM code so that instead of sending the item name, it sent the itemid

<input type="hidden" name="itemID" value="$itemID">

Then I'd change the second page so it retrieved itemID and I'd use itemID in the query.
Legend has it that reading the manual never killed anyone.
My site

#27 Pi_Mastuh

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

Posted 03 September 2006 - 04:14 PM

Now it displays everything the name should be as the ID number.
Schroedinger's Cat walks into a bar.
And doesn't.

#28 AndyB

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

Posted 03 September 2006 - 04:25 PM

You have the advantage over me here, because I can't see the first page code.  The error you're seeing almost surely results from how ' and " are used in your code in the area around where the form is being output.  If you post a few relevant lines, we can fix the error you're seeing.
Legend has it that reading the manual never killed anyone.
My site

#29 Pi_Mastuh

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

Posted 03 September 2006 - 04:29 PM

This is the entire first page:

          
		  
		  <table width="484" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#CC3300">
  <tr>
          <td width="480" align="center" valign="top"> <table width="500" border="0" cellspacing="0" cellpadding="0">
              <tr>
                
          <td bgcolor="#FF9900"> 
            <div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><strong>My 
              Items </strong></font></div></td>
              </tr>
              <tr>
                <td>    <table width=100% border="0" cellspacing="0">
        <tr> 
          <td><div align="center"></div></td>
        </tr>
        <tr>    
	 
<? 
				
				
$query_myItems = "SELECT * FROM myitemschibi WHERE userID = '$preuserID' and itemQty > '0'";

$result_myItems = mysql_query($query_myItems, $connection);

$query_data = mysql_fetch_array($result_myItems);

$numberItems = mysql_num_rows($result_myItems);








$i = 0;



if ($numberItems < 1) 

{

	print "<td><CENTER><P>You have no items.</CENTER>";

}

else 

{

	$rowcount = 0;

	while ($numberItems > $i) 

	{

		if ($rowcount == 3) 

		{ 

			echo "</tr>\n<tr>"; 

			$rowcount = 0; 

		}

	

		//$monopetImage1 = mysql_result($result2,$i,"monopetImage1");

	

		$itemName = mysql_result($result_myItems,$i,"itemName");
		//$itemDesc = mysql_result($result_myItems,$i,"itemDesc");
		$itemQty = mysql_result($result_myItems,$i,"itemQty");
	    $petPointsValue = mysql_result($result_myItems,$i,"petPointsValue");
		//$itemSpecial1 = mysql_result($result_myItems,$i, "itemSpecial1");
		//$itemSpecial2 = mysql_result($result_myItems,$i, "itemSpecial2");

		//$isequippable = mysql_result($result_myItems,$i, "isequippable");

		//$itemNumUses = mysql_result($result_myItems,$i, "itemNumUses");

		//$itemAttackValue = mysql_result($result_myItems,$i, "itemAttackValue");

		$itemID = mysql_result($result_myItems,$i, "itemID");

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

		$spacedname = str_replace(" ", "%20", $itemName);





		print '<td width=150 height=150>

				<center><font face=Arial, Helvetica, sans-serif size=2>';

		
// only display image if image exists (no broken images)

		if(file_exists('../images/items/'.$image.'.jpg'))

		{

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

		} else {

			echo '<br><br><b>No Image<br>Available<br></b>';

		}



		print"<br>


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

<input type=hidden name='itemID' value=$itemID>

<input type=image src=../images/details.jpg></FORM><br>



				";

				

		if($isequippable == '1')

		{	

			echo '<br><i><B>Equippable</b>';

			if($itemAttackValue > 0)

			{

				echo '<br>'.$itemAttackValue.' Attack Power';

			} else {

				echo '<br>'.abs($itemAttackValue).' Healing Power';

			}

			echo '<br>'.ucwords($itemNumUses).' Uses Remaining';

		}

				

		echo '</font></td>

';



		$i++;

		$rowcount++;

	}

}







///////
?>
      </tr>
            </table> </tr>
            </table>
            <div align="center"></div></td>
  </tr>
      </table> 

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

#30 AndyB

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

Posted 03 September 2006 - 05:58 PM

OK, there's a hidden input field that contains the value of itemID so change the second page to retrieve it as I suggested.

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

Give it try and report back on the outcome.
Legend has it that reading the manual never killed anyone.
My site

#31 Pi_Mastuh

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

Posted 03 September 2006 - 09:19 PM

Ok. It worked I guess but theres another problem.

Now It's not fetching the info again. Wen I look at the URL of the picture it says http://www.net-petz....ages/items/.jpg Here's how i have it coded:

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

Here's some other snippets of code that relate:

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

$spacedname = str_replace(" ", "%20", $itemName);

Which I have under

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

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

#32 AndyB

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

Posted 03 September 2006 - 10:58 PM

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

Try

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

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

#33 Pi_Mastuh

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

Posted 03 September 2006 - 11:00 PM

Nope  :-\. I think the problem is that none of the data is reaching the page for some reason.
Schroedinger's Cat walks into a bar.
And doesn't.

#34 AndyB

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

Posted 04 September 2006 - 12:43 PM

On your first page, you have this code:

<form action=../reg/secure/itemdetails.php method=post>
<input type=hidden name='itemID' value=$itemID>

Take a look at the generated html code and post here exactly what you see when you view the html source code.

That form will send the value of itemID to the itemdetails.php page where this line retrieves it.

$itemID = $_POST['itemID']; // retrieve itemID from form data

I think the problem is that none of the data is reaching the page for some reason.

Can you provide a more explicit description of the problem than that. Why do you think so? What happens, doesn't happen, etc.

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

#35 Pi_Mastuh

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

Posted 04 September 2006 - 02:20 PM

All the HTML code is in the page I posted before, except the actual htm page which is only

              <? include ("secure/config.php");
include ("secure/itemdetails.php");

?>

I think it's not reaching it because it's simply a blank table, and again the image is showing up as /items/.jpg. If the data were reaching it the name would show up and the imge would show up as $itemname.jpg.
Schroedinger's Cat walks into a bar.
And doesn't.

#36 AndyB

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

Posted 04 September 2006 - 02:48 PM

Sorry, let me explain. I/we don't want to see the code from the first page, I/we want to see what the browser generates based on that code (view source of the generated page). Then it will be obvious exactly what values have been placed in the form code, e.g. it will say name="itemID" value="12" or something like that.  If the value is blank then the problems in the first page.  If the value is a good one, then the reason why the second page doesn't work will lie in the code for the second page (and I think there's no problem there). 

The second page snippet you just posted clearly shows that whatever value should be there for the image name isn't there so I'm thinking there's a problem with your first page and how it generates the form.  If not, we can work on fixing whatever isn't happening on the second page.
Legend has it that reading the manual never killed anyone.
My site

#37 Pi_Mastuh

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

Posted 04 September 2006 - 03:47 PM

it's not letting me post it  >:(
Schroedinger's Cat walks into a bar.
And doesn't.

#38 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 04 September 2006 - 03:48 PM

Paste your code over at pastebin.com, your code most probably has something in it which is tripping the IPS we have installed here.

#39 Pi_Mastuh

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

Posted 04 September 2006 - 03:54 PM

It just comes up with a page cannot be displayed.

If I give you the URL and an account to login to would you be able to look at it?
Schroedinger's Cat walks into a bar.
And doesn't.

#40 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 04 September 2006 - 04:02 PM

Just post the code over at pastebin.com and provide a link to the posted code. That way we can see your code. Or a better option would be to attach the file to your post (Reply button > Additional Options... link > clik browse button to attach a file to the post.)

You can probide a demo account yes, as that way we can see whats going on




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users