我一直在試圖插入一行到我的表在我的數據庫,我不可能完成插入查詢也所以我不知道是什麼問題插入進不插入PHP/mysqli的
我不能讓任何錯誤我表:
CREATE TABLE IF NOT EXISTS `general_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`First Name` varchar(30) NOT NULL,
`Last Name` varchar(30) NOT NULL,
`University` varchar(80) NOT NULL,
`Major` varchar(50) NOT NULL,
`Current_Level` varchar(50) NOT NULL,
`Date_Joined` varchar(15) NOT NULL,
`Current_Team` varchar(50) NOT NULL,
`added_by` int(11) NOT NULL,
`Phone` varchar(25) NOT NULL,
`Email` varchar(50) NOT NULL,
PRIMARY KEY (`id`),
KEY `member_id` (`added_by`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
我的html:
<body>
<div class="memberInfo">
<h1>Add A Member</h1>
<form id=add_member name="add_member" method="post" action="addmember.php" >
<fieldset>
<legend>Member Details</legend>
<ol>
<li>
<label for=first_name>First Name</label>
<input id=first_name name=first_name type=text placeholder="First Name" required autofocus>
</li>
<li>
<label for=last_name>Last Name</label>
<input id=last_name name=last_name type=text placeholder="Last Name" required autofocus>
</li>
<li>
<label for=email>Email</label>
<input id=email name=email type=email placeholder="[email protected]" required>
</li>
<li>
<label for=university>University</label>
<input id=university name=university type=text placeholder="Eg.Istanbul University" required>
</li>
<li>
<label for=major>Major</label>
<input id=major name=major type=text placeholder="Eg. Business" >
</li>
<li>
<label for=phone>Phone</label>
<input id=phone name=phone type=tel placeholder="Eg. +447500000000" >
</li>
<li>
<label for=current_stage>Current Stage</label>
<input id=current_stage name=current_stage type=text placeholder="Eg.Newbie" required>
</li>
<li>
<label for=current_team>Current Team</label>
<input id=current_team name=current_team type=text placeholder="Eg.External Relations">
</li>
<li>
<label for=date_joined>Date Joined</label>
<input id=date_joined name=date_joined type=text placeholder="Eg. 08/24/2012" required>
</li>
</ol>
</fieldset>
<fieldset>
<button type=submit >Save Member</button>
</fieldset>
</form>
</div>
</body>
我如何檢索$ _SESSION [ 'user_ID的']在我登錄的PHP
if($stmt->num_rows==1){
echo $myusername . " ";
session_register("myusername");
session_register("mypassword");
$_SESSION['user_id']=$user_id;
$_SESSION['username'] = $myusername;
session_write_close();
header("location:login_success.php");
}
addmember.php:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
if(isset($_SESSION['user_id'])){
$mysqli = new mysqli('localhost', 'root', 'password', 'aiesec');
if(mysqli_connect_errno()) {
echo "Connection Failed: " . mysqli_connect_errno();
exit();
}
$stmt = $mysqli -> prepare("INSERT INTO general_info (First Name, Last Name, University, Major, Current_Level, Date_Joined, Current_Team, added_by, Phone, Email) VALUES (?,?,?,?,?,?,?,?,?,?)")
$stmt -> bind_param("sssssssiss", $First_Name, $Last_Name,$University,$Major, $Current_Level, $Date_Joined, $Current_Team, $added_by, $Phone, $Email);
$First_Name=$_POST['first_name'];
$Last_Name=$_POST['last_name'];
$University=$_POST['university'];
$Major=$_POST['major'];
$Current_Level=$_POST['current_stage'];
$Date_Joined=$_POST['date_joined'];
$Current_Team=$_POST['current_team'];
$added_by=$_SESSION['user_id'];
$Phone=$_POST['phone'];
$Email=$_POST['email'];
$stmt -> execute();
printf("%d Row inserted.\n", $stmt->affected_rows);
printf("Errormessage: %s\n", $stmt->error);
$stmt->close();
$mysqli->close();
}
else{
printf("Nope\n");
header("location:main_login.php");
}
?>
如果我刪除所有代碼,並把回聲看$_SESSION['user_id']
輸出1
所以如果聲明的作品。
我猜問題行可能是$added_by=$_SESSION['user_id'];
,但我不確定。
如何解決插入問題或如何查看錯誤?
在此先感謝您的任何建議。
-----編輯解決方案-------任何時候都
我已經改變了First Name
和Last Name
到First_Name
的 最簡單的錯誤,並Last_Name
我忘了分號結束把分號的腳本後,行 $stmt = $mysqli -> prepare("INSERT INTO general_info (First Name, Last Name, University, Major, Current_Level, Date_Joined, Current_Team, added_by, Phone, Email) VALUES (?,?,?,?,?,?,?,?,?,?)")
添加的行到數據庫
媽的,剛纔看到這後我發佈。討厭互聯網慢。 +1 – Fluffeh 2012-07-09 06:43:14
更改變量仍然沒有錯誤 – 2012-07-09 06:48:01
您需要將此行$ stmt - > bind_param(「sssssssiss」,$名,$姓,$大學,$重大,$ Current_Level,$ Date_Joined,$ Current_Team,$ added_by,$ Phone,$ Email); 您設置了所有參數 – 2012-07-09 06:50:18