1
$courses_taken=$row['course_id'];
<a href="course.php?course_id=$courses_taken"></a>

As you can see from above code, i'm taking a variable and passing it in query string, but this method is wrong.

How can i pass a variable in query string, as each user will have opted for different courses, thus they will have different course_id.

Is there a way to do it?

asked Oct 24, 2013 at 3:56

3 Answers 3

4
<?php 
 $courses_taken=$row['course_id'];
?>
<a href="course.php?course_id=<?php echo $courses_taken; ?>"></a>
answered Oct 24, 2013 at 4:54
0

You need an echo statement, and then interpolate the variable inside the string.

$courses_taken = $row['course_id'];
echo "<a href='course.php?course_id=$courses_taken'>click here</a>";
answered Oct 24, 2013 at 3:58
1
  • I'm sure this works, but another answers is more suitable for me. Commented Oct 24, 2013 at 16:46
0

Try this:

You are not using php tag to pass php variable in your anchor tag.
Do it like this:
<a href="course.php?course_id=<?= $courses_taken; ?>"></a>

- Thanks

answered Oct 24, 2013 at 5:13
2
  • He's using the "short open tags" feature. <?= is short for <?php echo Commented Oct 24, 2013 at 17:00
  • Yes use either of method. Both are ok with this. Commented Oct 25, 2013 at 4:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.