私はphpとmySQLの初心者であり、現在GUIにdreamweaverを使用して学習を支援しています。
ユーザーをデータベースに登録するための会員登録フォームを作成しようとしています。私が目指しているのは、ユーザーの名前と名前からユーザー名を生成することです。例:名:ジョン、姓:スミス。ユーザー名はjohn.smithとして自動的に生成されます(大文字は無視されます)
私はphpでの連結について読み、コードを思いつきました:
GetSQLValueString($_POST['firstname'], "text").GetSQLValueString('.'.$_POST['lastname'], "text"),
ただし、mySQLに保存されているデータを確認すると、firstname'.lastnameが返されます。すなわちjohn'.smith。(名に続く余分なアポストロフィに注意してください)
これは私の情報源でした:http: //forums.phpfreaks.com/index.php? topic = 294444.0、元のポスターは、dreamweaverが使用するコードを変更したと述べています。しかし、どちらを変更すればよいかわかりません。
これまでの私の既存のコードについては、以下を参照してください。
<?php require_once('../Connections/connSQL.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{ if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO member (m_firstname, m_lastname, m_username, m_password, m_workphone, m_address) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['firstname'], "text"),
GetSQLValueString($_POST['lastname'], "text"),
GetSQLValueString($_POST['firstname'], "text").GetSQLValueString(' .'.$_POST['lastname'], "text"),
GetSQLValueString($_POST['password'], "text"),
GetSQLValueString($_POST['passwordcheck'], "text"),
GetSQLValueString($_POST['address'], "text"));