Jump to content

Parse Error


tascam424
Go to solution Solved by Ch0cu3r,

Recommended Posts

I would greatly appreciate any help in debugging this piece of code. But please be aware i am an absolute noob and have really just botched this together through trial and error, so please be gentle if you discover a school boy error (as far as php is concerned i am a school boy)

 

So the problem lies pretty close to the end of the code where i am trying to pass a database value into a URL, i'm pretty sure you can see what i am TRYING to achieve.

<?php
$con=mysqli_connect("localhost","host_admin","mypassword","host_cdg");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($con,"SELECT DISTINCT DiscNo, Description FROM CDG ORDER BY DiscNo");
echo "<td><input type=\"checkbox\" onClick=\"toggle(this)\" /> Toggle All<br/></td>";
echo "<table>
<tr>
<th>Tag</th>
<th>Description</th>
<th>DiscNo</th>
<th>View Songs</th>
</tr>";

while($row = mysqli_fetch_array($result))
  {
  echo "<tr>"; 
  echo "<td><input type=\"checkbox\" name=\"checkbox\" value=\"\" id=\"checkbox\"></td>";
  echo "<td>" . $row['Description'] . "</td>";
  echo "<td>" . $row['DiscNo'] . "</td>";
  echo "<td>" . $row['TrackNo'] . "</td>";
  echo "<td><a href=\"tracks.php?DiscNo=<?php echo $row["DiscNo"]; ?>\"</a></td>";
  echo "</tr>";
  }
echo "</table>";

mysqli_close($con);
?>

Greatly appreciate any help, thanks 

Link to comment
Share on other sites

If you are getting an error, you should post the exact error message you are getting. It helps people identify what the problem is.

 

As for your problem, it stems from this line:

  echo "<td><a href=\"tracks.php?DiscNo=<?php echo $row["DiscNo"]; ?>\"</a></td>";
You do not open new PHP tags in order to include a variable into a string. What you do is concatenate the variable into the string using the . (dot) operator. You did this successfully on the lines before where you have the TrackNo variable. Simply use that same format for this line as well.
Link to comment
Share on other sites

Thanks for your reply and apologies for not including correct information. I understand what you are saying however i'm still not getting it correct. I believe i'm not enclosing the html correctly

 

The error i am getting is

 

 

Parse error: syntax error, unexpected 'tracks' (T_STRING), expecting ',' or ';' in your code on line 26
  • echo "";

 

Here is the line of code as i have tried to amend it based on your previous direction, but i'm obviously going seriously wrong somewhere.

echo "<td><a href="tracks.php?DiscNo=" . $row["DiscNo"]; . "</a></td>";

Really appreciate your help !!

Link to comment
Share on other sites

  • Solution

You need to escape the doubled quotes for the HTML

echo "<td><a href=\"tracks.php?DiscNo=" . $row["DiscNo"] . "\">Link Text</a></td>"; // with double quoted string escape the double quotes
//                ^^------  Escape the double quotes -------^^

// Or do
echo '<td><a href="tracks.php?DiscNo="' . $row["DiscNo"] . '">Link Text</a></td>'; // with single quoted string you do not need to escape the double quotes.
Edited by Ch0cu3r
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.