2017-09-21 1 views
1

고객 관리 시스템을 만들고 데이터베이스에 이미 이미지를 추가했는데 편집 페이지에서 해당 이미지를 검색하는 것이 좋습니다. 그러나 코드가 작동하지 않을 수 있습니다. 나는이 분야에서 새로운 분야에있어 실수를 저 지르고있다. 이 경우에 친절하게 도와주세요.mysql db에서 이미지를 검색 할 수 없습니다.

오류는 표시되지 않지만 이미지가 표시되지 않습니다.

감사합니다. 쿼리 $image = $row['image'];에서 이미지의 값을 받고으로

<?php 
require_once('includes\database.php'); 
?> 

<?php 
$id = $_GET['id']; 

$query = "SELECT * FROM customer 
       INNER JOIN customer_address 
       ON customer.id=customer_address.customer 
       WHERE customer.id=$id"; 
$mysqli->query($query); 

if ($result = $mysqli->query($query)) { 
    while ($row = $result->fetch_assoc()) { 
     $name = $row['name']; 
     $email = $row['email']; 
     $phone = $row['phone']; 
     $password = $row['password']; 
     $image = $row['image']; 
     $address = $row['address']; 
     $Country = $row['Country']; 
     $City = $row['City']; 
     $Zip_code = $row['Zip_code']; 
    } 

    $result->close(); 
} else { 

    echo "error"; 
} 
?> 

<?php 
if ($_POST) { 

    $id = $_GET['id']; 

    $name = mysqli_real_escape_string($mysqli, $_POST['name']); 
    $email = mysqli_real_escape_string($mysqli, $_POST['email']); 
    $phone = mysqli_real_escape_string($mysqli, $_POST['phone']); 
    $password = md5(mysqli_real_escape_string($mysqli, $_POST['password'])); 
    $image = $_FILES['image']['name']; 
    $tmp_image = $_FILES['image']['tmp_name']; 
    $address = mysqli_real_escape_string($mysqli, $_POST['address']); 
    $Country = mysqli_real_escape_string($mysqli, $_POST['Country']); 
    $City = mysqli_real_escape_string($mysqli, $_POST['City']); 
    $Zip_code = mysqli_real_escape_string($mysqli, $_POST['Zip_code']); 

    $sql = "UPDATE customer SET 
     name='$name', 
     email='$email', 
     phone='$phone', 
     password='$password', 
     image='$image' 
     WHERE id=$id"; 

    $mysqli->query($sql); 

    $sql = "UPDATE customer_address SET 
     address='$address', 
     Country='$Country', 
     City='$City', 
     Zip_code='$Zip_code' 
     WHERE customer=$id"; 

    $mysqli->query($sql) or die(); 
    $msg = "Record updated"; 
    header('url: index.php'); 

    exit; 
} 
?> 

<html lang="en"> 
    <head> 
     <meta charset="utf-8"> 
     <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
     <meta name="viewport" content="width=device-width, initial-scale=1"> 
     <title>CManager | Edit Customer</title> 
     <!-- Bootstrap core CSS --> 
     <link href="css/bootstrap.min.css" rel="stylesheet"> 
     <!-- Custom styles for this template --> 
     <link href="css/jumbotron-narrow.css" rel="stylesheet"> 
    </head> 
    <body> 
     <div class="container"> 
      <div class="header"> 
       <ul class="nav nav-pills pull-right"> 
        <li class="active"><a href="index.php">Home</a></li> 
        <li><a href="add_customer.php">Add Customer</a></li> 
       </ul> 
       <h3 class="text-muted">Store CManager</h3> 
      </div> 

      <div class="row marketing"> 
       <div class="col-lg-12"> 
        <h2>Edit Info</h2> 
        <table class="table table-striped"> 

         <form method="POST"> 
          <table> 
           <tr> 
            <td>Name:</td> 
            <td><input type="text" name="name" required="true" value="<?php echo $name; ?>"></td> 
           </tr> 

           <tr> 
            <td>Email:</td> 
            <td><input type="email" name="email" required="true" value="<?php echo $email; ?>"></td> 
           </tr> 

           <tr> 
            <td>Phone:</td> 
            <td><input type="phone" name="phone" required="true" value="<?php echo $phone; ?>"></td> 
           </tr> 

           <tr> 
            <td>Password:</td> 
            <td><input type="password" name="password" required="true" value="<?php echo $password; ?>"></td> 
           </tr> 

           <tr> 
            <td>Image:</td> 
            <td><img src="<?php echo $row->image; ?>" height="100px" height="100px"></td> 
           </tr> 

           <tr><td><h2>Other Details:</h2><td></tr> 
           <tr> 
            <td>Address:</td> 
            <td><input type="text" name="address" value="<?php echo $address; ?>"></td> 
           </tr> 
           <tr> 
            <td>Country:</td> 
            <td><input type="text" name="Country" value="<?php echo $Country; ?>"></td> 
            </select> 
           </tr> 
           <tr> 
            <td>City:</td> 
            <td><input type="text" name="City" value="<?php echo $City; ?>"></td> 
            </select> 
           </tr> 
           <tr> 
            <td>Zip Code:</td> 
            <td><input type="text" name="Zip_code" value="<?php echo $Zip_code; ?>"></td> 
           </tr> 

           <tr><td><input type="submit" value="update" name="submit"></td></tr> 

          </table> 
         </form> 
        </table> 
       </div> 
      </div> 
      <div class="footer"> 
       <p>&copy; Company 2014</p> 
      </div> 
     </div> 
    </body> 
</html> 
+2

이미지를 데이터베이스에 저장하는 대신 이미지 이름 만 저장하십시오. 프로젝트 디렉토리에 같은 것을 업로드하십시오 ...... –

+0

그리고 http://bobby-tables.com을 방문하여 SQL 인젝션에 대해 알아보십시오. 도주는 충분하지 않습니다. – Twinfriends

답변

1

그래서 당신은 $image 대신 $row['image'] 또는 $row->image 사용해야합니다.

아래 코드 줄을 시도해보십시오. 그러면 도움이 될 것입니다.

<td><img src="path/to/image/<?php echo $image; ?>" height="100px" height="100px"></td> 
1

이가 작동이

<tr><td>Image:</td><td><img src="<?php echo $image; ?>" height="100px" height="100px"></td> 

희망을 시도하면

0

당신이 당신을 디렉토리 폴더에 데이터베이스 테이블 및 이미지 업로드에서 이미지 이름을 저장하는 경우 그것은 더 좋을 것이다 그것을 쉽게 할 수 있습니다. 하지만 문제에 먼저 $ 이미지 변수는 다음이 작동 폴더의 전체 이미지 경로와 이미지 업로드가 포함 된 경우 다음

<td><img src="<?php echo $row->image; ?>" height="100px" height="100px"></td> 

<td><img src="<?php echo $image; ?>" height="100px" height="100px"></td> 

를 업데이트 $ 이미지

<?php 
require_once('includes\database.php'); 

$image = ''; 
$id= $_GET['id']; 

/* your code */ 

을 정의 , 또는 사용 youruploadfolder/<?php echo $image; ?>

관련 문제