FORM输入文本,将文本输出为特定链接


FORM input text to output text as specific link

我有一个FORM,它工作得很好。但我想把用户的输入转换成这样:

textbox:"user在这里写东西。"->单击提交,文本现在被添加到表中的SQL数据库中,但现在有一个HREF链接。输出"user在那里写东西。

让我给你看看:

  <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">&nbsp;</td>
      <td><input type="submit" value="Tilknytt bruker" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<p>
<body>
</body>
</html>

可能是这样的:

if(isset($_POST['brukernavn'])){
echo "<a href='update.php?oppdaterID=".$_POST['brukernavn']."'>your link here</a>";
}

如果您使用POST方法,您可以使用$_POST['brukenavn']在链接内显示用户的输入,如下所示:

<a href="update.php?oppdaterID=<?php echo $row_persondata2['id']; ?>"><?php echo $_POST['brukernavn']; ?></a>

尝试使用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>

您可以使用这样的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="buildUrl();"在您的提交按钮中。并在输入文本中添加一个id属性,以便识别:

<td><input type="text" name="brukernavn" id="brukernavn" value="" size="24" /></td>