php pdo for crud pop 練習寫法 問題

嗨,大家好,在學習oop寫法時,在insert的部分,一直無法新增到資料庫內,不知出了什麼問題,可以麻煩高手幫忙看是出了什麼問題呢?
在網頁使用echo顯示值時,都有出現,可是就一直沒傳過去,停在create.php頁面。
小妹在此謝謝了:)

這是我的create.php 顯示表單。

<!DOCTYPE html>
<html lang=\"en\">
<head>
<title></title>
<meta charset=\"UTF-8\">
</head>
<body>
<?php
$current_date = date ( 'Y' ) . '-' . date ( 'm' ) . '-' . date ( 'd' );
date_default_timezone_set ( \"Asia/Taipei\" );
$current_time = date ( \"H:i:s\" );

function __autoload($class) {
include_once($class. \".php\");
}

$obj = new oop_db_conn;

if(isset($_REQUEST['send'])) {
extract($_REQUEST);
if($obj->insertData($current_date,$current_time,$name,$phone,$email,$message,\"message_txt\")){
echo \"herehere\";
header(\"location:read.php?status_insert=success\");
}
}
echo $current_date.$current_time.$name.$phone.$email.$message;
echo \"
<div style='text-align:center;'>
<a href='read.php'>Home</a>
</div>
<p>
<form action='create.php' method='post'>
<table border='1' align='center'>
<tr>
<th>Date</th>
<td><input type='text' name='current_date' value='$current_date' readonly='readonly'></td>
<th>Time</th>
<td><input type='text' name='current_time' value='$current_time' readonly='readonly'></td>
</tr>
<tr>
<th>Name</th>
<td><input type='text' name='name' value='$name' id='name'></td>
<th>Phone</th>
<td><input type='text' name='phone' value='$phone' id='phone'></td>
</tr>
<tr>
<th>Email</th>
<td><input type='email' name='email' value='$email' id='email'></td>
</tr>
<tr>
<th>我要留言</th>
<td colspan='3'>
<input type='text' name='message' value='$message' id='message'></input>
</td>
</tr>
<tr>
<td colspan='4' align='center'>
<input type='submit' value='send' name='send' id='send'>
<input type='reset' value='Clean'>
<input type='button' value='Return' onclick='javascript:history.back(1);'/>
</td>
</tr>
<tr>
<td><a href='read.php'>Read_Message</a></td>
</tr>
</table>
</form>
\";
?>
</body>
</html
將變數傳至 oop_db_conn 其中的function中(insert)


public function insertData($current_date,$current_time,$name,$phone,$email,$message,$table){
$sql = "INSERT INTO $table SET current_date=:current_date,current_time=:current_time,name=:name";
$q = $this->conn->prepare($sql);
$q->execute(array(':current_date'=>$current_date,':current_time'=>$current_time,':name'=>$name,':phone'=>$phone,
':email'=>$email,':message'=>$message));
return true;
}
}
[code]


評論

Sign In or Register to comment.