【发布时间】:2014-12-31 05:57:37
【问题描述】:
我有一个 FORM,效果很好。但我想像这样转换用户输入:
文本框:“用户在这里写了一些东西。” -> 单击提交,文本现在已添加到表中的 SQL 数据库中,但现在附加了一个 HREF 链接。输出”user writes something here.
让我告诉你:
<td nowrap="nowrap" align="right">*Brukernavn:</td>
<td><input type="text" name="brukernavn" value="" size="24" /></td>
</tr>
当用户点击提交时,我希望文本是这样的:
<a href="update.php?oppdaterID=<?php echo $row_persondata2['id']; ?>"> "USERS INPUT"
这里是完整的代码:
<?php require_once('Connections/pc.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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 pcbua (time, `navn`, brukernavn, `Type PC`, ServiceTAG, Kommentar, bruker, gruppe) VALUES (NOW(), %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['navn'], "text"),
GetSQLValueString($_POST['brukernavn'], "text"),
GetSQLValueString($_POST['Type_PC'], "text"),
GetSQLValueString($_POST['ServiceTAG'], "text"),
GetSQLValueString($_POST['Kommentar'], "text"),
GetSQLValueString($_POST['bruker'], "text"),
GetSQLValueString($_POST['gruppe'], "text"));
mysql_select_db($database_pc, $pc);
$Result1 = mysql_query($insertSQL, $pc) or die(mysql_error());
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<body>
<p>Felt med * må fylles ut!</p>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table align="left">
<tr valign="baseline">
<td nowrap="nowrap" align="right">*Navn:</td>
<td><input type="text" name="navn" value="" size="24" />
</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">*Brukernavn:</td>
<td><input type="text" name="brukernavn" value="" size="24" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">*PC-Modell:</td>
<td><select name="Type_PC">
<option value="" <?php if (!(strcmp("", 1))) {echo "selected=\"selected\"";} ?>></option>
<option value="Surface Pro 3" <?php if (!(strcmp("Surface Pro 3", 1))) {echo "selected=\"selected\"";} ?>>Surface Pro 3</option>
<option value="Lenovo 530W" <?php if (!(strcmp("Lenovo 530W", 1))) {echo "selected=\"selected\"";} ?>>Lenovo 530W</option>
<option value="Lenovo X220" <?php if (!(strcmp("Lenovo X220", 1))) {echo "selected=\"selected\"";} ?>>Lenovo X220</option>
<option value="MAC" <?php if (!(strcmp("MAC", 1))) {echo "selected=\"selected\"";} ?>>MAC</option>
</select></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">*Serienummer:</td>
<td><input type="text" name="ServiceTAG" value="" size="24" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">*Gruppe:</td>
<td><input type="text" name="gruppe" value="" size="24" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Kommentar</td>
<td><input type="text" name="Kommentar" size="24" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">*Bruker</td>
<td><select name="bruker">
<option value="<?php global $current_user;
get_currentuserinfo();
echo '' . $current_user->user_login . "\n";?>" <?php if (!(strcmp("test", "ikke denne"))) {echo "selected=\"selected\"";} ?>>AutoMode</option>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Tilknytt bruker" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p>
<body>
</body>
</html>
【问题讨论】:
-
这发生在哪里,提交后在服务器上,或者使用 JavaScript 的客户端(如果是客户端,那么您需要向我们展示相关的 HTML,而不是服务器端的 php )?
-
我不确定你的意思。这里没有javascript。贴出整个代码
标签: php html forms hyperlink href