我有一张FORM,效果很好。但我想转换用户输入如下:
textbox:“用户在这里写东西。” - >单击“提交”,文本现在已添加到表中的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>
答案 0 :(得分:0)
喜欢这样:
if(isset($_POST['brukernavn'])){
echo "<a href='update.php?oppdaterID=".$_POST['brukernavn']."'>your link here</a>";
}
答案 1 :(得分:0)
尝试使用javascript
$(document).ready(function() {
$("#mybutton").click(function(){
var val = $('#brukernavn').val();
$('#mydiv').html('<a href="update.php?oppdaterID='+val+'"> USERS INPUT</a>');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<td nowrap="nowrap" align="right">*Brukernavn:</td>
<td><input type="text" name="brukernavn" id="brukernavn" value="" size="24" /></td>
<td><input type="button" id="mybutton" name="click" value="click" /></td>
</tr>
<div id="mydiv"></div>
答案 2 :(得分:0)
如果您使用的是POST方法,则可以使用 $ _ POST [&#39; brukernavn&#39;] 在链接中显示用户的输入:
<a href="update.php?oppdaterID=<?php echo $row_persondata2['id']; ?>"><?php echo $_POST['brukernavn']; ?></a>
答案 3 :(得分:0)
你可以使用这样的javascript函数:
<script type="text/javascript">
function buildUrl() {
var str;
var myInput=document.getElementById("brukernavn");
str = myInput.value;
// and here you can build your URL using the variable str
}
</script>
不要忘记添加 onclick =&#34; buildUrl();&#34; 在提交按钮中。并在输入文本中添加一个id属性,以便识别:
<td><input type="text" name="brukernavn" id="brukernavn" value="" size="24" /></td>