conan318 Posted April 28, 2011 Share Posted April 28, 2011 trying to post a link to the database $amessage ="<a href="link.php">this is a link </a>"; then return that link later on another page. Quote Link to comment https://forums.phpfreaks.com/topic/234930-can-a-variable-hold-a-link/ Share on other sites More sharing options...
conan318 Posted April 28, 2011 Author Share Posted April 28, 2011 $amessage ='<a href="link.php">this is a link </a>'; solved my own problem lol Quote Link to comment https://forums.phpfreaks.com/topic/234930-can-a-variable-hold-a-link/#findComment-1207344 Share on other sites More sharing options...
conan318 Posted April 28, 2011 Author Share Posted April 28, 2011 $amessage ='<a href='freindacept?username=.$info['username']}.php'>Has sent you a freind request </a>'; same thing trying to post link to the database then return it later having trouble getting the syntax right. Parse error: syntax error, unexpected T_STRING in /home/a7817347/public_html/freinds.php on line 6 Quote Link to comment https://forums.phpfreaks.com/topic/234930-can-a-variable-hold-a-link/#findComment-1207357 Share on other sites More sharing options...
btherl Posted April 28, 2011 Share Posted April 28, 2011 You're using quotes to mark the start and end of the string, but you're also using quotes inside the string. And the syntax for interpolating the variable is a bit off. Try this: $amessage ='<a href="freindacept?username={$info['username']}.php">Has sent you a freind request </a>'; BTW it is "friend", not "freind". Also you might be wanting this: $amessage ='<a href="freindacept.php?username={$info['username']}">Has sent you a freind request </a>'; Quote Link to comment https://forums.phpfreaks.com/topic/234930-can-a-variable-hold-a-link/#findComment-1207363 Share on other sites More sharing options...
conan318 Posted April 28, 2011 Author Share Posted April 28, 2011 here's the full code i have pretty much if someone clicks on a users profile and presses contact request link i wanting to send the link to confirm friends to alog which then shows up in the other users activity log if they press the link friends are confirmed then it takes both there users names and records them into the friends database. still getting Parse error: syntax error, unexpected T_STRING session_start(); require "database.php"; $myusername=$_SESSION['myusername']; $getuname=$_POST['to_user']; $amessage ='<a href="freindacept.php?username={$info['username']}">Has sent you a friend request </a>'; $message=$_POST['message']; if (!isset($_GET['username'])) { $data = mysql_query("SELECT * FROM users LEFT JOIN status ON status.username=users.username WHERE status.username = '".$_SESSION['myusername']."' ORDER BY id DESC LIMIT 1;") or die(mysql_error()); } else { $getuname = mysql_real_escape_string($_GET['username']); $data = mysql_query("SELECT * FROM users LEFT JOIN status ON status.username=users.username WHERE status.username = '".$getuname."' ORDER BY id DESC LIMIT 1;") or die(mysql_error()); mysql_query("INSERT INTO alog (from_user, to_user, message ) VALUES ('$myusername', '$getuname','$amessage')") OR die("A log error <br>".mysql_error()); } Echo 'freind request sent'; ?> still getting Parse error: syntax error, unexpected T_STRING Quote Link to comment https://forums.phpfreaks.com/topic/234930-can-a-variable-hold-a-link/#findComment-1207374 Share on other sites More sharing options...
Pikachu2000 Posted April 28, 2011 Share Posted April 28, 2011 $amessage ="<a href=\"freindacept.php?username={$info['username']}\">Has sent you a friend request </a>\""; Quote Link to comment https://forums.phpfreaks.com/topic/234930-can-a-variable-hold-a-link/#findComment-1207375 Share on other sites More sharing options...
btherl Posted April 28, 2011 Share Posted April 28, 2011 Oops, thankyou for correcting that pikachu Quote Link to comment https://forums.phpfreaks.com/topic/234930-can-a-variable-hold-a-link/#findComment-1207386 Share on other sites More sharing options...
kenrbnsn Posted April 28, 2011 Share Posted April 28, 2011 Or <?php $amessage ="<a href='freindacept.php?username={$info['username']}'>Has sent you a friend request </a>'"; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/234930-can-a-variable-hold-a-link/#findComment-1207395 Share on other sites More sharing options...
conan318 Posted April 28, 2011 Author Share Posted April 28, 2011 it kinda working but when i click the link it takes me to http://datenight.netne.net/freindacept.php?username= so its not passing the varaible $data = mysql_query("SELECT * FROM alog, users WHERE from_user=users.username AND alog.to_user='$myusername' ORDER BY alog.id DESC LIMIT 10;") or die(mysql_error()); //Puts it into an array while($info = mysql_fetch_array( $data )) { ?> <div class="chatroom"> <? Echo "<a href='viewprofile.php?username={$info['username']}'><img src='http://datenight.netne.net/images/".$info['img'] ."' width='30' height='30''></a>".$info['from_user']." ".$info['message']; } ?> [code] Quote Link to comment https://forums.phpfreaks.com/topic/234930-can-a-variable-hold-a-link/#findComment-1207401 Share on other sites More sharing options...
kenrbnsn Posted April 28, 2011 Share Posted April 28, 2011 Is $info['username'] set to anything? Put <?php echo '<pre>' . print_r($info,true) . '</pre>'; ?> at the start of your while loop. This will tell you what's being returned by the query. Ken Quote Link to comment https://forums.phpfreaks.com/topic/234930-can-a-variable-hold-a-link/#findComment-1207402 Share on other sites More sharing options...
conan318 Posted April 28, 2011 Author Share Posted April 28, 2011 it should because its working for the img link Quote Link to comment https://forums.phpfreaks.com/topic/234930-can-a-variable-hold-a-link/#findComment-1207403 Share on other sites More sharing options...
kenrbnsn Posted April 28, 2011 Share Posted April 28, 2011 The img link uses $info['img'] which is different than $info['username'] Just because it works for one, doesn't mean it works for the other. Ken Quote Link to comment https://forums.phpfreaks.com/topic/234930-can-a-variable-hold-a-link/#findComment-1207404 Share on other sites More sharing options...
conan318 Posted April 28, 2011 Author Share Posted April 28, 2011 the img link is using $info[username] and the location of the img is using $info. Quote Link to comment https://forums.phpfreaks.com/topic/234930-can-a-variable-hold-a-link/#findComment-1207410 Share on other sites More sharing options...
btherl Posted April 28, 2011 Share Posted April 28, 2011 Then it's likely that $info['img'] is set, but $info['username'] is not. You need to find out why $info['username'] isn't set. Quote Link to comment https://forums.phpfreaks.com/topic/234930-can-a-variable-hold-a-link/#findComment-1207937 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.