我有一个包含动态创建的 dorpdown 列表的 html 表单。下拉列表包含存储在我的 MySQL 数据库中的新闻通讯的名称。我想要下拉列表做的是:当我选择一个时事通讯时,另一个 php 脚本将激活,它将从我的数据库中的时事通讯中获取数据并将其写入 .txt 文件。我目前拥有的代码是:
下拉列表:
<?php
    echo "<select id=\"NieuwsbriefSelect\" name=\"show\">"; 
    echo "<option size =30 selected>Select</option>";
    if(mysql_num_rows($sql_result)) 
    { 
    while($row = mysql_fetch_assoc($sql_result)) 
    { 
    echo "<option value=\"$row[Titel]\">$row[Titel]</option>"; 
    } 
    } 
    else {
    echo "<option>No Names Present</option>";  
    } 
?>
和写脚本:
<?php
$title = $_REQUEST["show"];
mysql_connect('localhost','root','root'); 
mysql_select_db('NAW') or die (mysql_error()); 
$strSQL = "SELECT Content from NAW.Mail where Titel = '$title' ";
$sql_result = mysql_query($strSQL); 
$row = mysql_fetch_assoc($sql_result);  
$file = 'nieuwsbrief.txt';
$current = $row["Content"];
file_put_contents($file, $current);
?>
我不希望页面重定向到写入脚本,而只是执行它(我希望你得到这个^^)。这可以使用 HTML onChange 事件还是我必须使用 javascript?任何帮助都会很棒,如果您对我的代码有任何疑问,请在评论中提问!
笔记!
我知道我不应该使用 Mysql_* 并且我很容易受到 sql 注入的影响,但这不是重点。