Pi_Mastuh Posted September 2, 2006 Share Posted September 2, 2006 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? ??? Quote Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/ Share on other sites More sharing options...
onlyican Posted September 2, 2006 Share Posted September 2, 2006 Several waysPOSTGETSESSIONCOOKIEI recommend post, or maybe get, if post is unavailable Quote Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/#findComment-84768 Share on other sites More sharing options...
Pi_Mastuh Posted September 3, 2006 Author Share Posted September 3, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/#findComment-84948 Share on other sites More sharing options...
hackerkts Posted September 3, 2006 Share Posted September 3, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/#findComment-84952 Share on other sites More sharing options...
Pi_Mastuh Posted September 3, 2006 Author Share Posted September 3, 2006 Where do I put it? What do I do with it? Quote Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/#findComment-84954 Share on other sites More sharing options...
hackerkts Posted September 3, 2006 Share Posted September 3, 2006 Hmm.. Is this what you are doing..When a user clicked on an item, it will show the details from database ? Quote Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/#findComment-84956 Share on other sites More sharing options...
Pi_Mastuh Posted September 3, 2006 Author Share Posted September 3, 2006 Yes, it takes them to another page with a table showing a bunch of data fetched from the database. Quote Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/#findComment-84957 Share on other sites More sharing options...
ToonMariner Posted September 3, 2006 Share Posted September 3, 2006 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 urlor $_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'] Quote Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/#findComment-84959 Share on other sites More sharing options...
Pi_Mastuh Posted September 3, 2006 Author Share Posted September 3, 2006 They don't enter anything in. It just sends the name of the item they click on. $itemName Quote Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/#findComment-84960 Share on other sites More sharing options...
hackerkts Posted September 3, 2006 Share Posted September 3, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/#findComment-84962 Share on other sites More sharing options...
Pi_Mastuh Posted September 3, 2006 Author Share Posted September 3, 2006 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(" ", " ", $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"> 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"> </font> </tr> </table></td> </tr> </table><br> </td> </table> </html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/#findComment-84965 Share on other sites More sharing options...
hackerkts Posted September 3, 2006 Share Posted September 3, 2006 [code]$SQL = "SELECT * FROM myitemschibi WHERE itemName ='$itemName'";[/code]You need to change itemName to your correct table. Quote Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/#findComment-84967 Share on other sites More sharing options...
Pi_Mastuh Posted September 3, 2006 Author Share Posted September 3, 2006 Still didn't work :-\ Quote Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/#findComment-84968 Share on other sites More sharing options...
hackerkts Posted September 3, 2006 Share Posted September 3, 2006 Try going to that page using URL, because I think you didn't set the session correctly. Quote Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/#findComment-84969 Share on other sites More sharing options...
Pi_Mastuh Posted September 3, 2006 Author Share Posted September 3, 2006 Still not working Quote Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/#findComment-84971 Share on other sites More sharing options...
hackerkts Posted September 3, 2006 Share Posted September 3, 2006 Check your query again, I think you do it wrongly. Quote Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/#findComment-84972 Share on other sites More sharing options...
Pi_Mastuh Posted September 3, 2006 Author Share Posted September 3, 2006 I dunno what you mean ??? Quote Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/#findComment-84974 Share on other sites More sharing options...
AndyB Posted September 3, 2006 Share Posted September 3, 2006 What is going on with your variable $itemName.First, it's mis-declared as a session variableThen it's declared as passed in the $_GET arrayAnd 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] Quote Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/#findComment-84976 Share on other sites More sharing options...
Pi_Mastuh Posted September 3, 2006 Author Share Posted September 3, 2006 It saysError with query SELECT * FROM myitemschibi WHERE itemName ='' Quote Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/#findComment-85147 Share on other sites More sharing options...
AndyB Posted September 3, 2006 Share Posted September 3, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/#findComment-85148 Share on other sites More sharing options...
Pi_Mastuh Posted September 3, 2006 Author Share Posted September 3, 2006 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(" ", " ", $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"> 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"> </font> </tr> </table></td> </tr> </table><br> </td> </table> </html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/#findComment-85151 Share on other sites More sharing options...
AndyB Posted September 3, 2006 Share Posted September 3, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/#findComment-85174 Share on other sites More sharing options...
Pi_Mastuh Posted September 3, 2006 Author Share Posted September 3, 2006 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 Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/#findComment-85177 Share on other sites More sharing options...
AndyB Posted September 3, 2006 Share Posted September 3, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/#findComment-85182 Share on other sites More sharing options...
Pi_Mastuh Posted September 3, 2006 Author Share Posted September 3, 2006 ok, now it sends it but only as the first word. I'm using $image = str_replace(" ", "", $itemName); $spacedname = str_replace(" ", " ", $itemName);because most of the items have spaces in their names. It's not working though. Quote Link to comment https://forums.phpfreaks.com/topic/19493-how-do-i-send-data-from-1-page-to-another/#findComment-85189 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.