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?

3 Answers 3

4
<?php 
    $courses_taken=$row['course_id'];
?>
<a href="course.php?course_id=<?php echo $courses_taken; ?>"></a>
Sign up to request clarification or add additional context in comments.

Comments

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>";

1 Comment

I'm sure this works, but another answers is more suitable for me.
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

2 Comments

He's using the "short open tags" feature. <?= is short for <?php echo
Yes use either of method. Both are ok with this.

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.