PHP/SQL 向 sql 插入数据 [英] PHP/SQL inserting data to sql

查看:44
本文介绍了PHP/SQL 向 sql 插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从我的表单向 sql 插入数据,但数据没有进入我的 sql 表.我也没有收到错误.这是我所拥有的:

I'm trying to insert data to sql from my form but the data is not going into my sql table. Also I'm not getting errors. Here is what I have :

<?php
mysqli_select_db($connect, "prekes");
if(isset($_POST['submit']))
{
     $pavad =  $_POST['pavad'];
     $Gamintojas =  $_POST['Gamintojas'];
     $Spalva =  $_POST['Spalva'];
     $Kiekis =  $_POST['Kiekis'];
     $Blizgumas = $_POST['Blizgumas'];
     $Kaina =  $_POST['Kaina'];
     $Kategorija =  $_POST['Kategorija'];
     $sandely =  $_POST['sandely'];

$query="
INSERT INTO prekes 
( pavad, Gamintojas, Spalva, Kiekis
, Blizgumas, Kaina, Kategorija, sandely) 
VALUES 
( '$pavad', '$Gamintojas', '$Spalva', '$Kiekis'
, '$Blizgumas', '$Kaina', '$Kategorija', '$sandely')
";

      if(mysqli_query($connect,$query))
      {
        echo "prideta";
      }else {
        echo"nope";
      }
}
?>

我还把我的 main.php 代码放在我把我的连接和表放在

I've also putting my main.php code where I put my connection and tables at

</table>
<div class="prekiu_lentele">
<div class="lent">
<table class="lenetele_prekems" align="center">
<form action="insert.php" method="post">
<form action="update.php" method="get">
<tr>
    <th>Pavadinimas:<input type="text" name="pavad"></tr>
    <th>Gamintojas:<input type="text" name="Gamintojas"></tr>
    <th>Spalva:<input type="text" name="Spalva"></tr>
    <th>Kiekis:
      <select name="Kiekis">
        <option value="1l">1 l</option>
        <option value="2l">2 l</option>
        <option value="5l">5 l</option>
        <option value="10l">10 l</option>
      </select></tr>
    </tr>
    <tr>
    <th>Blizgumas:<input type="text" name="Blizgumas"></tr>
    <th>Kaina:<input type="text" name="Kaina"></tr>
    <th>Kategorija:<input type="text" name="Kategorija"></tr>
    <th>Kiekis sandelyje:<input type="text" name="sandely"></tr>
    </tr>
    <tr>
      <th ><input type="submit"; style="width: 300px"; value="Insert"  name="submit" ></th>
</tr>
</form>

推荐答案

我成功了,我的 sql 数据库路径错误-_-.mysqli_select_db($connect, "prekes");->mysqli_select_db($connect, "produktai");菜鸟错误..

I got it working, my path to sql database was wrong -_-. mysqli_select_db($connect, "prekes"); -> mysqli_select_db($connect, "produktai"); Noob mistakes..

这篇关于PHP/SQL 向 sql 插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆