हाय मैं तैयार बयानों उपयोग करने के लिए एसक्यूएल इंजेक्शन आदि से बचने के लिए उचित तरीके से जानने के लिए कोशिश कर रहा हूँपीएचपी अद्यतन तैयार बयान
जब मैं स्क्रिप्ट मैं अपने स्क्रिप्ट 0 पंक्तियाँ सम्मिलित किए कहने से एक संदेश प्राप्त निष्पादित, मैं उम्मीद यह कहने के लिए 1 पंक्तियां डालें और निश्चित रूप से तालिका को अपडेट करें। मैं अपने तैयार कथन पर पूरी तरह से यकीन नहीं कर रहा हूं, क्योंकि मैंने कुछ शोध किया है और मेरा मतलब है कि यह उदाहरण से उदाहरण के लिए भिन्न होता है।
जब मैं अपनी तालिका अपडेट कर रहा हूं तो मुझे सभी फ़ील्ड घोषित करने की आवश्यकता है या क्या यह सिर्फ एक फ़ील्ड अपडेट करना ठीक है ??
कोई भी जानकारी बहुत उपयोगी होगी।
index.php
<div id="status"></div>
<div id="maincontent">
<?php //get data from database.
require("classes/class.Scripts.inc");
$insert = new Scripts();
$insert->read();
$insert->update();?>
<form action="index2.php" enctype="multipart/form-data" method="post" name="update" id="update">
<textarea name="content" id="content" class="detail" spellcheck="true" placeholder="Insert article here"></textarea>
<input type="submit" id="update" name="update" value="update" />
</div>
वर्गों/class.Scripts.inc
public function update() {
if (isset($_POST['update'])) {
$stmt = $this->mysqli->prepare("UPDATE datadump SET content=? WHERE id=?");
$id = 1;
/* Bind our params */
$stmt->bind_param('is', $id, $content);
/* Set our params */
$content = isset($_POST['content']) ? $this->mysqli->real_escape_string($_POST['content']) : '';
/* Execute the prepared Statement */
$stmt->execute();
printf("%d Row inserted.\n", $stmt->affected_rows);
}
}
क्या आपने यह देखने के लिए प्रयास किया कि क्या होता है? –
real_escape_string() तैयार कथन के लिए आवश्यक नहीं है – Danijel
अपने एसक्यूएल में, पहला पैरामीटर सामग्री है और दूसरा आईडी है। जब आप bind_param को कॉल करते हैं, तो आपने ऑर्डर को उलट दिया है - bind_param – andrewsi