ユーザー テーブルにフィールドが挿入されないという小さな問題があります。次のように2つのテーブルがあります。
ユーザー - id、gamerid、メール、パスワード、国、country_code 国 - country_id、country、country_code
これで、gamerid、email、password、国選択 (php を使用して国テーブルから取得) で構成されるサインアップ フォームができました。
私の問題は、フォームを送信するときに、クエリを実行して、ユーザーが選択したものと一致するテーブルから国コードを取得し、これらのフィールドをユーザー テーブルに挿入することです。country_code を除いて、すべてのデータが正しく挿入されています。
これがhtml選択セクションの私のコードです:
<select name = "country_create" style = "height: 25px; width: 180px;">
<option value="0" selected="selected" class = "signup_form_country_select_class">Select your country</option>
<?php
include "config.php";
$connection = mysql_connect($host, $username, $password) or die(mysql_error());
mysql_select_db($dbname, $connection) or die(mysql_error());
$result = mysql_query('SELECT country FROM countries');
while($row = mysql_fetch_array($result))
{
echo '<option value="'.$row['country'].'">'.$row['country'].'</option>';
}
?>
</select>
そして、ここに登録スクリプトのphpがあります:
$connection = mysql_connect($host, $username, $password) or die(mysql_error());
mysql_select_db($dbname, $connection) or die(mysql_error());
// INPUT CLEANING FUNCTION
function clean($str)
{
$cleaned = mysql_real_escape_string(strip_tags($str));
return $cleaned;
}
$gamerid = clean($_POST['gamerid_create']);
$email = clean($_POST['email_create']);
$password = clean($_POST['password_create']);
$country = ($_POST['country_create']);
$cc_qry = "SELECT country_code FROM countries WHERE country = '$country'";
$country_code = mysql_query($cc_qry);
$insert = "insert into users(gamerid,email,password,country,country_code) values('$gamerid','$email','$password','$country','$country_code')";
mysql_query($insert, $connection);
よろしくお願いします!