• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

PHP get image based on sql value

Zaluthe

New Member
Joined
Mar 31, 2010
Messages
8
Reaction score
2
Hello peeps!

Trying to make a variable for a webpage that will list image from an external place based on the value from my database.

Example:

http://somewebpage.com/someimage.gif


I want it to fetch the image based on my "itemid" value from database.


Everything works, except listing image from that page with fetching the "itemid" with is the name of the files, ofcourse.

Following error occurs:

Notice: Use of undefined constant itemid - assumed 'itemid' in D:\Xampps\htdocs\shop2insert.php on line 114

Notice: Array to string conversion in D:\Xampps\htdocs\shop2insert.php on line 114

PHP File:


PHP:
  $items=mysql_select_multi("SELECT itemid FROM test;");
      $web="test.com";
    
    
   ?>
            <tr>
            <td><?php echo $row[1]; ?></td>
            <td><?php echo $row[2]; ?></td>
            <td><?php echo $row[3]; ?></td>
            <td><?php echo $row[4]; ?></td>
            <?php echo '<td><img src="http://'. $web .'/'. $items['itemid'] .'.'. $config['shop']['imageType'] .'" alt="img"></td>'; ?>




image.png




Anyone got any clue???
 
Last edited:
You should post the entire file, not just a fragment of it, because $items isn't being utilized in the script that we can see.

Edit: my bad there is $items hehe
 
Last edited:
<?php require_once 'engine/init.php';
include 'layout/overall/header.php';
protect_page();
admin_only($user_data);

?>
<table width="20%" border="0" align="center" cellpadding="10" cellspacing="5">
<tr>
<td><form name="form1" method="post" action="shop2.php"/>

<table width="10%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td colspan="10"><strong>Insert Data Into mySQL Database </strong></td>
</tr>
<tr>
<td width="7">Type</td>
<td width="8">:</td>
<td width="20%"><input name="type" type="radio" value="1" />Items</td>
<td width="30%"><input name="type" type="radio" value="2" />Premium Days</td>
<td width="20%"><input name="type" type="radio" value="3" />Sex Change</td>

</tr>
<tr>
<td>Item ID</td>
<td>:</td>
<td><input name="itemid" align="center" type="text" id="itemid"></td>
</tr>
<tr>
<td>Count</td>
<td>:</td>
<td><input name="count" type="text" id="count"></td>
</tr>
<td>Description</td>
<td>:</td>
<td><input name="description" type="text" id="description"></td>
</tr>
<td>Points</td>
<td>:</td>
<td><input name="points" type="text" id="points"></td>
</tr>
<tr>
<td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td>
<td> <input type='reset' value='RESET'/></td>
</tr>
</table>
</form>
</td>
</tr>
</table>

<?php
mysql_connect("localhost","root", "password");
mysql_select_db("theforgottenserver");
$sql_query="SELECT id, id, itemid, description, points FROM znote_shop";
$result_set=mysql_query($sql_query);
if(isset($_GET['delete_id']))
{
$sql_query="DELETE FROM znote_shop WHERE id=".$_GET['delete_id'];
mysql_query($sql_query);
header("Location: shop2insert.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP Delete Data With Javascript Confirmation - By Cleartuts</title>

<script type="text/javascript">
function delete_id(id)
{
if(confirm('Sure To Remove This Record ?'))
{
window.location.href='shop2insert.php?delete_id='+id;
}
}
</script>
</head>
<body>
<center>

<div id="header">
<div id="content">

</div>
</div>
<div id="body">
<div id="content">
<table align="center">
<tr>
<th>ID</th>
<th>Item ID</th>
<th>Description</th>
<th>Points</th>
<th>Image</th>
<th>Delete</th>
</tr>
<?php
if(mysql_num_rows($result_set)>0)
{
while($row=mysql_fetch_row($result_set))
{

$items=mysql_select_multi("SELECT itemid FROM znote_shop;");
$web="test.com";


?>
<tr>
<td><?php echo $row[1]; ?></td>
<td><?php echo $row[2]; ?></td>
<td><?php echo $row[3]; ?></td>
<td><?php echo $row[4]; ?></td>
<?php echo '<td><img src="http://'. $web .'/'. $items['itemid'] .'.'. $config['shop']['imageType'] .'" alt="img"></td>'; ?>





<td align="center"><a href="javascript:delete_id(<?php echo $row[0]; ?>)"><img src="layout/sub/delete.png" width="20px" height="20px" alt="Delete" /></a></td>
</tr>
<?php
}
}
else
{
?>
<tr>
<th colspan="4">There's No data found !!!</th>
</tr>
<?php
}
?>
</table>
</div>
</div>

<div id="footer">
<div id="content">
<hr /><br/>
</div>
</div>

</center>
</body>
</html>
 
Try this
PHP:
if(mysql_num_rows($result_set)>0)
{
  while($row=mysql_fetch_row($result_set))
  {

      $items=mysql_select_multi("SELECT `itemid` FROM `znote_shop`;");
      $web="test.com";
   
   
   ?>
            <tr>
            <td><?php echo $row[1]; ?></td>
            <td><?php echo $row[2]; ?></td>
            <td><?php echo $row[3]; ?></td>
            <td><?php echo $row[4]; ?></td>
          
            <?php echo
            if ( isset($items['itemid']) && $items['itemid'] != '' ){
            '<td><img src="http://'. $web .'/'. $items['itemid'] .'.'. $config['shop']['imageType'] .'" alt="img"></td>';
            }
            ?>
     
         
         
 

         
            <td align="center"><a href="javascript:delete_id(<?php echo $row[0]; ?>)"><img src="http://mail.skogliveien.com:8080/layout/sub/delete.png" width="20px" height="20px" alt="Delete" /></a></td>
            </tr>
            <?php
  }
}
 
Made corrections, this may not work either, you should print_r what $items is
PHP:
if(mysql_num_rows($result_set)>0)
{
  while($row=mysql_fetch_row($result_set))
  {

      $items=mysql_select_multi("SELECT `itemid` FROM `znote_shop`;");
      $web="test.com";
  
  
   ?>
            <tr>
            <td><?php echo $row[1]; ?></td>
            <td><?php echo $row[2]; ?></td>
            <td><?php echo $row[3]; ?></td>
            <td><?php echo $row[4]; ?></td>
         
            <?php echo
            if(is_array($items)){
                foreach($items as $item){
                    if ( isset($item['itemid']) && $item['itemid'] != '' ){
            '<td><img src="http://'. $web .'/'. $item['itemid'] .'.'. $config['shop']['imageType'] .'" alt="img"></td>';
                    }
                }
            }else{
                if ( isset($items) && $items != '' ){
            '<td><img src="http://'. $web .'/'. $items .'.'. $config['shop']['imageType'] .'" alt="img"></td>';
                }
            }
            ?>
    
        
        


        
            <td align="center"><a href="javascript:delete_id(<?php echo $row[0]; ?>)"><img src="http://mail.skogliveien.com:8080/layout/sub/delete.png" width="20px" height="20px" alt="Delete" /></a></td>
            </tr>
            <?php
  }
}
 
Last edited:
Parse error: syntax error, unexpected 'if' (T_IF) in D:\Xampps\htdocs\shop2insert.php on line 116


Line116: if(is_array($items)){
 
Parse error: syntax error, unexpected 'if' (T_IF) in D:\Xampps\htdocs\shop2insert.php on line 116


Line116: if(is_array($items)){
See you missed that too :p
PHP:
if(mysql_num_rows($result_set)>0)
{
  while($row=mysql_fetch_row($result_set))
  {

      $items=mysql_select_multi("SELECT `itemid` FROM `znote_shop`;");
      $web="test.com";
  
  
   ?>
            <tr>
            <td><?php echo $row[1]; ?></td>
            <td><?php echo $row[2]; ?></td>
            <td><?php echo $row[3]; ?></td>
            <td><?php echo $row[4]; ?></td>
         
            <?php
            if(is_array($items)){
                foreach($items as $item){
                    if ( isset($item['itemid']) && $item['itemid'] != '' ){
                        echo '<td><img src="http://'. $web .'/'. $item['itemid'] .'.'. $config['shop']['imageType'] .'" alt="img"></td>';
                    }
                }
            }else{
                if ( isset($items) && $items != '' ){
                    echo '<td><img src="http://'. $web .'/'. $items .'.'. $config['shop']['imageType'] .'" alt="img"></td>';
                }
            }
            ?>
    
        
        


        
            <td align="center"><a href="javascript:delete_id(<?php echo $row[0]; ?>)"><img src="http://mail.skogliveien.com:8080/layout/sub/delete.png" width="20px" height="20px" alt="Delete" /></a></td>
            </tr>
            <?php
  }
}
 
Last edited:
There are a whole lot of redundancies here. 'layout/overall/header.php' should already set the DOCTYPE and <head> etc, and you already have a connection to the database from 'enigne/init.php'.
All you need to do is to use the znote functions, mysql_select_multi and mysql_delete (see 'engine/database/connect.php').

Why complicate things?
PHP:
<?php require_once 'engine/init.php';
include 'layout/overall/header.php';
protect_page();
admin_only($user_data);

?>
<table width="20%" border="0" align="center" cellpadding="10" cellspacing="5">
    <tr>
        <td>
            <form name="form1" method="post" action="shop2.php"/>
                <table width="10%" border="0" cellspacing="1" cellpadding="3">
                    <tr>
                        <td colspan="10"><strong>Insert Data Into mySQL Database </strong></td>
                    </tr>
                    <tr>
                        <td width="7">Type</td>
                        <td width="8">:</td>
                        <td width="20%"><input name="type" type="radio" value="1" />Items</td>
                        <td width="30%"><input name="type" type="radio" value="2" />Premium Days</td>
                        <td width="20%"><input name="type" type="radio" value="3" />Sex Change</td>
                    </tr>
                    <tr>
                        <td>Item ID</td>
                        <td>:</td>
                        <td><input name="itemid" align="center" type="text" id="itemid"></td>
                    </tr>
                    <tr>
                        <td>Count</td>
                        <td>:</td>
                        <td><input name="count" type="text" id="count"></td>
                    </tr>
                        <td>Description</td>
                        <td>:</td>
                        <td><input name="description" type="text" id="description"></td>
                    </tr>
                    <td>Points</td>
                        <td>:</td>
                        <td><input name="points" type="text" id="points"></td>
                    </tr>
                    <tr>
                        <td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td>
                        <td> <input type='reset' value='RESET'/></td>
                    </tr>
                </table>
            </form>
        </td>
    </tr>
</table>

<?php
if(isset($_GET['delete_id']))
{
    $sql_query="DELETE FROM znote_shop WHERE id=".$_GET['delete_id'];
    mysql_delete($sql_query);
    header("Location: shop2insert.php");
}
?>

<script type="text/javascript">
function delete_id(id)
{
    if(confirm('Sure To Remove This Record ?'))
    {
        window.location.href='shop2insert.php?delete_id='+id;
    }
}
</script>

<center>
<table align="center">
    <tr>
        <th>ID</th>
        <th>Item ID</th>
        <th>Description</th>
        <th>Points</th>
        <th>Image</th>
        <th>Delete</th>
    </tr>
    <?php
    $items=mysql_select_multi("SELECT id, itemid, description, points FROM znote_shop;");
    $web="test.com";
    if($items !== false)
    {
        foreach ($items as $item)
        {
            ?>
            <tr>
                <td><?php echo $item['id']; ?></td>
                <td><?php echo $item['itemid']; ?></td>
                <td><?php echo $item['description']; ?></td>
                <td><?php echo $item['points']; ?></td>
                <?php echo '<td><img src="http://'. $web .'/'. $item['itemid'] .'.'. $config['shop']['imageType'] .'" alt="img"></td>'; ?>

                <?php echo '<td align="center"><a href="javascript:delete_id(' . $item["id"] .')"><img src="layout/sub/delete.png" width="20px" height="20px" alt="Delete" /></a></td>'; ?>
            </tr>
            <?php
        }
    }
    else
    {
        ?>
        <tr>
            <th colspan="4">There's No data found !!!</th>
        </tr>
        <?php
    }
    ?>
</table>

</center>

<?php include 'layout/overall/footer.php'; ?>
I can't say for sure that this will work either, but it's a start.
 
Back
Top