2012-03-25 4 views
0

양식은 sql 명령과 관련된 MySql 데이터베이스에 저장된 페이지 (example.php)의 모든 데이터를 삭제합니다. 제출 성공 후 양식 작업 상태 메시지

코드 정보

다음과 같습니다

if ((isset($_POST['id'])) && ($_POST['id'] != "")) { 
    $deleteSQL = sprintf("DELETE FROM users WHERE id=%s", 
         GetSQLValueString($_POST['id'], "int")); 


    mysql_select_db($database_example, $example); 
    $Result1 = mysql_query($deleteSQL, $example) or die(mysql_error()); 


    $deleteGoTo = "example.php"; 
    if (isset($_SERVER['QUERY_STRING'])) { 
    $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?"; 
    $deleteGoTo .= $_SERVER['QUERY_STRING']; 
    } 
    header(sprintf("Location: %s", $deleteGoTo)); 
} 

$colname_deleterecord = "5"; 
if (isset($_GET['id'])) { 
    $colname_deleterecord = $_GET['id']; 
} 
mysql_select_db($database_example, $example); 
$query_deleterecord = sprintf("SELECT id, user_name, email, address FROM users WHERE id = %s", GetSQLValueString($colname_deletetrecord, "int")); 
$deleterecord = mysql_query($query_deleterecord, $example) or die(mysql_error()); 
$row_deleterecord = mysql_fetch_assoc($deleteecord); 
$totalRows_deleterecord = mysql_num_rows($deleterecord); 

<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 
    <label> 
     <input type="submit" name="Delete Record" id="Delete Record" value="Delete Record" /> 
    </label> 
    <input name="id" type="hidden" id="id" value="<?php echo $row_deleterecord['id']; ?>" /> 
    </form> 

어떻게 그 후 순수 PHP 문법과 같은 페이지에 ("기록 삭제")와 같은 형태의 동작 상태 메시지를 표시하여야한다 성공적으로 제출 되었습니까?

미리 감사드립니다.

답변

0

순수 PHP로 할 수 없다. 아약스를 사용하여 할 필요가있다. 클라이언트 측 스크립팅 및 서버 측 스크립팅에 관한 ... 한 번 ur 양식이 제출되면 다른 PHP 스크립트로 리디렉션된다. 서버 측에서 ... 한 oreder에 유 단지 AJAX를 사용하는 데 필요한 클라이언트 측에 메시지를 게시 할 수 ... 성공적으로 삭제 한 후 내보기

+0

나는 이미 순수한 PHP 구문을 기반으로 여러 양식 관련 웹 응용 프로그램에 양식 제출 상태 메시지를 통합했지만 불행히도 나는이 경우 뭔가를 놓치고 제대로 작동하지 않을 수 있습니다. – polarexpress

0

에서 유일하게 사용되고 있습니다 이잖아, 당신은 당신의 상태 메시지를 작성,

// After mysql delete command 
$msg = urlencode("Record deleted"); 

을 편집 header 명령이

처럼 보이게하기
header(sprintf("Location: %s", $deleteGoTo . ?msg={$msg})); 

당신이 당신의 페이지에 메시지를 표시하고 코드 가

난 당신이 동일한 페이지에 양식을 제출하는 것을 볼 수있다, 당신은을 사용할 필요가 없습니다

echo isset($_GET['msg']) ? urldecode($msg) : ''; // This line will display the content of the variable $msg if it is set 
을 넣을 지금까지 그런 곳을 선택 header 기능,이 경우에는 두 번째 방법이 더 빠를 것이

$msg = "Record deleted"; 
echo isset($msg) ? $msg : ''; // This line will display the content of the variable $msg if it is set 

처럼 보이게 상태 메시지 표시 메시지를 변경합니다.

+0

첫 번째 해결책은 구문 분석 오류입니다. 예를 들어 변수'$ msg()를 사용하면 헤더에 sprintf ("Location : % s", $ deleteGoTo,? msg = {$ msg})) '는 mysql 결과 다음과 같은 방식으로 정의된다 : mysql_select_db ($ database_example, $ example); $ Result1 = mysql_query ($ deleteSQL, $ example) 또는 die (mysql_error()); $ msg = urlencode ("Record deleted");'반면에 두 번째 해결 방법은 양식이 성공적으로 제출 된 후 페이지에 상태 메시지를 인쇄하지 않습니다. – polarexpress

0

마지막으로 문제를 해결했습니다.

트릭은 쿼리 문자열 (키/값 쌍)을 헤더 위치 변수에 할당하거나 헤더 위치 변수를 관련 값으로 직접 바꾸는 것입니다.

그런 다음 함수 및 양식 변수와 연관된 쿼리 문자열 (키/값 쌍)을 전환하고 성공적으로 제출 한 후 페이지에 양식 동작 상태 메시지가 표시되어야하는 div로 감싸십시오.