donpb2823 2012-05-23 17:39
浏览 47
已采纳

PHP插入MYSQL表单[关闭]

Hello i am having problems with my first php project which i am doing to teach my self a bit about it.So i made a form here is code:

vpis.html

<html>
    <head>
        <title>Php-Web Page - Input</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <div id="glava">
            <center>Php Spletna Stran</center>
            <hr/>
        </div>

        <div id="menu">
            <center>
                <a href="index.php">NAZAJ</a>
                <a href="bris.html">BRISANJE</a>
            </center>
            <hr/>
        </div>

        <div id ="vsebina">

            <div div="vpisigr">
                <form action="insert.php" method="post">
                    Vpisovanje igralca<br/>
                    ID:<input type="text" name="pid" size="20"/><br/>
                    Ime:<input type="text" name="pime" size="20"/><br/>
                    Priimek:<input type="text" name="ppriimek" size="20"/><br/>
                    Starost:<input type="text" name="pstarost" size="20"/><br/>
                    Velikost:<input type="text" name="pvelikost" size="20"/><br/>
                    Polozaj:<input type="text" name="ppolozaj" size="20"/><br/>
                    ID Kluba:<input type="text" name="ppid" size="20"/><br/>
                    <input type="submit" value="Shrani"/>
                    <input type="reset" value="Reset"/>
                </form>
            </div>
        </div>

        <hr/>

        <div id="footer">
            <center>Vse pravice pridržane </center>
        </div>
    </body>
<html>

So here i require from user to enter all data to insert into database. Here is screenshoot of database:

Database image

and here is insert.php which is called as form action

<?php
header("Content-type: text/html; charset=utf-8");
$con = mysql_connect("localhost","username","pass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("php", $con);
//hmmmm ne dela
$sql="INSERT INTO Igralec (iID, iIME, iPRIIMEK, iSTAROST, iVELIKOST, iPOLOZAJ, ID)
VALUES ('$_POST[pid]', '$_POST[pime]', '$_POST[ppriimek]', '$_POST[pstarost]', '$_POST[pvelikost]', '$_POST[ppolozaj]', '$_POST[ppid]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }

//die(print_r($_POST));
echo "Dodana je ena nova vrstica";


mysql_close($con);
?> 

The problem is thath evry time i submit data, it writes false data into database all in format like 0--0-0-00 or simmilar to thath. But in array before is written it contains correct data but somehow it writes in database false data.

  • 写回答

3条回答 默认 最新

  • doujiexi1824 2012-05-23 17:46
    关注

    Try editing your $sql variable to this:

        $sql="INSERT INTO Igralec (iID, iIME, iPRIIMEK, iSTAROST, iVELIKOST, iPOLOZAJ, ID)
    VALUES ('".$_POST[pid]."', '".$_POST[pime]."', '".$_POST[ppriimek]."', '".$_POST[pstarost]."', '".$_POST[pvelikost]."', '".$_POST[ppolozaj]."', '".$_POST[ppid]."')";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效