Welcome to WebmasterWorld Guest from 54.166.178.177

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

dynamic pages

     
10:07 am on Apr 12, 2013 (gmt 0)



im new to using php, mysql and this website. i just could really do with some help on this, but as far as i know this code should be working...


mysql_select_db("test_art_center", $con);

$result = mysql_query("SELECT * FROM events");

while($event_data=mysql_fetch_array($result)){

$id = $event_data['EventID'] ;

echo "<a href=\"Edetails_page.php?id= '$id'>";
echo $event_data['description']." ".$event_data['UserID']." </a>";
echo "<br><br>";


i am trying to display all of the rows of the table as links to dynamic pages but it will only display one result and on the second page if i use

$id = $_GET['id'] ;

echo $id;


it shows the whole row and not just the event ID

i realise the code isn't going to be fantastic but if anyone could point out any way that i have gone wrong then please let me know
11:35 am on Apr 12, 2013 (gmt 0)

WebmasterWorld Senior Member swa66 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



First:

Do not use the obsolete mysql interface anymore - esp. not for learning new things.
Use instead the mysqli (note the i) interface. ref: [php.net...]

Next, be very careful of security bugs.

e.g.:
$id = $_GET['id'] ;

echo $id;

is a XSS hole of epic proportions. Ref: [owasp.org...]
I'm unsure if you're aware of XSS: but one hole anywhere on your site has the potential to affect ALL you have on your entire domain.

As the your real question, it's a bit hard to see with the info you gave, but
echo "<a href=\"Edetails_page.php?id= '$id'>";

seems to have an spurious space after the equal sign that might be causing you grief.
11:40 am on Apr 12, 2013 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



echo "<a href=\"Edetails_page.php?id= '$id'>";


Don't surround the URL parameter in single quotes and don't precede with a space. You also aren't closing the double quote of your href attribute, which is where all your extra data is coming. ie. It should be something like:
echo "<a href=\"Edetails_page.php?id=$id>\"";


Although I would choose to write this with single quotes and use string concatenation (so you don't need to escape the double quotes in your string):
echo '<a href="Edetails_page.php?id='.$id.'>"';


I would assume you are seeing the same jumble of data in the address bar?
3:27 pm on Apr 12, 2013 (gmt 0)



Hey
thanks guys, yea I was getting the data in the address bar but this appears to have solved it and the link itself is working fine... the link is however not displaying the full data and is just showing a number... any ideas why this could be?
4:03 pm on Apr 12, 2013 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



The link should be showing the contents of $event_data['description'] and $event_data['UserID'] - whatever they might contain. Have you verified that these fields are correct and populated? Use print_r() to get a snapshot of the array's contents.
5:23 pm on Apr 12, 2013 (gmt 0)



ok i think its sorted, thanks penders
 

Featured Threads

Hot Threads This Week

Hot Threads This Month