TABLE.PHP - 表正確顯示。我剛在這裏發佈了重要的代碼。將數組中的td值傳遞給函數類,然後插入數據庫
$ipn="192.168.196.";
echo "<form method ='post' action='class_prdsbmt.php'>";
echo "<table border='5'>";
echo "<td>";
echo "<table name='' border='3'>";
for($a1=51;$a1<68;$a1++){
for($a2=52;$a2<70;$a2++){
echo "<tr>";
echo "<td><input type='hidden' value='".$ipn.$a1."' name='td_a[]' />$ipn$a1</td>";
echo "<td><input type='hidden' value='".$ipn.$a2."' name='td_a[]' />$ipn$a2</td>";
echo "</tr>";
$a1+=2;
$a2+=1;
}
echo "</table>";
echo "</td>";
}
echo "<td><input type='submit' value='PRINT' name='btnss' /></td>";
class_prdsbmt.php
include("class_prdtrans.php");
$pcs = $_POST['td_a'];
for ($i = 0; $i < ; $i++) {
$arr=$pcs[$i];
$printval = new PrintVal($arr,"TESTING ONLY");
$crud = new CRUD_process();
}
<?php
if(isset($_POST['btnss'])){
$isSuccess=0;
$strCol = "pcip,pcname";
$strVal = "'".$printval->getIp()."','". $printval- >getPcname()."'";
$isSuccess = $crud->saveRecord("machine",$strCol,$strVal);
}else{
"NOT SAVED! GO BACK!!!";
}
?>
class_prdtrans.php
define('DB_SERVER','localhost');
define('DB_USER','user');
define('DB_PASSWORD','');
define('DB_NAME','db');
class PrintVal{
var $_ipmac;
function __construct($ipmac,$namemac){
$this->_ipmac = $ipmac;
}
function getIp(){
return $this->_ipmac;
}
}
//crud operation
class CRUD_process{
var $con;
function __construct(){
$this->con = new mysqli(DB_SERVER,DB_USER,DB_PASSWORD,DB_NAME);
}
function saveRecord($record,$columns,$values){
$result = false;
switch($record){
case "machine":
$result = $this->con->query("INSERT INTO tbl (".$columns.") VALUES(".$values.");");
break;
default:
}
return $result;
}
function getRecord($record,$values){
$result = false;
$val = explode(",",$values);
switch($record){
case "machine":
$result = $this->con->query("SELECT * FROM tbl WHERE pcip =".$val[0]." AND pcname = ".$val[1].";");
break;
default:
}
return $result;
}
}
嘗試呼應INSERT
查詢和輸出是錯誤的。第一個字段(pcip)值爲空。以下是SQL輸出。
INSERT INTO tbl (pcip,pcname) VALUES('','TESTING ONLY');
請幫我先到了一種更好的方式或簡單的方式接入的所有數組值「td_a []」從表中插入我的數據庫,一旦我按一下按鈕。
因此,做一些基本的調試以找出你在那個地方使用的變量爲什麼是空的......並且還要閱讀SQL注入以及你需要做些什麼 – CBroe
@Brian Tompsett - 湯萊恩Ok會這樣做,謝謝 – Ronix