hi,
i am having trouble echoing from posted page, in the url it shows the send id but it gives me error for this queryand i get this errorCode PHP:$_GET['$songs_set["id"]'];
Undefined index: $songs_set["id"]
| SitePoint Sponsor |
What does the url look like?
My guess is it should be:
Code:$_GET['id'];
Guido - Community Team Advisor
Do you know where the (database) error is? Add it to the list!
Thinking Web: Voices of the Community
Blog - Free Flash Slideshow Widget
I'm guessing actually you've gotten your arrays backwards.
Were you trying to do $songs_set[$_GET['id']] ?
I hope there is no space between song and =Code:single.php?song =1
Guido - Community Team Advisor
Do you know where the (database) error is? Add it to the list!
Thinking Web: Voices of the Community
Blog - Free Flash Slideshow Widget
The undefined index error is because you had things mixed up like StarLion said.
Change your code like he told you, and try again.
Guido - Community Team Advisor
Do you know where the (database) error is? Add it to the list!
Thinking Web: Voices of the Community
Blog - Free Flash Slideshow Widget
Because the variable name isn't 'id', but 'song'. You called it that way in the query string.
single.php?key=value
$_GET['key'] contains value
single.php?song=1 (get rid of that space)
$_GET['song'] contains 1
Guido - Community Team Advisor
Do you know where the (database) error is? Add it to the list!
Thinking Web: Voices of the Community
Blog - Free Flash Slideshow Widget
Let's add some color:
I can't explain it any clearer than that.Code:single.php?key=value $_GET['key'] contains value single.php?song=1 $_GET['song'] contains 1
Do a print_r($_GET); in your code to see the contents of $_GET.
Guido - Community Team Advisor
Do you know where the (database) error is? Add it to the list!
Thinking Web: Voices of the Community
Blog - Free Flash Slideshow Widget
i don't know what is wrong. i am reading a tut too it says the same about passing and getting value, this is page 1
this is page 2Code PHP:<a href=\"single.php?song=key{$songs_set["id"]}\">".$songs_set["title"]."</a>
and i m echoing on page 2Code PHP:$song = $_REQUEST['id'];
Code PHP:echo $song;
here is my code
and here is the single pageCode PHP:<form action="single.php" method="post"> <div class="songslist"> <table class="songs" width="1020" border="0" cellpadding="0" cellspacing="0"> <tr> <th width="281">Artist</th> <th width="281">Title</th> <th width="204">Length</th> <th width="204">Genre</th> <th width="50">Ratings</th> </tr> </table> <table class="songs" width="1020" border="0" cellpadding="0" cellspacing="0"> <tr> <?php $songs = mysql_query("SELECT * FROM songs LIMIT 10"); if($songs){ echo mysql_error(); } while($songs_set = mysql_fetch_array($songs)){ echo "<tr> <td width=\"281\">".$songs_set["artist"]."</td>" . "<td width=\"281\"><a href=\"single.php?song={$songs_set["id"]}\">".$songs_set["title"]."</a></td>" . "<td width=\"204\">".$songs_set["length"]."</td>" . "<td width=\"204\">".$songs_set["genre"]."</td>" . "<td width=\"50\">".$songs_set["rating"]."</td><tr>"; } ?> </table> </div> </form>
now can u guide me where am i going wrong?Code PHP:<?php $song = $_REQUEST['id']; echo "$song"; ?>
single.php?song=1
$_REQUEST['id'];
This is where you're going wrong.
Like I told you, do a print_r($_GET); in your code (or a print_r($_REQUEST); ), and you'll see what exactly is sent to single.php
Guido - Community Team Advisor
Do you know where the (database) error is? Add it to the list!
Thinking Web: Voices of the Community
Blog - Free Flash Slideshow Widget
Change
inPHP Code:song={$songs_set["id"]}
That line should have given you an error though.PHP Code:song={$songs_set['id']}
Guido - Community Team Advisor
Do you know where the (database) error is? Add it to the list!
Thinking Web: Voices of the Community
Blog - Free Flash Slideshow Widget
Did you change id to song?
Guido - Community Team Advisor
Do you know where the (database) error is? Add it to the list!
Thinking Web: Voices of the Community
Blog - Free Flash Slideshow Widget
and the print_r of $_GET still gives an empty error?
Can you check the html code of the first page in your browser and post the link code here?
Guido - Community Team Advisor
Do you know where the (database) error is? Add it to the list!
Thinking Web: Voices of the Community
Blog - Free Flash Slideshow Widget
well i get undefined index for print_r for songs.i did posted the page code above,here i'll do it again
and second pageCode HTML4Strict:<form action="single.php" method="post"> <div class="songslist"> <table class="songs" width="1020" border="0" cellpadding="0" cellspacing="0"> <tr> <th width="281">Artist</th> <th width="281">Title</th> <th width="204">Length</th> <th width="204">Genre</th> <th width="50">Ratings</th> </tr> </table> <table class="songs" width="1020" border="0" cellpadding="0" cellspacing="0"> <tr> <?php $songs = mysql_query("SELECT * FROM songs LIMIT 10"); if($songs){ echo mysql_error(); } while($songs_set = mysql_fetch_array($songs)){ echo "<tr> <td width=\"281\">".$songs_set["artist"]."</td>" . "<td width=\"281\"><a href=\"single.php?song={$songs_set['id']}\">".$songs_set["title"]."</a></td>" . "<td width=\"204\">".$songs_set["length"]."</td>" . "<td width=\"204\">".$songs_set["genre"]."</td>" . "<td width=\"50\">".$songs_set["rating"]."</td><tr>"; } ?> </table> </div> </form>
Code PHP:print_r ($_POST['song']);
Why don't you just do what I ask you?
The first time I asked you about $_GET, you changed things to $_REQUEST.
Now, you change things to $_POST.
Of course things don't work. You send the data in the query string of the link, so $_POST is empty. You must use $_GET.
Guido - Community Team Advisor
Do you know where the (database) error is? Add it to the list!
Thinking Web: Voices of the Community
Blog - Free Flash Slideshow Widget
Yes, I understand the feelingAnd it's a good thing you're not just waiting for answers, but also trying yourself. It's just hard to help when the feedback says my suggestions didn't work, while in reality they did work, but other changes created a new error (or even worse, the same error).
goodit worked![]()
First you'll have to sanitize it. If it's supposed to be a number, cast it with (int). If it's a string, put it through mysql_real_escape_string. And then you can use it in a query.so now can i use this id to put it in query to get information from the table?
Guido - Community Team Advisor
Do you know where the (database) error is? Add it to the list!
Thinking Web: Voices of the Community
Blog - Free Flash Slideshow Widget
Bookmarks