doublestar2014 2017-11-14 15:01
浏览 46
已采纳

PHP网站表单到数据库不起作用

I've currently made an php form on my website that sends the information to my database, but when someone uses it it only posts two of the 4 input fields to the database, see the image i linked below.

It's an refund site by the way written in Norwegian so, please use Google Translate if needed :D

Here's my refund.php:

    <html>

<head>
  <link type="text/css" media="all" href="https://bootswatch.com/4/lumen/bootstrap.min.css" rel="stylesheet" />

 <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
    <meta charset="utf-8" />
    <title>NattLAN</title>
    <meta name="author" content="ukieweb" />
    <meta name="keywords" content="soon, css3, template, html5 template" />
    <meta name="description" content="Balk - Page Template" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <!-- Favicons -->
    <link rel="apple-touch-icon" sizes="144x144" href="assets/img/favicons/apple-touch-icon-144x144.png" />
    <link rel="apple-touch-icon" sizes="114x114" href="assets/img/favicons/apple-touch-icon-114x114.png" />
    <link rel="apple-touch-icon" sizes="72x72" href="assets/img/favicons/apple-touch-icon-72x72.png" />
    <link rel="apple-touch-icon" href="assets/img/favicons/apple-touch-icon.png" />
    <link rel="shortcut icon" href="assets/img/favicons/favicon.png" />
    <!-- Google Fonts -->
    <link href='http://fonts.googleapis.com/css?family=Exo+2:400,100,100italic,200,200italic,300,300italic,400italic,500,500italic,600,600italic,700,700italic,800,800italic,900,900italic' rel='stylesheet' type='text/css'>
<style>
body {
    background-color: #F0F0F0;
}
</style>
</head>

<body>
<!DOCTYPE html>
<p align="center"><img src="http://24.media.tumblr.com/0128a30614276768bf956ad868604b5d/tumblr_n6zhprHRGv1qgefibo1_400.gif"></p>
<p>&nbsp;</p>
<h3 align="center" color="black"> Refunderingsskjema</h3>
<form action="send.php" method="post">
<p align="center">Navn på deltaker:<br></p>
  <p align="center"><input type="text" name="u_deltaker" required><br></p>

<p align="center">Navn på betaler:<br></p>
  <p align="center"><input type="text" name="u_payer" required><br></p>

<p align="center">Telefonnummer:<br></p>
  <p align="center"><input type="text" name="u_phone" required><br></p>

<p align="center">Kontonummer:<br></p>
  <p align="center"><input type="text" name="u_konto" required><br></p>
<p align="center"><input class="btn btn-success" type="submit" value="Send"><br></p>
</form>
<p align="center"><a href="help.php">Hjelp! Hva betyr alt dette ovenfor? KLIKK HER!</a></p>
</body>
</html>
  <footer id="footer">
        <div class="container">

            <!-- footer socials -->
            <div class="row">

                <div class="footer_socials col-sm-12 text-center">

                    <div class="contact_icons">
                        <ul class="contact_socials clearfix">
                            <!-- social icons -->
                        </ul>
                    </div>
                     <img src="oldwebsite/assets/nb.png" width="162" height="53" class="navbar-logo-img" alt="">
<div class="copyright">Kontakt: kontakt@nattlan.net</div>
<div class="copyright">&copy; Copyright 2017 NattLAN</div>

Here's my send.php:

<title>NattLAN - Refund</title>
<?php

require 'connection.php';
$conn        = Connect();
$deltaker    = $conn->real_escape_string($_POST['u_deltaker']);
$payer       = $conn->real_escape_string($_POST['u_payer']);
$phone       = $conn->real_escape_string($_POST['u_phone']);
$konto       = $conn->real_escape_string($_POST['u_konto']);
$query       = "INSERT into tb_cform (u_deltaker,u_payer,u_phone,u_konto) VALUES('" . $deltaker . "','" . $payer . "','" . $phone . "','" . $konto . "')";
$success     = $conn->query($query);

if (!$success) {
    die("Fail".$conn->error);

}

echo "Success";

$conn->close();

?>

Here's my connection.php:

<?php
function Connect()
{
 $dbhost = "PRIVATE";
 $dbuser = "PRIVATE";
 $dbpass = "PRIVATE";
 $dbname = "PRIVATE";

 // Create connection
 $conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname) or die($conn->connect_error);

 return $conn;
}

?>

My database only put's the two last information from the form in the database, image showing the problem:

Image form DB showing that it inputs 0's in two of the fields:

https://prntscr.com/had0ak

Can someone help me figure out why this happens? Thanks :D

  • 写回答

1条回答 默认 最新

  • doujiu6976 2017-11-14 15:05
    关注

    I think it's inserting 0 because the column type is int? Check on that and change to varchar.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型