结果不会正常显示

时间:2014-08-24 08:36:45

标签: php mysql

<?php
$connection = @mysql_connect ("localhost","root","");
@mysql_select_db ("streamurl" , $connection) or die ('Error in DB Connection');
$select_all= "SELECT * FROM url";
$array = mysql_query($select_all, $connection);
    if(isset($_POST['btn'])){
$mysql_query_rename = "UPDATE url SET ST_NAME='$_POST[name]', URL='$_POST[url]', ID='$_POST[id]'  WHERE ID='$_POST[hidden2]' AND ST_NAME='$_POST[hidden3]' AND URL='$_POST[hidden1]' ";  
    if(mysql_query($mysql_query_rename, $connection)){
        echo 'Changes were applied Successfully';
    } else {
        echo 'Changes Could not be Applied';
    };
    };
while ($show = mysql_fetch_array($array)){
    echo "<form action=deletestation.php method=post>";
    echo "<input type=text name=id value=$show[ID] >";
    echo "<input type=text name=name value=$show[ST_NAME] >";
    echo "<input type=text name=url value=$show[URL] >";
    echo "<input name=hidden1 type=hidden value=$show[URL] >";
    echo "<input name=hidden2 type=hidden value=$show[ID] >";
    echo "<input name=hidden3 type=hidden value=$show[ST_NAME] >";
    echo "<input name=btn type=submit value=UPDATE>";   
    echo "</form>";
};
mysql_close($connection);
?>

首先是PHP和MYSQL的新手

上面的代码用于更新mysql数据库中的表,我已经在文本框中回显了结果。表中只有很少的信息(站名,ID和URL)。问题是只有第一个结果是可更新的,其他结果无法更新。除第一个结果外,另一个不会显示完整的电台名称(ST_NAME)。

请在我的代码中指出错误。

1 个答案:

答案 0 :(得分:0)

<?php
$connection = mysql_connect ("localhost","Sithira","1sithiraM");
mysql_select_db ("streamurl" , $connection) or die ('Error in DB Connection');
$select_all= "SELECT * FROM url";
$array = mysql_query($select_all, $connection);
    if(isset($_POST['btn'])){
$mysql_query_rename = "UPDATE url SET ST_NAME='$_POST[name]', URL='$_POST[url]', ID='$_POST[id]'  WHERE ID='$_POST[hidden]' ";  
    if(mysql_query($mysql_query_rename, $connection)){
        echo 'Changes were applied succesfully';
    } else {
        echo 'Changes Could not be Applied';
    };
    };
while ($show = mysql_fetch_array($array)){
    echo "<form action=deletestation.php method=post >";
    echo "<input type=text name=id value=$show[ID] >";
    echo "<input type=text name=name value=$show[ST_NAME] >";
    echo "<input type=text name=url value=$show[URL] >";
    echo "<input name=hidden type=hidden value=$show[ID] >";
    echo "<input name=btn type=submit value=UPDATE>";   
    echo "</form>";
};

mysql_close($connection);
?>

最后我得到了它的工作:)