duaedf6509 2016-03-18 13:35
浏览 72

PHP Wamp服务器[关闭]

Hey I have a database that contains information about different countries. I also have a html page where you can submit information about countries. Can someone help me to write a code that says that the information has been stored in the database instead of it just redirecting to a blank page?

Here is my html page where you submit information:

<!DOCTYPE HTML>
<html>
<head>
    <meta charset="UTF-8">
        <title>Sett inn land</title>
</head>
<body>
    <form action="geoinn.php" method="get">
        Land: <input type="text" name="navn"> <br>
        Hovedstad: <input type="text" name="hovedstad"> <br>
        Areal: <input type="text" name="areal"> <br>
        Folketall: <input type="text" name="folketall"> <br>

        <input type="submit" value="Legg inn informasjon">  
    </form>
</body>
</html>

And here is the page that you are redirected to when you click submit on the other page. This is the page where I want to have a code saying either that "The information has been stored in our database" or that it has not:

    <?php
    $tjener = "localhost";
    $brukernavn = "root";
    $passord ="";
    $database ="Geografi";
    $kobling = mysqli_connect($tjener,$brukernavn,$passord,$database);
    $kobling->set_charset("utf8");
?>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="UTF-8">
    <title>Geografi</title>
</head>
<body>
    <?php
    $land = $_GET["navn"];
    $hovedstad = $_GET["hovedstad"];
    $areal = $_GET["areal"];
    $folketall = $_GET["folketall"];
    $sql ="INSERT INTO land (navn,hovedstad, areal, folketall)       VALUES('$land','$hovedstad','$areal', '$folketall')";
    mysqli_query($kobling, $sql);
    mysqli_close($kobling);
    ?>
</body>
</html>
  • 写回答

1条回答 默认 最新

  • douyu7210 2016-03-18 13:45
    关注

    Add some output and you will get some output. The blank page you get is the page that does the updates. You add the basic HTML page tags but do not output anything inside the <body>

    $sql ="INSERT INTO land 
                 (navn,hovedstad, areal, folketall)       
           VALUES('$land','$hovedstad','$areal', '$folketall')";
    
    $result = mysqli_query($kobling, $sql);
    if ( $result === FALSE ) {
       echo '<p>FAILED MESSAGE</p>';
    } else {
       echo '<p>SUCCESS MESSAGE</p>';
    }
    echo "<p>Land = $land</p>";
    echo "<p>hovedstad = $hovedstad</p>";
    // and so on
    
    mysqli_close($kobling);
    

    As Jay says,

    Your script is at risk for SQL Injection Attacks. Learn about prepared statements for MySQLi.

    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大