0

Hi,

Please, I am trying to open a details page from the main page item link as follows:

Link on the main page:

<td><a href=details.php?c_id=<?php echo ".urlencode($c_id)." ?> ><img src="./images/<?php echo $row['cfilename']; ?>" width="90" height="120" alt="" /></a></td>

And the details.php page is:

<?php
$mysqli = new mysqli("localhost", "joseph", " ", "collectionsdb");

if(!isset($_GET['c_id']))

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

// get value of object id that was sent from address bar

    /* Create the prepared statement */
    if ($stmt = $mysqli->prepare("SELECT c_id,ctitle,csubject,creference,cyear,cobjecttype,cmaterial,ctechnic,cwidth,cheight,cperiod,cmarkings,cdescription,csource,cartist,cfilename FROM collections WHERE c_id='$c_id'")) {  
    /* Execute the prepared Statement */
    $stmt->execute();

    /* Bind results to variables */
    $stmt->bind_result($c_id,$ctitle,$csubject,$creference,$cyear,$cobjecttype,$cmaterial,$ctechnic,$cwidth,$cheight,$cperiod,$cmarkings,$cdescription,$csource,$cartist,$cfilename);

    $c_id=mysql_real_escape_string($_GET['c_id']);
// get value of object id that sent from address bar


    /* fetch values */
    while ($rows = $stmt->fetch()) {
     // display records in a table

    // image table   
?>
    <table border="1" align="left">
<tr>
    <td rowspan=16 valign=top> <?php echo '<img src="./images/'.$cfilename.'" width="300" height="400" />';  ?> </td>
</tr>

<tr><td>ID</td><td><?php echo $c_id; ?></td></tr>
<tr><td>TITLE</td><td><?php echo $ctitle; ?></td></tr>
<tr><td>SUBJECT</td><td><?php echo $csubject; ?></td></tr>
<tr><td>REFERENCE No.</td><td><?php echo $creference; ?></td></tr>
<tr><td>YEAR</td><td><?php echo $cyear; ?></td></tr>
<tr><td>OBJECT TYPE</td><td><?php echo $cobjecttype; ?></td></tr>
<tr><td>MATERIAL USED</td><td><?php echo $cmaterial; ?></td></tr>
<tr><td>TECHNIC</td><td><?php echo $ctechnic; ?></td></tr>
<tr><td>WIDTH</td><td><?php echo $cwidth; ?></td></tr>
<tr><td>HEIGHT</td><td><?php echo $cheight; ?></td></tr>
<tr><td>PERIOD</td><td><?php echo $cperiod; ?></td></tr>
<tr><td>MARKINGS</td><td><?php echo $cmarkings; ?></td></tr>
<tr><td>DESCRIPTION</td><td width=300><?php echo $cdescription; ?></td></tr>
<tr><td>SOURCE</td><td><?php echo $csource; ?></td></tr>
<tr><td>ARTIST</td><td><?php echo $cartist; ?></td></tr>
</table>

<?php
    }

    /* Close the statement */
    $stmt->close();
}
else {
    /* Error */
    printf("Prepared Statement Error: %s\n", $mysqli->error);
}

/* close our connection */
$mysqli->close();
?>              
            <!-- Column 1 end -->
        </div>

    </div>
</div>
</div>
<div id="footer">

</div>

</body>
</html>

Unfortunately, when the link is pressed, I get an error Undefined variable: c_id ... on line 16 of the details.php page.

Kindly help me resolve this error.

Joseph

3
Contributors
3
Replies
18
Views
4 Years
Discussion Span
Last Post by diafol
1

You haven't set the $c_id var as far as I can see. Do this:

if(!isset($_GET['c_id']))
    $c_id = $_GET['c_id'];
Votes + Comments
Useful post
1

and also dont forget to santize your values too.
if its a number ensure its a number else default to 0, etc, etc

0

Good point, use a parameterized query with binding.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.