Coding. i need a little help :)

hello against :smile:

there’s something i’ve got against with php.

<!-- INCLUDE overall_header.html -->
<div align="center">
<h2>My Den</h2>
<br>
<br>

<div class="panel">

<!-- PHP -->
include("config.php");

// Create connection
$conn = mysqli_connect($dbhost, $dbuser, $dbpasswd, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT crany_name, crany_breed, crany_gender, crany_level FROM phpbb_crany ORDER BY crany_id";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        echo "name: " . $row["crany_name"]. "<br> ";
        echo  "<img src="/img/image.php?crany_id=" . $row["crany_breed"]. "" alt="crany">"
    }
} else {
    echo "No Cranies in your den";
}

mysqli_close($conn);
<!-- ENDPHP -->

</div>
</div>

<!-- INCLUDE jumpbox.html -->
<!-- INCLUDE overall_footer.html -->

when i run the code gave me:

Parse error: syntax error, unexpected '=' in /home/vol6_8/epizy.com/epiz_23744660/htdocs/main/styles/template/den.php on line 26

how do i fix it :slight_smile:. i don’t know how do i put <img> tag into the echo()

thank you

1 Like

The contents of the src attribute should have apexes instead of quotation marks, and goes the same on the contents of the alt attribute on the img tag; if you don’t correct it, it gives the unexpected = on line 26.

Maybe I’m just missing something but I don’t see your opening or closing tags for the PHP script ‘<?php' and '?>’

@thenicopanda, the PHP opening and closing tags are where the comments <!-- PHP –> and <!-- ENDPHP –> are.

My bad :upside_down_face:

maybe switch this…
echo “<img src=”/img/image.php?crany_id=" . $row[“crany_breed”]. “” alt=“crany”>"

to this
echo “<img src=‘/img/image.php?crany_id=’ . $row[“crany_breed”]. " " alt=‘crany’>”

I think the Quotation marks inside of your echo might be what is messign you up :slight_smile:

Your quotation marks and apexes are not in correct disposition and correct form. This should make more errors in the code. Let me fix this for you and @anon19508339:
echo "<img src='/img/image.php?crany_id=".$row["crany_breed"]."' alt='crany'>";

2 Likes

worked ^^

thank you

now i’ve bug at this line:

$sql = "SELECT crany_name, crany_breed, crany_gender, crany_level FROM phpbb_crany ORDER BY crany_id WHERE crany_user='.$_REQUEST['user'].';";

tells me:
syntax error, unexpected ''

Here’s the correct line:
$sql = "SELECT crany_name, crany_breed, crany_gender, crany_level FROM phpbb_crany ORDER BY crany_id WHERE crany_user=".$_REQUEST["user"].";";

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.