ellchr3 Posted December 12, 2011 Share Posted December 12, 2011 Hello. I'm having trouble with using hyperlinks in PHP. I've found several things online about using the print or echo command but for some reason it only gives the link as text and not an actual link. I'm very new to PHP so please be gentle <?php $con = mysql_connect("localhost","xxxxx","xxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("addresses", $con); $sql="INSERT INTO addresses (first_name, last_name, extra_info, address, city, state, zip) VALUES ('$_POST[first_name]','$_POST[last_name]','$_POST[extra_info]','$_POST[address]','$_POST[city]','$_POST[state]','$_POST[zip]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; echo "<a ref="http://localhost/index.html">Click here to enter another record</a>"; mysql_close($con) ?> Quote Link to comment https://forums.phpfreaks.com/topic/253022-php-hyperlinks/ Share on other sites More sharing options...
Adib Posted December 12, 2011 Share Posted December 12, 2011 Use single quote like this: echo '<a href="whatever">link_name</a>'; Quote Link to comment https://forums.phpfreaks.com/topic/253022-php-hyperlinks/#findComment-1297207 Share on other sites More sharing options...
Winstons Posted December 12, 2011 Share Posted December 12, 2011 In the code have very many errors. I've recommended you alter it so: <?php $con = mysql_connect("localhost","xxxxx","xxxxx") or die('Could not connect: ' . mysql_error()); mysql_select_db("addresses", $con); $sql = "INSERT INTO `addresses` (`first_name`, `last_name`, `extra_info`, `address`, `city`, `state`, `zip`) VALUES ('" . mysql_real_escape_string($_POST['first_name']) . "', '" . mysql_real_escape_string($_POST['last_name']) . "', '" . mysql_real_escape_string($_POST['extra_info']) . "', '" . mysql_real_escape_string($_POST['address']) . "', '" . mysql_real_escape_string($_POST['city']) . "', '" . mysql_real_escape_string($_POST['state']) . "', '" . mysql_real_escape_string($_POST['zip']) . "')"; mysql_query($sql,$con) or die('Error: ' . mysql_error()); echo "1 record added"; echo '<a ref="http://localhost/index.html">Click here to enter another record</a>'; mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/253022-php-hyperlinks/#findComment-1297208 Share on other sites More sharing options...
ellchr3 Posted December 15, 2011 Author Share Posted December 15, 2011 Even with changing the single and double quotes to the way you specified, Adib, it still doesn't create the hyperlink. Could it be something with the web server setup? I installed Xampp so I thought it configured everything properly. I also made the modifications that Winstons suggested and still get the same results. It doesn't create the hyperlink, only text. Thanks for your help so far guys. Any other suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/253022-php-hyperlinks/#findComment-1298135 Share on other sites More sharing options...
QuickOldCar Posted December 15, 2011 Share Posted December 15, 2011 it's <a href not <a ref here is a simple way by wrapping it in double quotes, and all single quotes within echo "<a href='http://localhost/index.html'>Click here to enter another record</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/253022-php-hyperlinks/#findComment-1298136 Share on other sites More sharing options...
ellchr3 Posted December 15, 2011 Author Share Posted December 15, 2011 That was it. Thank you for catching my idiot typo mistake! I don't know how I missed it for that long. Quote Link to comment https://forums.phpfreaks.com/topic/253022-php-hyperlinks/#findComment-1298148 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.