dongtanliefang8765 2015-04-05 20:09
浏览 22
已采纳

按名称更新用户输入

I'm trying to make a script that updates a row, from the user input row (2 different rows).

Lets say, the table has 'timeleft', and 'user'. The user will type in the 'user', and the time, so the 'timeleft' gets updated.

I've tried doing it, but I can't as I just starded learning PHP like for a week now.

$db = mysql_connect(dbhost, dbuser,dbpass);
if($db){
    mysql_select_db(dbname);

    print('
        <form action="" method="POST">
                <div class="InputLine"><span class="CTBanForm">Nombre: </span><input type="text" name="IntroducedName" placeholder="Nombre..."></div>
                <div class="InputLine"><span class="CTBanForm">Tiempo: </span><input type="text" name="IntroducedTime" placeholder="Tiempo en numeros..."></div>
                <input type="submit" value="Borrar" name="PerformDelete">
        </form>
        ');
    if(empty($_POST['IntroducedName'])){
        echo '<div id="IDEmpty">Introduzca un nombre porfavor...</div>';
    }else if(empty($_POST['IntroducedTime'])){
        echo '<div id="IDEmpty">Introduzca un numero porfavor...</div>';
    }else{

        /* SQL STATEMENTS! */
        $IntroducedNameSQLSelect = 'SELECT '.$_POST['IntroducedName'].'" FROM CTBan_Log';

        $IntroducedTimeSQLUpdate = 'UPDATE '.$_POST['IntroducedTime'].'" FROM CTBan_Log WHERE timeleft=?';
        /* END SQL STATEMENTS! */
        if(!empty($_POST['IntroducedName'])){

            mysql_query($IntroducedNameSQLSelect);
            if(mysql_query($delete)){
                echo '<div id="Hecho"> Hecho. </div>';
            }
            else{
                echo '<div id="NoHecho"> Error, no se pudo realizar. </div>';
            }
        }
        else if(!empty($_POST['IntroducedTime'])){

            mysql_query($IntroducedTimeSQLUpdate);
            if(mysql_query($delete)){
                echo '<div id="Hecho"> Hecho. </div>';
            }
            else{
                echo '<div id="NoHecho"> Error, no se pudo realizar. </div>';
            }
        }
    }
    mysql_close($db);
}
  • 写回答

2条回答 默认 最新

  • dqlk31541 2015-04-05 21:48
    关注

    I've found the solution:

    I fixed the SQL statement, thanks to hr.anvari. I used this:

    'UPDATE CTBan_Log SET timeleft="'.$time.'" WHERE perp_name="'.$_POST['IntroducedName'].'"'
    
    $time = mysql_real_escape_string($_POST['IntroducedTime']); // Had to use this to get numbers passed to Mysql.
    

    instead of this(wth :P):

        /* SQL STATEMENTS! */
        $IntroducedNameSQLSelect = 'SELECT '.$_POST['IntroducedName'].'" FROM CTBan_Log';
    
        $IntroducedTimeSQLUpdate = 'UPDATE '.$_POST['IntroducedTime'].'" FROM CTBan_Log WHERE timeleft=?';
        /* END SQL STATEMENTS! */
    

    Thats all. I need to use mysqli tho. Thanks both Fredy, and hr.anvari(SQL).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)