0

以下のコードでデータを挿入していますが、挿入されていません。エコー$_REQUESTデータですべてをチェックしました出力ではすべて問題ありませんが、データは挿入されません

このコードで。フォームからデータを取得しています

$bname         =$_REQUEST['bname'];
$btype         =$_REQUEST['btype'];
$bemail        =$_REQUEST['bemail'];
$bwebsite      =$_REQUEST['bwebsite'];
$bphone        =$_REQUEST['bphone'];
$bpostal       =$_REQUEST['bpostal'];
$bcountry      =$_REQUEST['bcountry'];
$bannertype    =$_REQUEST['bannertype'];
$bgcolor       =$_REQUEST['bgcolor'];
$bheadcolor    =$_REQUEST['bheadcolor'];
$bsubheadcolor =$_REQUEST['bsubheadcolor'];
$btextcolor    =$_REQUEST['btextcolor'];

これで簡単に反響します

echo "$bname, $btype, $bemail, $bwebsite, $bphone, $bpostal, $bcountry, $bannertype,  
$bgcolor, $bheadcolor,$bsubheadcolor,$btextcolor";

しかし、挿入に関しては動作しませんエラーが発生します

include 'dbconnect.php';

$sql="insert into company (business_id, business_name, business_type, bunsiness_email,

business_website, work_phone,  postal_code, business_country,banner_type, 

select_bgcolor, select_heading1, select_heading2, select_text) values 


('NULL','".$bname."','".$btype."','".$bemail."','".$bwebsite."', '".$bphone."', 

'".$bpostal."', '".$bcountry."','".$bannertype."', '".$bgcolor."', '".$bheadcolor."', 

'".$bsubheadcolor."', '".$btextcolor."')";

mysql_query($sql) or die("An Error Occured while updating");
include 'dbclose.php';*/

これは私のテーブルの説明です

+----------------------------+---------------+------+-----+---------+-----------
-----+
| Field                      | Type          | Null | Key | Default | Extra
 |
+----------------------------+---------------+------+-----+---------+-----------
-----+
| business_id                | int(10)       | NO   | PRI | NULL    | auto_increment |
| business_name              | varchar(50)   | NO   |     | NULL    ||
| business_type              | varchar(50)   | NO   |     | NULL    |      |
| business_email             | varchar(50)   | NO   |     | NULL    |
| business_website           | varchar(50)   | NO   |     | NULL    |
| work_phone                 | varchar(20)   | NO   |     | NULL    |
| postal_code                | varchar(20)   | NO   |     | NULL    |
| business_country           | varchar(20)   | NO   |     | NULL    |
| banner_type                | varchar(50)   | NO   |     | NULL    |
| select_bgcolor             | varchar(50)   | NO   |     | NULL    |
| select_heading1            | varchar(50)   | NO   |     | NULL    |
| select_heading2            | varchar(50)   | NO   |     | NULL    |
| select_text                | varchar(50)   | NO   |     | NULL    |
4

6 に答える 6

1

NULL列に値 を挿入しようとしてbusiness_idいます。この列を null にすることはできません (主キーであるため)。

使用してみてください: (business_id 列への挿入を削除しました)

$sql="insert into company (business_name, business_type, bunsiness_email,

business_website, work_phone,  postal_code, business_country,banner_type, 

select_bgcolor, select_heading1, select_heading2, select_text) values 


('".$bname."','".$btype."','".$bemail."','".$bwebsite."', '".$bphone."', 

'".$bpostal."', '".$bcountry."','".$bannertype."', '".$bgcolor."', '".$bheadcolor."', 

'".$bsubheadcolor."', '".$btextcolor."')";
于 2013-02-11T12:49:02.617 に答える
1

bunsiness_email挿入する必要があります。列が存在しないbusiness_emailため、完全に壊れます。bunsiness_email準備されたステートメントについて学ぶことは何もありません。ここでは、多くの開始および終了の一重引用符と二重引用符を処理するシナリオがあり、準備されたステートメントにより、その処理がはるかに簡単になり、SQL インジェクションに対してより安全になります。

于 2013-02-11T12:51:35.820 に答える
0

あなたのbusiness_idは自動インクリメントの主キーであるため、クエリでnullとして送信しているため、クエリからbusiness_idを削除してエラーが発生しています

$sql="insert into company ( business_name, business_type, bunsiness_email,

business_website, work_phone,  postal_code, business_country,banner_type, 

select_bgcolor, select_heading1, select_heading2, select_text) values 


('".$bname."','".$btype."','".$bemail."','".$bwebsite."', '".$bphone."', 

'".$bpostal."', '".$bcountry."','".$bannertype."', '".$bgcolor."', '".$bheadcolor."', 

'".$bsubheadcolor."', '".$btextcolor."')";

mysql_query($sql) or die("An Error Occured while updating");
于 2013-02-11T12:48:54.683 に答える
0

は INT AUTO INCREMENT 列であるためbusiness_id、INSERT クエリでは必要ありません。

    $sql = "insert into company (
    business_name, 
    business_type, 
    business_email,
    business_website, 
    work_phone,
    postal_code,
    business_country,
    banner_type, 
    select_bgcolor, 
    select_heading1, 
    select_heading2, 
    select_text
    ) values (
        '" . $bname . "',
        '" . $btype . "',
        '" . $bemail . "',
        '" . $bwebsite . "',
        '" . $bphone . "',
        '" . $bpostal . "', 
        '" . $bcountry . "',
        '" . $bannertype . "', 
        '" . $bgcolor . "', 
        '" . $bheadcolor . "', 
        '" . $bsubheadcolor . "', 
            '" . $btextcolor . "'
    )";

クエリで NULL を渡したい場合は、引用符なしで行ってください。

于 2013-02-11T12:47:40.460 に答える
0

business_id が NULL になることはありません。これは自動インクリメント フィールドです。

$sql="insert into company (business_name, business_type, bunsiness_email,

business_website, work_phone,  postal_code, business_country,banner_type, 

select_bgcolor, select_heading1, select_heading2, select_text) values 


('".$bname."','".$btype."','".$bemail."','".$bwebsite."', '".$bphone."', 

'".$bpostal."', '".$bcountry."','".$bannertype."', '".$bgcolor."', '".$bheadcolor."', 

'".$bsubheadcolor."', '".$btextcolor."')";
于 2013-02-11T12:47:12.917 に答える
0

あなたのビジネス ID は主キーです。それは自動インクリメント値です。そのため、business_id を挿入する間、NULL として挿入することはできません。したがって、クエリは次のようになります。

$sql="insert into company (business_name, business_type, bunsiness_email,

business_website, work_phone,  postal_code, business_country,banner_type, 

select_bgcolor, select_heading1, select_heading2, select_text) values 


('".$bname."','".$btype."','".$bemail."','".$bwebsite."', '".$bphone."', 

'".$bpostal."', '".$bcountry."','".$bannertype."', '".$bgcolor."', '".$bheadcolor."', 

'".$bsubheadcolor."', '".$btextcolor."')";
于 2013-02-11T13:48:08.940 に答える