2012-06-19 2 views
0

admin 사용자가 클라이언트 정보를 업데이트 할 수있는 페이지를 만듭니다. 우선 고객 정보를 쿼리하고 텍스트 필드에 표시합니다. 그런 다음 그 고객을 위해 원하는 새로운 정보를 입력 할 수 있습니다. SQL에서 update 명령을 실행하면 업데이트가 성공했다는 페이지로 이동하지만 데이터베이스를 다시 볼 때 고객 정보는 변경되지 않았습니다.데이터베이스의 고객 정보 업데이트가 작동하지 않습니다.

<?php 


//Function to sanitize values received from the form. Prevents SQL injection 
function clean($str) { 
    $str = @trim($str); 
    if(get_magic_quotes_gpc()) { 
     $str = stripslashes($str); 
    } 
    return mysql_real_escape_string($str); 
} 

//define username variable and sanitize 
$username = clean($_POST['username']); 

//Run query for selected user and store in an array 
$result = mysql_query("select * from members where username='".$username."'"); 
$row = mysql_fetch_array($result); 

//display all clients information in a form to edit 
echo '<h1>'.$username.'</h1>'; 
echo '<form name="update-client" action="update-client.php" />'; 
echo '<table>'; 
echo '<tr><td>'; 
echo '<input type="hidden" name="member_id" value="'.$row['member_id'].'"'; 
echo '</td></tr>'; 
echo '<tr><td>'; 
echo 'Username: <input name="username" type="text" value="'.$username.'" />'; 
echo '</td></tr>'; 
echo '<tr><td>'; 
echo 'Password: <input name="password" type="text" value="'.$row['password'].'" />'; 
echo '</td></tr>'; 
echo '<tr><td>'; 
echo 'Business Name: <input name="bizname" type="text" value="'.$row['bizname'].'" />'; 
echo '</td></tr>'; 
echo '<tr><td>'; 
echo 'Phone: <input name="phone" type="text" value="'.$row['phone'].'" />'; 
echo '</td></tr>'; 
echo '<tr><td>'; 
echo 'Email: <input name="email" type="text" value="'.$row['email'].'" />'; 
echo '</td></tr>'; 
echo '<tr><td>'; 
echo 'Website Address: <input name="url" type="text" value="'.$row['url'].'" />'; 
echo '</td></tr>'; 
echo '<tr><td>'; 
echo 'Contact: <input name="contact" type="text" value="'.$row['contact'].'" />'; 
echo '</td></tr>'; 
echo '<tr><td>'; 
echo 'Notes: <input name="notes" type="text" value="'.$row['notes'].'" />'; 
echo '</td></tr>'; 
echo '<tr><td>'; 
echo 'Sales Representative: <input name="sales_rep" type="text" value="'.$row['sales_rep'].'" />'; 
echo '</td></tr>'; 
echo '<tr><td>'; 
echo '<input name="submit" type="submit" value="Edit" />'; 
echo '</td></tr>'; 
echo '</table>'; 
echo '</form>'; 


?> 

갱신 client.php

<?php 


//Function to sanitize values received from the form. Prevents SQL injection 
function clean($str) { 
    $str = @trim($str); 
    if(get_magic_quotes_gpc()) { 
     $str = stripslashes($str); 
    } 
    return mysql_real_escape_string($str); 
} 

//define variables 
$member_id = $_POST['member_id']; 
$username = $_POST['username']; 
$password = $_POST['password']; 
$bizname = $_POST['bizname']; 
$phone = $_POST['phone']; 
$email = $_POST['email']; 
$url = $_POST['url']; 
$contact = $_POST['contact']; 
$notes = $_POST['notes']; 
$sales_rep = $_POST['sales_rep']; 
$member_type = $_POST['member_type']; 

//encrypt the password 
$password = md5($password); 

//Check for duplicate username 
if($username != '') { 
    $qry_uname = "SELECT * FROM members WHERE username='".$username."'"; 
    $result = mysql_query($qry_uname); 
    if($result) { 
     if(mysql_num_rows($result) > 0) { 
      $errmsg_arr[] = 'Username already in use'; 
      $errflag = true; 
     } 
     @mysql_free_result($result); 
    } 
    else { 
     die("Query failed1"); 
    } 
} 

//update customers information 
$qry = "update members set username='".$username."',password='".$password."',bizname='".$bizname."',phone='".$phone."',email='".$email."',url='".$url."',contact='".$contact."',notes='".$notes."',sales_rep='".$sales_rep."',member_type='".$member_type."' where member_id='".$member_id."'"; 

//Check whether the query was successful or not 
/*if(mysql_query($qry)) { 
    header("location: update-success.php"); 
exit(); 
    } 
else { 
    die("Query failed2"); 
    }*/ 

echo $qry; 

?> 

(고객 정보를 표시하는 페이지)

편집 - client.php 내 코드에 문제가 있습니까? 나는 변경하지 않을 경우 사용자 이름이 이미 존재하기 때문에, 중복 된 이름에 대한 사용자 이름과 ID가

확인을 확인 // 아파치 서버를

+0

먼저, 청결 기능이 무섭다. (http://stackoverflow.com/a/7810880/362536 참조)이 컨텍스트에서 작동하지만주의해야합니다. 준비된 쿼리를 사용하는 것이 좋습니다. 둘째,'@ '로 에러를 숨기지 마라. – Brad

+0

echo $ qry는 무엇을 반환합니까? –

+0

에 오신 것을 환영합니다. 적절한 태그를 사용하십시오. 'sql' 태그는 mysql 태그 여야합니다. 다음 번에 이것을 명심하십시오. 너무 좋아해. –

답변

0

을 사용하고 있습니다.

관련 문제