473,708 Members | 2,453 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do i transfer $_GET['id'] ?

69 New Member
i need to get the value of the id from 1 page called image.php a insert it in to the database from another page submitComment.p hp

this is my code....

image.php....

Expand|Select|Wrap|Line Numbers
  1. $photoId = mysql_escape_string($_GET['id']);                
  2. $q = "SELECT * FROM comments WHERE photoId = '" . $photoId . "' ORDER BY date DESC LIMIT 5";
submitComment.p hp....

Expand|Select|Wrap|Line Numbers
  1. $theMessage = addslashes(strip_tags($_POST['message'])); 
  2. $q = "INSERT INTO comments (photoId, date, content) VALUES ('" . $photoId . "', '" . $theDate . "', '" . $theMessage . "')";
  3. $result = $mysqli->query($q) or die ('error could not insert into comments' . mysql_error());
everything works fine except i get this error...

Undefined variable: photoId in C:\wamp\www\fot ostor\submitCom ment.php on line 39

and the photoId in the database displays 0, i cant merge the pages togetherso it recognises the image.php's $_GET['id']; so i was wondering if i could get the value of it and transfer it some how, please help
Aug 12 '09 #1
14 8853
dlite922
1,584 Recognized Expert Top Contributor
how are users getting to submitComment.p hp from image.php?

link, form button?

Then change it to add the photoID as a URL parameter. Either in the link or the forum action.

You can also use session, but not recommended for your problem here.




Dan
Aug 12 '09 #2
luke noob
69 New Member
sorry Its quite hard to explain but basically i need to get the page id value from one page and store it in to a varable which i can do. but then i need to somehow send that varible information to another page and from that page send it to my database.

on the submitComment.p hp there is a comment form that posts the comment and at the same time stores the information into the database, the problem is that it doesnt insert the photoId (the image.php $_GET['id']) because it dosent recognise it. so i was think or some how sending the id (image.php's $_GET['id']) to the submitComments page so it does.


but how can i send the variable? without form or button? thanx in advance, iv been googling for days
Aug 12 '09 #3
dlite922
1,584 Recognized Expert Top Contributor
post the entire code from both pages and I'll try to take a look at it for you.
Aug 12 '09 #4
luke noob
69 New Member
submitComment.p hp
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. require 'database.php';
  4. require 'functions.php';
  5.  
  6. $timestamp = time();
  7. $date_time_array = getdate($timestamp);
  8.  
  9. $hours = $date_time_array['hours'];
  10. $minutes = $date_time_array['minutes'];
  11. $seconds = $date_time_array['seconds'];
  12. $month = $date_time_array['mon'];
  13. $day = $date_time_array['mday'];
  14. $year = $date_time_array['year'];
  15. ?>
  16. <?php
  17.  
  18. $timestamp = mktime($hours + 8,$minutes,$seconds,$month,$day,$year);
  19. $theDate = strftime('%Y-%m-%d %H:%M:%S',$timestamp);
  20.  
  21. mysql_connect("localhost","root",""); 
  22.  
  23. mysql_select_db("myPhotos") or die("Unable to select database");
  24.  
  25. $theMessage = addslashes(strip_tags($_POST['message']));
  26.  
  27. $photoId = mysql_escape_string($_GET['id']);              
  28.  
  29. $q = "INSERT INTO shoutbox (photoId, date, content) VALUES ('" . $photoId . "', '" . $theDate . "', '" . $theMessage . "')";
  30. $result = $mysqli->query($q) or die ('error could not insert into shout box' . mysql_error());  
  31.  
  32. $theMessage = str_replace(":frown:","&nbsp;<img src='smilies/frown.gif'>", $theMessage); 
  33.  
  34. ?>
  35.         <div class="comment-unapproved">
  36.             <div class="date">
  37.                 <span class="day-month"><?php echo date('d M'); ?></span>
  38.                 <span class="year"><?php echo date('y'); ?></span>
  39.             </div>
  40.             <span class="content"><?php echo stripslashes($theMessage); ?></span>
  41.             <div class="clear"></div>
  42.         </div>



review_image.ph p

Expand|Select|Wrap|Line Numbers
  1. <body>  
  2.   <?php 
  3.     require 'functions.php';
  4.   ?>       
  5.  
  6.       <div id="container">
  7.            <div id="main">
  8.  
  9.     <img src="images/logos/logofold.jpg" width="64" height="126" class="logofold">        
  10.     <img src="images/logos/logo1.jpg" width="913" height="126" id="logo">
  11.      <div class="aerobuttonmenu">
  12.  
  13. <a href="#" class="aero"><span>About Us</span></a> 
  14. <a href="#" class="aero"><span>Services</span></a>
  15. <a href="contact.html" class="aero"><span>Contact</span></a> 
  16. <a href="index.php" class="aero"><span>Home</span></a> 
  17.  
  18. </div></div></div>
  19.  
  20.       <div id="container"> 
  21.       <img src="images/logos/footer1.jpg" width="100%" height="31" align="right" id="footer1">
  22.  
  23.          <p id="text"><font color="#486583">Photo Description</font></p>
  24.                           </div> </div>
  25.  
  26.        <div id="container">
  27.            <div id="main">
  28.  
  29. <?php getChosenPhoto($_GET['id']);  ?>
  30. <table align="center"><tr><td>  
  31. <div id="container">
  32.     <div id="comments">
  33. <?php
  34.  
  35. include("database.php");
  36.  
  37.    function datediff($d1, $d2)
  38.  {
  39.     $d1 = (is_string($d1) ? strtotime($d1) : $d1);
  40.     $d2 = (is_string($d2) ? strtotime($d2) : $d2);
  41.  
  42.     $diff_secs = abs($d1 - $d2);
  43.     $base_year = min(date("Y", $d1), date("Y", $d2));
  44.  
  45.     $diff = mktime(0, 0, $diff_secs, 1, 1, $base_year);
  46.     $diffArray = array(
  47.         "years" => date("Y", $diff) - $base_year,
  48.         "months_total" => (date("Y", $diff) - $base_year) * 12 + date("n", $diff) - 1,
  49.         "months" => date("n", $diff) - 1,
  50.         "days_total" => floor($diff_secs / (3600 * 24)),
  51.         "days" => date("j", $diff) - 1,
  52.         "hours_total" => floor($diff_secs / 3600),
  53.         "hours" => date("G", $diff),
  54.         "minutes_total" => floor($diff_secs / 60),
  55.         "minutes" => (int) date("i", $diff),
  56.         "seconds_total" => $diff_secs,
  57.         "seconds" => (int) date("s", $diff)
  58.     );
  59.     if($diffArray['days'] > 0){
  60.         if($diffArray['days'] == 1){
  61.             $days = '1 day';
  62.         }else{
  63.             $days = $diffArray['days'] . ' days';
  64.         }
  65.         return $days . ' and ' . $diffArray['hours'] . ' hours ago';
  66.     }else if($diffArray['hours'] > 0){
  67.         if($diffArray['hours'] == 1){
  68.             $hours = '1 hour';
  69.         }else{
  70.             $hours = $diffArray['hours'] . ' hours';
  71.         }
  72.         return $hours . ' and ' . $diffArray['minutes'] . ' minutes ago';
  73.     }else if($diffArray['minutes'] > 0){
  74.         if($diffArray['minutes'] == 1){
  75.             $minutes = '1 minute';
  76.         }else{
  77.             $minutes = $diffArray['minutes'] . ' minutes';
  78.         }
  79.         return $minutes . ' and ' . $diffArray['seconds'] . ' seconds ago';
  80.     }else{
  81.         return 'Less than a minute ago';
  82.     }
  83.  }  
  84.  
  85. $timestamp = time();
  86. $date_time_array = getdate($timestamp);
  87.  
  88. $hours = $date_time_array['hours'];
  89. $minutes = $date_time_array['minutes'];
  90. $seconds = $date_time_array['seconds'];
  91. $month = $date_time_array['mon'];
  92. $day = $date_time_array['mday'];
  93. $year = $date_time_array['year'];
  94.  
  95. $timestamp = mktime($hours + 8,$minutes,$seconds,$month,$day,$year);
  96. $theDate = strftime('%Y-%m-%d %H:%M:%S',$timestamp);
  97.  
  98. mysql_connect("localhost","root",""); 
  99.  
  100. mysql_select_db("myphotos") or die("Unable to select database"); 
  101.  
  102. $photoId = mysql_escape_string($_GET['id']);
  103.  
  104. $q = "SELECT * FROM shoutbox WHERE photoId = '" . $photoId . "' ORDER BY date DESC LIMIT 5";
  105.  
  106. $result = $mysqli->query($q);
  107. while($row = $result->fetch_array()) {
  108.     $date = strtotime($row['date']);
  109.     $dayMonth = date('d M', $date);
  110.     $year = date('y', $date);                     
  111.     $message = $row['content'];
  112.     $datediff = datediff($theDate, $date);
  113.  
  114. $message = str_replace(":frown:","&nbsp;<img src='smilies/frown.gif'>", $message);      
  115. ?>    
  116.  
  117.         <div class="comment">
  118.             <div class="date">
  119.                 <span class="day-month"><?php echo $dayMonth; ?></span>
  120.                 <span class="year"><?php echo $year; ?></span>
  121.             </div>
  122.             <span class="content"><?php echo stripslashes($message);?> <span class="time"><?php echo $datediff; ?></span></span>
  123.             <div class="clear"></div>
  124.         </div>
  125. <?php 
  126. }
  127.  
  128.  
  129. ?>
  130.     </div>
  131.     <div id="submission">
  132.         <form name="comment-submission">
  133.  
  134. <a title="Frown"><img border="0" src="smilies/frown.gif" onclick="InsertWord(':frown:');" width="15" height="15"></a>
  135.  
  136.             <textarea id="message" name="message" value="message"></textarea>
  137.             <span class="limit">140</span>
  138.             <input type="submit" id="submit-comment" value="" />
  139.         </form>
  140.         <div class="clear"></div>
  141.     </div>
  142. </div>
Aug 12 '09 #5
dlite922
1,584 Recognized Expert Top Contributor
I think I know what you need.

In review_image you have this $photo_id that you use to pull an image. Then if someone wants to make a comment, they fill out this form:

<form name="comment-submission"> on like 132 above.

This message and comment should be attached to that photo_id, which needs to get passed to submitComment.p hp

Well, just like how you're sending the message itself, send the photo_id, by putting it in a hidden field inside that form.

One thing I don't see is how you get to submitComment.p hp. Your form doesn't have an action="" that goes to this page.

A hidden field is like
Expand|Select|Wrap|Line Numbers
  1. <input type="hidden" value="<?php echo $photo_id;?>" />
Does that help?



Dan
Aug 12 '09 #6
dlite922
1,584 Recognized Expert Top Contributor
Forgot to mention, when you put it in a hidden field, you grab it just like you grab message, via $_POST. make sure you still run mysql_escape on it because just because it's hidden, doesn't mean people can't change the value.


Dan
Aug 12 '09 #7
luke noob
69 New Member
i tryed this but i get an error saying Undefined index: photo_Id in C:\wamp\www\fot ostor\submitCom ment.php

submitComment.p hp

Expand|Select|Wrap|Line Numbers
  1. $theMessage = addslashes(strip_tags($_POST['message']));
  2.  
  3. $photoId = mysql_escape_string($_POST['photo_Id']);
  4.  
  5. $q = "INSERT INTO shoutbox (photoId, date, content) VALUES ('" . $photoId . "', '" . $theDate . "', '" . $theMessage . "')";
  6. $result = $mysqli->query($q) or die ('error could not insert into shout box' . mysql_error());  
  7.  
review_image.ph p

Expand|Select|Wrap|Line Numbers
  1. <textarea id="message" name="message" value="message"></textarea>
  2.             <span class="limit">140</span>
  3.             <input type="hidden" id="photo_Id" value="<?php echo mysql_escape_string($photoId); ?>"  name="photo_Id">
  4.             <input type="submit" id="submit-comment" value="" />
  5.         </form>
  6.  
Aug 12 '09 #8
dlite922
1,584 Recognized Expert Top Contributor
is your form posting to that page?

i.e. ensure your form action is equal to "submitComment. php" and the method is equal to 'post'.

By the way, escape_string() is useless when you echo in the hidden field.

If you do the above it will work.



Dan
Aug 12 '09 #9
luke noob
69 New Member
didnt work, thanx anyway for your help and time, i think i gonna up to be honest..
Aug 12 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4354
by: Ricki Susic | last post by:
Hi, Can anyone help me to get my query printed when I parse ID. Here is the code: FILE: udskriv.php <?php
0
1565
by: James | last post by:
Hi, I am making a basic DVD shop and after having produced code which displays a list of DVDs from my database, I implemented a search facility which enables the user to search by title, director or actor. The user can also browse the DVDs by genre. However, when the DVDs are filtered, the id that is used to select a DVD and add it to the basket is incorrect as they are output in a sequential manner and so the DVD placed into the basket...
3
1652
by: sharma | last post by:
Hi, I am passing a variable through url. www.example.com/maxmoney.php?id=xyz@yahoo.com In the maxmoney.php I have tried to catch it this way $email=$_GET; when i echoed $email or $_GET; its not displaying. I am using php 5. I could not figure out what the issue is. can any
27
5322
by: meltedown | last post by:
urlencode turns # into %23 When I sent it thru $_GET, it dissapears, along with anything that comes after it. for example: urlencode turns HOYDM_EXC_#4_NAT into HOYDM_EXC_%234_NAT When I use it in an url
1
2165
by: stephane | last post by:
I have a problem which must be in this : print" <script type='text/javascript'> document.location.replace('http://127.0.0.1/add_task.php?req_id={$maxValue}&tk_request_name={$req_name}'); </script>"; or maybe here, in file2 <?php $tk_req_id = $_GET;
2
2780
by: just_me | last post by:
Hello, I'd like to ask if anyone knows the format /category/13/ where probably 13 is the ID if it's actually a directory/file and a script automatically created it when someone updated his site or they just use a regex method to extract the number (which means /13/ is virtual), in our case '13' and then try "select 'bla bla' from table where id='13' " which is the same as "$id = $_GET;" with the second type of
12
1760
by: Lennart Anderson | last post by:
I'm having a MySQl table wih a lot of information. I want to present some main fields in a table on one page. Each record do, of course, have a unique ID. The presnted table will have one field as a linked field. I want to be able to click this link, retreive the ID information for that record and then present detailed data for that record on the next page. How do I retreive the ID? Any hints are very much appreciated. Thanks
3
8266
by: LOSERSonSTRIKE | last post by:
I am trying to get the id number of a row in my table using the $_GET function... but i cant figure out how to retreive it. This is what i have now but it is coming up with an error. $result = mysql_query("SELECT * FROM net WHERE `id`=".$_GET); what is the problem with that? please reply
2
3136
by: keeps21 | last post by:
I have a script that recieves an id number via the address bar when a link is clicked. ie . index.php?id=1 if the link was for the story whose ID is 1. My script checks if a user is logged in, if not they are redirected to the login page. If logged in they may edit the story. I assign $_GET to $id.
0
8697
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9290
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9159
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4713
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3151
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2508
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2097
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.