duanjiao6735 2014-05-24 16:21
浏览 66
已采纳

如何添加提交按钮的操作

sry for my amateur question. I wrote this code for get text from input and add in to database:

    <html xmlns="http://www.w3.org/1999/xhtml" lang="fa">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>My Title</title>
    </head>
    <body>
        <form action=""  method="POST">
            <label for="name" id="app_name_label"  >name</label>
            <input type="text" name="name" id="name_textfield">

            <input type="submit" name"Submit" value="send" >
        </form>
<?php

if(isset($_POST['Submit']))
{
        include_once("config.php");
    $con = mysql_connect($db_host,$db_user,$db_pass)
    or die(mysql_error());

    $selected=mysql_select_db($db_name, $con) 
    or die(mysql_error());

    if($selected){
    $name = $_REQUEST['name'];

    $ins = "INSERT INTO infos (app_name )  VALUES ('$name')";
    $saved=mysql_query($ins );
    if($saved)
    {
        echo "Saved!!";
    }
    else
    {
        echo "Don't Saved!!";
    }

    }
    mysql_close($con);
}


?>

    </body>
</html>

My database doesn't have any problem But when i run it, nothing write to my database! :( what should i do? I think problem is in isset($_POST['Submit']).

  • 写回答

2条回答 默认 最新

  • dtyz76562 2014-05-24 16:31
    关注

    If everything else is ok, then I am afraid you have a simple typo in your code that is causing you the problem.

     <input type="submit" name"Submit" value="send" >
    

    should be

     <input type="submit" name="Submit" value="send" >
    

    You have missed the equal to sign in your code after name. :)

    On a side note, you should not use $_REQUEST['name'] but instead use $_POST['name'] when the form method is post. It is more secure. And secondly, try to use mysqli database extension instead of using mysql. mysql extension is deprecated from PHP 5.5 onward.

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

报告相同问题?

悬赏问题

  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据