我是 php 和 mySQL 的初学者,我目前正在使用 Dreamweaver 的 GUI 来帮助我学习。
我正在尝试创建一个成员注册表单以将用户注册到数据库中。我的目标是从用户的名字和姓氏生成用户名。例如:名字:John,姓氏:Smith。用户名将自动生成为 john.smith(忽略大写)
我阅读了有关在 php 中进行连接的信息并提出了代码:
GetSQLValueString($_POST['firstname'], "text").GetSQLValueString('.'.$_POST['lastname'], "text"),
但是,当我检查 mySQL 中存储的数据时,它会返回 firstname'.lastname。即约翰史密斯。(注意名字后面的多余撇号)
这是我的来源: 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"));