tascam424 Posted January 2, 2014 Share Posted January 2, 2014 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 Quote Link to comment Share on other sites More sharing options...
kicken Posted January 2, 2014 Share Posted January 2, 2014 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. Quote Link to comment Share on other sites More sharing options...
tascam424 Posted January 2, 2014 Author Share Posted January 2, 2014 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 26echo ""; 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 !! Quote Link to comment Share on other sites More sharing options...
Solution Ch0cu3r Posted January 2, 2014 Solution Share Posted January 2, 2014 (edited) 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 January 2, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
tascam424 Posted January 2, 2014 Author Share Posted January 2, 2014 Thank you ever so much, that does the trick !! Quote Link to comment 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.