【发布时间】:2012-06-27 01:02:49
【问题描述】:
我是 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"));
【问题讨论】:
标签: php mysql database phpmyadmin