このコードは本当に私を混乱させました。
私はそれを実行した第1および第2の時間、それは完全に働いたが、その後、それはデータベースに2つのテーブルに挿入
を動作を停止し、私はそれを説明してみましょう:
私は2つのテーブルで動作します。
最初のテーブル私は、現在の日付、現在の時刻、およびユーザーがセッションから取得したIDをIDに挿入します。 私はそれがうまく動作すると信じています。
私の問題は2番目の表にあります。私が得るエラーは、2番目の挿入後に「印刷」に入力したエラーです。
これは私のコードです:
session_start();
//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['con_id'])) {
header("location: login.html");
exit();
}
$DB_USER ='root';
$DB_PASSWORD='';
$DB_DATABASE='';
$con= mysql_connect($DB_HOST ,$DB_USER , $DB_PASSWORD);
if (!$con) {
die('Failed to connect to server :'.mysql_error());
}
$db=mysql_select_db($DB_DATABASE);
if (!$db) {
die("unable to select database");
}
//first table
$qry="insert into shipment values('',NOW(),CURTIME(),'".$_SESSION['con_id']."');";
$resultop=mysql_query($qry);
//to take the id frome last insert because i need it in the second insert
$SNo=mysql_insert_id();
if ($resultop) {
$options=$_POST['op'];//this is the name of the check boxe's
if (empty($options)) {
header("location: manage_itemsE.php");}
// this is the second table .. my reaaal problem
$qun=$_POST['Quantit'];
$size =count($options);
for ($i =0; $i<$size; $i++) {
$qqry="insert into shipmentquantity values('".$options[$i]."','".$SNo."','".$qun[$i]."');"; // $options is array of the id's which i took from the checkbox's in the html ... $qun is array of the values i took form html ... i sure this is right ;)
$resultqun=mysql_query($qqry);
}
if ($resultqun) {
header("location: shipment_order.php");
}
else print "error in the Quantity";
}
else print "error in the shipmet";
ありがとうございました...私はこれを行いました...重複したエントリ '3'キー 'PRIMARY'はデータベースのエラーを意味しますか? – proG
これは、プライマリキーに3を挿入しようとしていますが、その値はすでに存在しています。 – nnichols
ありがとうございました。本当に素晴らしいです...!私はPDO – proG