2013-06-27 4 views
0

안녕하세요. 내 데이터베이스에서 내 간단한 추천 앱을 업데이트하지 않는 경우 작은 문제가 있습니다. 이 구문 분석 스크립트를 사용하여 데이터베이스에 항목을 삽입 할 때 내 애플행이 업데이트되지 않음

<?php 
     $testtitle = preg_replace('#[^a-z0-9""-. ]#i', '', $_POST['ts_tt']); 
     $testbody = preg_replace('#[^a-z0-9""-. ]#i', '', $_POST['ts_tb']); 
     $compowner = preg_replace('#[^a-z0-9 ]#i', '', $_POST['ts_co']); 
     $ownertitle = preg_replace('#[^a-z0-9 ]#i', '', $_POST['ts_ot']); 
     $compname = preg_replace('#[^a-z0-9 ]#i', '', $_POST['ts_cn']); 
     $compwebsite = preg_replace('#[^a-z0-9 .-]#i', '', $_POST['ts_cw']); 

     include_once "../php_includes/db_conx.php"; 

     $sql = "INSERT INTO testimonials (testtitle, testbody, compowner, ownertitle, compname, compwebsite) 
       VALUES ('$testtitle', '$testbody', '$compowner', '$ownertitle', '$compname', '$compwebsite')"; 
     if (!mysql_query($sql, $connection)){ 
      die('Error: ' . mysql_error()); 
    } 
    exit(); 
?> 

내가 내 업데이트 스크립트를 업데이트하지 않는 것을 발견 .. 잘 작동! 나는 여기에 뭔가 빠져 있니? 많은 감사 ...

<?php 
     $pid = $_POST['pid']; 
     $testtitle = preg_replace('#[^a-z0-9""-. ]#i', '', $_POST['ts_tt']); 
     $testbody = preg_replace('#[^a-z0-9""-. ]#i', '', $_POST['ts_tb']); 
     $compowner = preg_replace('#[^a-z0-9 ]#i', '', $_POST['ts_co']); 
     $ownertitle = preg_replace('#[^a-z0-9 ]#i', '', $_POST['ts_ot']); 
     $compname = preg_replace('#[^a-z0-9 ]#i', '', $_POST['ts_cn']); 
     $compwebsite = preg_replace('#[^a-z0-9 .-]#i', '', $_POST['ts_cw']); 

     include_once "../php_includes/db_conx.php"; 

     $sql = "UPDATE testimonials SET testtitle='$testtitle', testbody='$testbody', compowner='$compowner', ownertitle='$ownertitle', compname='$compname', compwebsite='$compwebsite' WHERE id='$pid' LIMIT 1"; 

     if (!mysql_query($sql, $connection)){ 
      die('Error: ' . mysql_error()); 
    } 
    exit(); 
?> 

UPDATE 이 내가 지금 너희들이 무엇을 ...

<?php 
$sql = "SELECT * FROM testimonials WHERE id='$pid'"; 

     $pid = $_POST['pid']; 
     $testtitle = preg_replace('#[^a-z0-9""-. ]#i', '', $_POST['ts_tt']); 
     $testbody = preg_replace('#[^a-z0-9""-. ]#i', '', $_POST['ts_tb']); 
     $compowner = preg_replace('#[^a-z0-9 ]#i', '', $_POST['ts_co']); 
     $ownertitle = preg_replace('#[^a-z0-9 ]#i', '', $_POST['ts_ot']); 
     $compname = preg_replace('#[^a-z0-9 ]#i', '', $_POST['ts_cn']); 
     $compwebsite = preg_replace('#[^a-z0-9 .-]#i', '', $_POST['ts_cw']); 

     include_once "../php_includes/db_conx.php"; 

     $sql = "UPDATE testimonials SET testtitle='$testtitle', testbody='$testbody', compowner='$compowner', ownertitle='$ownertitle', compname='$compname', compwebsite='$compwebsite' WHERE id='$pid'"; 

     if (!mysql_query($sql, $connection)){ 
      die('Error: ' . mysql_error()); 
    } 
    exit(); 
?> 

안녕 여기에 요청 모두 같은 요청에 따라 내 HTML 양식입니다! 나는 그것이 테이블에 있다는 것을 압니다. 나는이 인 형태로 위의 일부 PHP 코드 ...

<?php 
$pid = ereg_replace("[^0-9]", "", $_POST['pid']); 
include_once "../php_includes/db_conx.php"; 
$sql = "SELECT testtitle, testbody, compowner, ownertitle, compname, compwebsite FROM testimonials WHERE id='$pid' LIMIT 1"; 
$query = mysql_query($sql, $connection) or die (mysql_error()); 
while ($row = mysql_fetch_array($query)) { 
    $testtitle = $row["testtitle"]; 
    $testtitle = str_replace("<br />", "", $testtitle); 
    $testbody = $row["testbody"]; 
    $testbody = str_replace("<br />", "", $testbody); 
    $compowner = $row["compowner"]; 
    $ownertitle = $row["ownertitle"]; 
    $compname = $row["compname"]; 
    $compwebsite = $row["compwebsite"]; 
} 
mysql_free_result($query); 
?> 

이 그리고 내 양식은 UPDATE에서

<form method="post" action="testimonial_edit_parse.php" onsubmit="return validate_form ();"> 
    <tr> 
    <td width="12%" align="right" bgcolor="#F5E4A9">Testimonial Full Title</td> 
    <td width="88%" bgcolor="#F5E4A9"><input name="ts_tt" id="testtitle" type="text" size="80" maxlength="64" value="<?php echo $testtitle; ?>" /></td> 
    </tr> 
    <tr> 
    <td align="right" valign="top" bgcolor="#DAEAFA">Testimonial Body</td> 
    <td bgcolor="#DAEAFA"><textarea name="ts_tb" id="testbody" cols="60" rows="16"><?php echo $testbody; ?></textarea></td> 
    </tr> 
    <tr> 
    <td align="right" bgcolor="#D7EECC">Company Owner</td> 
    <td bgcolor="#D7EECC"><input name="ts_co" id="compowner" type="text" maxlength="64" size="80" value="<?php echo $compowner; ?>" /></td> 
    </tr> 
    <tr> 
    <td align="right" bgcolor="#D7EECC">Owner Title</td> 
    <td bgcolor="#D7EECC"><input name="ts_ot" id="ownertitle" type="text" maxlength="64" size="80" value="<?php echo $ownertitle; ?>"/></td> 
    </tr> 
    <tr> 
    <td align="right" bgcolor="#D7EECC">Company Name</td> 
    <td bgcolor="#D7EECC"><input name="ts_cn" id="compname" type="text" maxlength="64" size="80" value="<?php echo $compname; ?>" /></td> 
    </tr> 
    <tr> 
    <td align="right" bgcolor="#D7EECC">Company Website</td> 
    <td bgcolor="#D7EECC"><input name="ts_cw" id="compwebsite" type="text" maxlength="64" size="80" value="<?php echo $compwebsite; ?>" /></td> 
    </tr> 
    <tr> 
    <td>&nbsp;</td> 
    <td><input type="submit" name="ts_button" value="Submit this edit" /></td> 
    </tr> 
    </form> 
+0

당신이 $ pid'은 데이터베이스에있는'확신에서 ID와 숨겨진 필드를 채울 필요가? –

+2

mysql_로 시작하는 PHP 함수는 PHP 5.5.0부터 사용되지 않습니다. 그렇게 할 수있는 위치에 있다면, [MySQLi] (http://www.php.net/manual/en/book.mysqli.php) 또는 [PDO] (http : /www.php.net/manual/en/ref.pdo-mysql.php) 확장 기능을 사용하십시오. –

+3

이런 질문이 너무 많습니다. 시간을내어 [오류를 해석하고 코드를 수정하는 방법]을 배우십시오 (http://jason.pureconcepts.net/2013/05/fixing-php-errors/). –

답변

0

첫 번째로, 나는 PDO ...로 이것을 할 것입니다. 왜냐하면 ... mysql_ * 함수는 더 이상 사용되지 않으며 곧 PHP에서 제거 될 것입니다. PDO는보다 안전하며, mysql_real_escape_string 모든 것을 준비 할 필요가 없다.

$conn = new PDO("mysql:host=localhost;dbname=$yourdbname",$yourdbuser,$yourdbpass); 

    $sql = "UPDATE testimonials 
    SET testtitle=?, testbody=?, compowner=?, ownertitle=?, compname=?, compwebsite=?, 
    WHERE id=?"; 
    $q = $conn->prepare($sql); 
    $q->execute(array($testtitle,$testbody, $compowner, $ownertitle, $compname, $compwebsite, $pid)); 

귀하의 질문에 대답 할 수 있지만

는 ..... 나는 당신의 $_POST['pid'] 정말 때문에 행이 업데이트되지 않고 제대로 전달되지 않는다 생각한다. 당신은 필요

우리 도움이 더 내가 의심으로

편집

, 그 어디는 $ PID를 통과하지 않는 원하는 경우,이 정보를 제출하여 HTML 양식 보여 양식, 따라서 반대편에있는 스크립트는 어떤 ID를 업데이 트할지 전혀 모른다.

이 기록

<input type="hidden" name="pid" id="pid" value="<?echo $idfromdatabase;?>"> 
+0

건배 KyleK MySQL은 내 강한 포인트가 아닙니다! 도움을 주셔서 감사합니다. 위로 내 양식을 추가했습니다! –

0

제거 LIMIT 1 괜찮을한다 ...입니다. 행 수를 계산할 때를 제외하고는 UPDATE 구문에서 LIMIT가 필요하지 않습니다.

+0

건배하지만 여전히 업데이트되지 않습니다. 내가 원래 가지고있는 질문을 업데이트 할 것이다. 많은 감사합니다 –

관련 문제