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.php
this is my code....
image.php.... - $photoId = mysql_escape_string($_GET['id']);
-
$q = "SELECT * FROM comments WHERE photoId = '" . $photoId . "' ORDER BY date DESC LIMIT 5";
submitComment.php.... - $theMessage = addslashes(strip_tags($_POST['message']));
-
$q = "INSERT INTO comments (photoId, date, content) VALUES ('" . $photoId . "', '" . $theDate . "', '" . $theMessage . "')";
-
$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\fotostor\submitComment.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
thanks man. however, i am not sure if we are both pounding on the same problem here. what i am trying to contribute to is luke_noob's problem about passing variables without a form. I strugled with that question, too, and I was answered yesterday by a moderator nicknamed Atli. So, I think I got it good this time.
I would not like to take up your time trying to teach you (a moderator) what you already know. However, I would like to add the following.
The value of $_GET['id'] is taken from the URL of the page this ($_GET['id']) script is executed in. In other words, the initial page that linkes to the script page holding the $_GET script must have something like:
<a href="this_script.php?id=<?php echo 'whatever_the_id_is'?>"
Now, the $_GET takes the id from the URL - www.this_script.php?id=<?php echo 'whatever_the_id_is'?>. Then you use the mysql_escape_string($_GET['id']) to clear off any unwanted symbol so that you get only the result of " <?php echo 'whatever_the_id_is'?> "
THAT'S IT. All Luke_noob must pay attantion to is the nature of $_GET method. What it does is take variable values from the URL it is executed in. This did it for me. Atli explained it for me and I thought I should pass it on to Luke_noob too. I hope that helps everybody.
14 8835
how are users getting to submitComment.php 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
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.php 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
post the entire code from both pages and I'll try to take a look at it for you.
submitComment.php - <?php
-
-
require 'database.php';
-
require 'functions.php';
-
-
$timestamp = time();
-
$date_time_array = getdate($timestamp);
-
-
$hours = $date_time_array['hours'];
-
$minutes = $date_time_array['minutes'];
-
$seconds = $date_time_array['seconds'];
-
$month = $date_time_array['mon'];
-
$day = $date_time_array['mday'];
-
$year = $date_time_array['year'];
-
?>
-
<?php
-
-
$timestamp = mktime($hours + 8,$minutes,$seconds,$month,$day,$year);
-
$theDate = strftime('%Y-%m-%d %H:%M:%S',$timestamp);
-
-
mysql_connect("localhost","root","");
-
-
mysql_select_db("myPhotos") or die("Unable to select database");
-
-
$theMessage = addslashes(strip_tags($_POST['message']));
-
-
$photoId = mysql_escape_string($_GET['id']);
-
-
$q = "INSERT INTO shoutbox (photoId, date, content) VALUES ('" . $photoId . "', '" . $theDate . "', '" . $theMessage . "')";
-
$result = $mysqli->query($q) or die ('error could not insert into shout box' . mysql_error());
-
-
$theMessage = str_replace(":frown:"," <img src='smilies/frown.gif'>", $theMessage);
-
-
?>
-
<div class="comment-unapproved">
-
<div class="date">
-
<span class="day-month"><?php echo date('d M'); ?></span>
-
<span class="year"><?php echo date('y'); ?></span>
-
</div>
-
<span class="content"><?php echo stripslashes($theMessage); ?></span>
-
<div class="clear"></div>
-
</div>
review_image.php - <body>
-
<?php
-
require 'functions.php';
-
?>
-
-
<div id="container">
-
<div id="main">
-
-
<img src="images/logos/logofold.jpg" width="64" height="126" class="logofold">
-
<img src="images/logos/logo1.jpg" width="913" height="126" id="logo">
-
<div class="aerobuttonmenu">
-
-
<a href="#" class="aero"><span>About Us</span></a>
-
<a href="#" class="aero"><span>Services</span></a>
-
<a href="contact.html" class="aero"><span>Contact</span></a>
-
<a href="index.php" class="aero"><span>Home</span></a>
-
-
</div></div></div>
-
-
<div id="container">
-
<img src="images/logos/footer1.jpg" width="100%" height="31" align="right" id="footer1">
-
-
<p id="text"><font color="#486583">Photo Description</font></p>
-
</div> </div>
-
-
<div id="container">
-
<div id="main">
-
-
<?php getChosenPhoto($_GET['id']); ?>
-
<table align="center"><tr><td>
-
<div id="container">
-
<div id="comments">
-
<?php
-
-
include("database.php");
-
-
function datediff($d1, $d2)
-
{
-
$d1 = (is_string($d1) ? strtotime($d1) : $d1);
-
$d2 = (is_string($d2) ? strtotime($d2) : $d2);
-
-
$diff_secs = abs($d1 - $d2);
-
$base_year = min(date("Y", $d1), date("Y", $d2));
-
-
$diff = mktime(0, 0, $diff_secs, 1, 1, $base_year);
-
$diffArray = array(
-
"years" => date("Y", $diff) - $base_year,
-
"months_total" => (date("Y", $diff) - $base_year) * 12 + date("n", $diff) - 1,
-
"months" => date("n", $diff) - 1,
-
"days_total" => floor($diff_secs / (3600 * 24)),
-
"days" => date("j", $diff) - 1,
-
"hours_total" => floor($diff_secs / 3600),
-
"hours" => date("G", $diff),
-
"minutes_total" => floor($diff_secs / 60),
-
"minutes" => (int) date("i", $diff),
-
"seconds_total" => $diff_secs,
-
"seconds" => (int) date("s", $diff)
-
);
-
if($diffArray['days'] > 0){
-
if($diffArray['days'] == 1){
-
$days = '1 day';
-
}else{
-
$days = $diffArray['days'] . ' days';
-
}
-
return $days . ' and ' . $diffArray['hours'] . ' hours ago';
-
}else if($diffArray['hours'] > 0){
-
if($diffArray['hours'] == 1){
-
$hours = '1 hour';
-
}else{
-
$hours = $diffArray['hours'] . ' hours';
-
}
-
return $hours . ' and ' . $diffArray['minutes'] . ' minutes ago';
-
}else if($diffArray['minutes'] > 0){
-
if($diffArray['minutes'] == 1){
-
$minutes = '1 minute';
-
}else{
-
$minutes = $diffArray['minutes'] . ' minutes';
-
}
-
return $minutes . ' and ' . $diffArray['seconds'] . ' seconds ago';
-
}else{
-
return 'Less than a minute ago';
-
}
-
}
-
-
$timestamp = time();
-
$date_time_array = getdate($timestamp);
-
-
$hours = $date_time_array['hours'];
-
$minutes = $date_time_array['minutes'];
-
$seconds = $date_time_array['seconds'];
-
$month = $date_time_array['mon'];
-
$day = $date_time_array['mday'];
-
$year = $date_time_array['year'];
-
-
$timestamp = mktime($hours + 8,$minutes,$seconds,$month,$day,$year);
-
$theDate = strftime('%Y-%m-%d %H:%M:%S',$timestamp);
-
-
mysql_connect("localhost","root","");
-
-
mysql_select_db("myphotos") or die("Unable to select database");
-
-
$photoId = mysql_escape_string($_GET['id']);
-
-
$q = "SELECT * FROM shoutbox WHERE photoId = '" . $photoId . "' ORDER BY date DESC LIMIT 5";
-
-
$result = $mysqli->query($q);
-
while($row = $result->fetch_array()) {
-
$date = strtotime($row['date']);
-
$dayMonth = date('d M', $date);
-
$year = date('y', $date);
-
$message = $row['content'];
-
$datediff = datediff($theDate, $date);
-
-
$message = str_replace(":frown:"," <img src='smilies/frown.gif'>", $message);
-
?>
-
-
<div class="comment">
-
<div class="date">
-
<span class="day-month"><?php echo $dayMonth; ?></span>
-
<span class="year"><?php echo $year; ?></span>
-
</div>
-
<span class="content"><?php echo stripslashes($message);?> <span class="time"><?php echo $datediff; ?></span></span>
-
<div class="clear"></div>
-
</div>
-
<?php
-
}
-
-
-
?>
-
</div>
-
<div id="submission">
-
<form name="comment-submission">
-
-
<a title="Frown"><img border="0" src="smilies/frown.gif" onclick="InsertWord(':frown:');" width="15" height="15"></a>
-
-
<textarea id="message" name="message" value="message"></textarea>
-
<span class="limit">140</span>
-
<input type="submit" id="submit-comment" value="" />
-
</form>
-
<div class="clear"></div>
-
</div>
-
</div>
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.php
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.php. Your form doesn't have an action="" that goes to this page.
A hidden field is like - <input type="hidden" value="<?php echo $photo_id;?>" />
Does that help?
Dan
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
i tryed this but i get an error saying Undefined index: photo_Id in C:\wamp\www\fotostor\submitComment.php submitComment.php -
$theMessage = addslashes(strip_tags($_POST['message']));
-
-
$photoId = mysql_escape_string($_POST['photo_Id']);
-
-
$q = "INSERT INTO shoutbox (photoId, date, content) VALUES ('" . $photoId . "', '" . $theDate . "', '" . $theMessage . "')";
-
$result = $mysqli->query($q) or die ('error could not insert into shout box' . mysql_error());
-
review_image.php -
<textarea id="message" name="message" value="message"></textarea>
-
<span class="limit">140</span>
-
<input type="hidden" id="photo_Id" value="<?php echo mysql_escape_string($photoId); ?>" name="photo_Id">
-
<input type="submit" id="submit-comment" value="" />
-
</form>
-
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
didnt work, thanx anyway for your help and time, i think i gonna up to be honest..
i am a newbie myself, and am struggling with the exact same problem... so i thought i might offer some insight: ae you sure that your SQL statement of WHERE has the proper value. What I see you have is:
WHERE photoId = '" . $photoId . "
Try maybe:
"...... WHERE photold= 'photoId' ...." Note that I am specifically suggesting you take out the periods and double quotes.
@bibiki
that would insert "photoId" as value, which is imo not intended.
yeah... I c that I forgot the dollar sign. so my actual suggestion is that you put in '$photoId'
both ways are valid. which one you use is a matter of personal preference.
thanks man. however, i am not sure if we are both pounding on the same problem here. what i am trying to contribute to is luke_noob's problem about passing variables without a form. I strugled with that question, too, and I was answered yesterday by a moderator nicknamed Atli. So, I think I got it good this time.
I would not like to take up your time trying to teach you (a moderator) what you already know. However, I would like to add the following.
The value of $_GET['id'] is taken from the URL of the page this ($_GET['id']) script is executed in. In other words, the initial page that linkes to the script page holding the $_GET script must have something like:
<a href="this_script.php?id=<?php echo 'whatever_the_id_is'?>"
Now, the $_GET takes the id from the URL - www.this_script.php?id=<?php echo 'whatever_the_id_is'?>. Then you use the mysql_escape_string($_GET['id']) to clear off any unwanted symbol so that you get only the result of " <?php echo 'whatever_the_id_is'?> "
THAT'S IT. All Luke_noob must pay attantion to is the nature of $_GET method. What it does is take variable values from the URL it is executed in. This did it for me. Atli explained it for me and I thought I should pass it on to Luke_noob too. I hope that helps everybody.
Sign in to post your reply or Sign up for a free account.
Similar topics
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
|
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...
|
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...
|
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...
|
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}');...
|
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...
|
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...
|
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 =...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |