MySQL ve PHP ile sorun maintiaing biçiminin devlet

1 Cevap php

Ben kontrol olarak onay kutusunu göstermek ve gerektiğinde kontrolsüz olarak güncellemek, onay kutuları ile bir form göstermek işaretli ise geri gönderebilir ya da değil, veritabanında sonucu depolamak ve daha sonra sayfanın bir sonraki yüklemede gereken bir sayfa var.

Ben yüzen "işaretli" olan benim çözüm ideal değil anlıyorum, ama iyi çalışıyor, ve ben bunu sopa ile istiyorum.

Ben yaşıyorum sorun rekor bir veritabanına doğru takılmış olabilir iken, bu sayfayı yeniden üzerine kontrol hem görünmüyor, ve doğru kayıtlarının güncellenmesi olmasıdır.

İşte benim kod:

<?php
error_reporting(E_ALL);
if (isset($_GET["cmd"]))
  $cmd = $_GET["cmd"]; else
if (isset($_POST["cmd"]))
  $cmd = $_POST["cmd"]; else
die("Invalid URL");
if (isset($_GET["pk"])) {
    $pk = $_GET["pk"];
}
$checkDeleted = "";
$checkNotice = "";
$checkWarrant = "";
$checkPromise = "";
$checkCompensation = "";
$checkBond = "";
$checkInjunction = "";
$checkActionpay = "";
$checkActionorder = "";
$checkCourtpayment = "";
$checkForeclosure = "";
$checkPenalty = "";
$checkboxes = $_POST['checkboxes'];
if (in_array('deleted', $checkboxes))
  $checkDeleted = 'checked';
$con = mysqli_connect("localhost","user","pass", "db");
if (!$con) {
    echo "Can't connect to MySQL Server. Errorcode: %s\n". mysqli_connect_error();
    exit;
}
$con->set_charset("utf8");
$getformdata = $con->query("select ARTICLE_NO, deleted from STATUS where ARTICLE_NO = '$pk'");
while ($row = mysqli_fetch_assoc($getformdata)) {
    $ARTICLE_NO = $row['ARTICLE_NO'];
    $checkDeleted = $row['deleted'];
}
if($cmd=="submitinfo") {
    if ($ARTICLE_NO == null) {
    	$statusQuery = "INSERT INTO STATUS VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    	if ($statusInfo = $con->prepare($statusQuery)) {
    		$statusInfo->bind_param("sssssssssssss", $pk, $checkDeleted, $checkNotice, $checkWarrant, $checkPromise, $checkCompensation, $checkBond, $checkInjunction, $checkActionpay, $checkActionorder, $checkCourtpayment, $checkForeclosure, $checkPenalty);
    		$statusInfo->execute();
    		$statusInfo->close();
    		echo $pk;
    		echo $checkDeleted;
    	} else {
    		print_r($con->error);
    	}
    } else if ($ARTICLE_NO == $pk) {
    	$statusQuery = "UPDATE STATUS SET deleted = ?, notice = ?, warrant = ?, promise = ?, compensation = ?, bond = ?, injunction = ?, actionpay = ?, actionorder = ?, courtpayment = ?, foreclosure = ?,penalty = ? WHERE ARTICLE_NO = ?";
    	if ($statusInfo = $con->prepare($statusQuery)) {
    		$statusInfo->bind_param("sssssssssssss", $checkDeleted, $checkNotice, $checkWarrant, $checkPromise, $checkCompensation, $checkBond, $checkInjunction, $checkActionpay, $checkActionorder, $checkCourtpayment, $checkForeclosure, $checkPenalty, $pk);
    		$statusInfo->execute();
    		$statusInfo->close();
    	} else {
    		print_r($con->error);
    	}
    }
}
if($cmd=="EditStatusData") {
    echo '<link rel="stylesheet" href="style.css" type="text/css" />' . "\n";
    echo "<form name=\"statusForm\" action=\"test.php?pk=".$pk."\" method=\"post\" enctype=\"multipart/form-data\">
<h1>Editing information for Auction No: ".$pk."</h1>
<input type=\"checkbox\" name=\"checkboxes[]\" value=\"deleted\" ".$checkDeleted." />
<label for=\"deleted\">Löschung Ebay</label>
<br />
<input type=\"hidden\" name=\"cmd\" value=\"submitinfo\" />
<input name=\"Submit\" type=\"submit\" value=\"submit\" />
</form>";
}

Ben neden burada yatıyor emin olmadan, mümkün olduğunca bu aşağı kesilmiş olması.

1 Cevap

Birazdan değiştirme sorunuzu anladım ettiyseniz

$checkboxes = $_POST['checkboxes'];

ile

$checkboxes = (isset($_POST['checkboxes'])? $_POST['checkboxes'] : array());

Ben sorununuzu çözecektir sanırım. (Ben test etmek için komut dosyasını çalıştırmak vermedi ama umarım hata ücretsiz olacak)

Tam Örnek:

<?php
error_reporting(E_ALL);

if (isset($_GET["cmd"]))
  $cmd = $_GET["cmd"]; 
    else
if (isset($_POST["cmd"]))
  $cmd = $_POST["cmd"]; 
    	else die("Invalid URL");

if (isset($_GET["pk"])) { $pk = $_GET["pk"]; }

$checkDeleted = "";
$checkNotice = "";
$checkWarrant = "";
$checkPromise = "";
$checkCompensation = "";
$checkBond = "";
$checkInjunction = "";
$checkActionpay = "";
$checkActionorder = "";
$checkCourtpayment = "";
$checkForeclosure = "";
$checkPenalty = "";

$checkboxes = (isset($_POST['checkboxes'])? $_POST['checkboxes'] : array());

if (in_array('deleted', $checkboxes)) $checkDeleted = 'checked';

$con = mysqli_connect("localhost","user","pass", "db");
if (!$con) { echo "Can't connect to MySQL Server. Errorcode: %s\n". mysqli_connect_error(); exit; }

$con->set_charset("utf8");

$getformdata = $con->query("select ARTICLE_NO, deleted from STATUS where ARTICLE_NO = '$pk'");

while ($row = mysqli_fetch_assoc($getformdata)) {
    $ARTICLE_NO = $row['ARTICLE_NO'];
    $checkDeleted = $row['deleted'];
}

if($cmd=="submitinfo") {
    if ($ARTICLE_NO == null) {
       $statusQuery = "INSERT INTO STATUS VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        if ($statusInfo = $con->prepare($statusQuery)) {
                $statusInfo->bind_param("sssssssssssss", $pk, $checkDeleted, $checkNotice, $checkWarrant, $checkPromise, $checkCompensation, $checkBond, $checkInjunction, $checkActionpay, $checkActionorder, $checkCourtpayment, $checkForeclosure, $checkPenalty);
                $statusInfo->execute();
                $statusInfo->close();
                echo $pk;
                echo $checkDeleted;
        } else {
                print_r($con->error);
        }
    } else if ($ARTICLE_NO == $pk) {
        $statusQuery = "UPDATE STATUS SET deleted = ?, notice = ?, warrant = ?, promise = ?, compensation = ?, bond = ?, injunction = ?, actionpay = ?, actionorder = ?, courtpayment = ?, foreclosure = ?,penalty = ? WHERE ARTICLE_NO = ?";
        if ($statusInfo = $con->prepare($statusQuery)) {
                $statusInfo->bind_param("sssssssssssss", $checkDeleted, $checkNotice, $checkWarrant, $checkPromise, $checkCompensation, $checkBond, $checkInjunction, $checkActionpay, $checkActionorder, $checkCourtpayment, $checkForeclosure, $checkPenalty, $pk);
                $statusInfo->execute();
                $statusInfo->close();
        } else {
                print_r($con->error);
     }  
    }
}
if($cmd=="EditStatusData") {
    echo '<link rel="stylesheet" href="style.css" type="text/css" />' . "\n";
    echo "<form name=\"statusForm\" action=\"test.php?pk=".$pk."\" method=\"post\" enctype=\"multipart/form-data\">
    		<h1>Editing information for Auction No: ".$pk."</h1>
    			<input type=\"checkbox\" name=\"checkboxes[]\" value=\"deleted\" ".$checkDeleted." />
    			<label for=\"deleted\">Löschung Ebay</label>
    			<br />
    			<input type=\"hidden\" name=\"cmd\" value=\"submitinfo\" />
    			<input name=\"Submit\" type=\"submit\" value=\"submit\" />
    	</form>";
}
?>