1

I'm trying to insert a hyperlink into a mysql databse which will then be retrieved by the user through a messaging system. I can't get the hyperlink to work; the output is just text saying "click here to respond".

So, when a user is invited to something(an event in this case), they will receive a message saying something like "Click here to respond." When the user clicks the link it will display the event. I echo'd this link on a page and I know it works, I just can't figure out how to get it to display once pulled fromt he database. It's being stored in a column that is of type varchar.

The inputs from code above this chunk have been sanatized using mysql_real_escape_string. Just thought I'd throw that out there before anyone mentions it.

$to = $userExplode[$i];
$from = "0";
$eventNumber = mysql_fetch_array($eventNum);
$title = "Event Invitation";
            $message =  '<a href= http:/localhost/loginsystem/viewevent.php?eventID = ' . $eventNumber['eventID'] . '> Click here </a> to respond.';
$sql = mysql_query("Insert INTO messages (title,message,to,from) VALUES ('New Message','$message','$to','$from')");

edit: I got it to work, it was tricky. I had to hard-code my messaging system to check if the system sent a message. Then it would echo the parts of the URL and insert the link after href="..."

5
  • 2
    You need to add quotes around your href attribute value. Commented Feb 7, 2012 at 22:40
  • Is the data inserted correctly into the database? How are you outputting it? Commented Feb 7, 2012 at 22:41
  • @CharlesSprayberry True although Commented Feb 7, 2012 at 22:41
  • 1
    To save on database space and not write http:/localhost/loginsystem/viewevent.php?eventID a million times, just save the event ID as a SQL entry, then call it in PHP with something like this: "<a href= 'http:/localhost/loginsystem/viewevent.php?eventID='<?php echo $var-from-database>> (Sorry if the syntax is off, typing from memory) Commented Feb 7, 2012 at 22:43
  • On second thought, how am I supposed to query the database if I have no "where" portion of my statement? For example "select eventID from messages where...." See what I mean, I don't know what I'm selecting from. Commented Feb 7, 2012 at 23:21

1 Answer 1

1

Put quotes around the href and give http:// the full two slashes, not just one :P Other than that, post your code to output it.

Sign up to request clarification or add additional context in comments.

1 Comment

I tried to make a link just to the homepage and it didn't work. I think it's an issue with hyperlinks in general, not just using variables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.