Lambneck Posted February 16, 2009 Share Posted February 16, 2009 I have a problem with selecting hyperlinks from mysql. How come when someone submits info containing a hyperlink to my database and then when that info(link) is selected and displayed onto a page it doesnt take me to the site in their link but to something like the following url: http://mysite.com/"http://their-hyperlink.com/" ??? Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 16, 2009 Share Posted February 16, 2009 I would suspect, that your site adds 'http://mysite.com/"' part when displaying links. Did you check if the links are stored in MySQL with or without 'http://mysite.com/"'? Quote Link to comment Share on other sites More sharing options...
Lambneck Posted February 16, 2009 Author Share Posted February 16, 2009 I forgot to mention that they are using html to make the links: <a href="http://www.their-hyperlink.com">http://www.their-hyperlink.com</a> still, why would my site prefix its url when displaying links? Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 16, 2009 Share Posted February 16, 2009 Because it's coded to do so. Are you using a some kind of CMS? Quote Link to comment Share on other sites More sharing options...
Lambneck Posted February 16, 2009 Author Share Posted February 16, 2009 No, i kindof raped and pasted this code, but i dont see anything that would create this effect. what should I be looking for in the code that would cause this prefix to be attached to these outgoing hyperlinks? Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 16, 2009 Share Posted February 16, 2009 First of all, check how they look in the database. If they're unmodified, then it's the displaying code that adds this. If they're modified, then they're obviously being modified when saving to database. Quote Link to comment Share on other sites More sharing options...
Lambneck Posted February 16, 2009 Author Share Posted February 16, 2009 They look normal in the database. So I looked over the selection code but cant find anything to indicate why this is happening. :-\ Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 16, 2009 Share Posted February 16, 2009 Well... it has to be somewhere between the database and html output. Quote Link to comment Share on other sites More sharing options...
Lambneck Posted February 16, 2009 Author Share Posted February 16, 2009 yah i agree but what? could be nl2br() somehow? heres the selection code: <?php require_once('pageLoad.php'); if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Woops! YOU broke the system! Quick! Refresh the page!"); if (!mysql_select_db($database)) die("Can't... se... select... data... base."); $id = (int) $_GET['id']; $sql = "SELECT * FROM $table WHERE submission_id=$id"; $result = mysql_query($sql); if(mysql_num_rows($result) == 1){ $row = mysql_fetch_array($result); echo "<table>"; echo "<tr><td><strong>"; echo stripslashes(htmlspecialchars($row['col_1'])); echo " | "; echo date("l M dS, Y", $row['submission_date']); echo " | "; echo "Posted by: "; echo stripslashes(htmlspecialchars($row['name'])); echo "</strong><hr></td></tr>"; echo "<tr><td><br>".(nl2br($row['col_2']))."</td></tr>"; echo "</table>"; }else{ echo 'Oops! Something went wrong! Try something else!'; } ?> Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 16, 2009 Share Posted February 16, 2009 No... nl2br is not the culprit here... Hmm... No idea... Quote Link to comment Share on other sites More sharing options...
Lambneck Posted February 16, 2009 Author Share Posted February 16, 2009 Argh! it was the form processing code. needed a stripslashes() around (nl2br($row['col_2'])... it was mysql_real_escape_string() that flubbed it up while processing the info to the database. Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 16, 2009 Share Posted February 16, 2009 Huh... too much escaping... Quote Link to comment Share on other sites More sharing options...
Lambneck Posted February 16, 2009 Author Share Posted February 16, 2009 Huh... too much escaping... What do you recommend? Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 16, 2009 Share Posted February 16, 2009 Do you have magic_quotes enabled on your server? Quote Link to comment Share on other sites More sharing options...
Lambneck Posted February 17, 2009 Author Share Posted February 17, 2009 Not sure. I thought using mysql_real_escape_string() was more effective than magic_quotes anyway, no? Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 17, 2009 Share Posted February 17, 2009 Surely it is. But if you have magic_quotes enabled, you're escaping variables twice... which is once too much Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.