简体   繁体   English

如何从php / html表单中获取数据到数据库?

[英]How can I fetch data from a php/html form into database?

I have problems when trying to update my database with the data posted in my web system. 尝试使用Web系统中发布的数据更新数据库时遇到问题。 I've created a php file that contains the html forms as far as my order-form is concerned, where I can select several producs and their quantity. 我已经创建了一个php文件,其中就我的订单形式而言包含html表单,在这里我可以选择多个产品及其数量。 Then I've created this : 然后我创建了这个:

   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <?php 
        require_once("buzzcafe_fns.php");
     do_html_header('Order form');
    db_connect();
        $otable=$_POST['otable'];
        $title=$_POST['title'];
        $quantity=$_POST['quantity'];
        $datetime=$_SESSION['datetime'];
        $username=$_SESSION['username'];

        if(isset($_SESSION['username']))
                {
                        if( !$otable || !$title || !$quantity )
                        {
                            echo'<font color="red">Please fill in all required fields</font>';
                            exit;
                        }
                }
            $insertOrder = mysql_query('INSERT INTO orders VALUES($oid, $title, $quantity, $sum, $datetime, $username)')or die(mysql_error());

                        echo ('<p>Your order is added</p>');
                        echo ('<p>View your order <a href="vieworder.php?insertOrder='.$insertOrder.'"></a></p>');
                        echo ('<p>Add a new order <a href="addorder-form.php"></a></p>');
                        echo ('<p>Return in main page<a href="members.php"></a></p>');

?>

What is wrong on this code ? 此代码有什么问题?

This statement, which infact is the core, is incorrect 该声明实际上是核心,它是不正确的

$insertOrder = mysql_query('INSERT INTO orders VALUES($oid, $title, $quantity, $sum, $datetime, $username)')or die(mysql_error());

It should be 它应该是

$insertOrder = mysql_query("INSERT INTO orders VALUES($oid, $title, $quantity, $sum, $datetime, $username)")or die(mysql_error());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从php中的数据库中获取数据? - how can i fetch data from the database in php? 为什么我不能使用 php 从我的 SQL 数据库中的 html 文档中获取数据? - Why can't i fetch data from my SQL database, in a html document, using php? 我可以在post方法表单中从数据库中获取数据吗? - Can I fetch data from database, inside the post method form? 我如何从 MYSQL 数据库中获取数组形式的数据并在 android 工作室中显示 - How i can fetch array form of data from MYSQL database and show it in android studio 如何同时从不同表中的数据库中获取数据 PHP MYSQL - How can I Fetch data from database from different tables at the same time PHP MYSQL 如何读取 php 中的 fetch() 表单数据? - How can I read fetch() form data in php? 如何使用PHP从另一个网站获取数据并将其存储在MySQL数据库中? - How can I use PHP to fetch data from another website and store it in a MySQL database? 使用PHP以HTML形式以表格式从数据库中获取和显示数据 - Fetch and display data from database in table format in HTML form using PHP 如何使用表单输入中的值在数据库中进行匹配并获取记录/行数据以预填充表单? - How can i use a value from a form input to match in my database and fetch record/row data to prefill a form? 我如何从php的while循环中使用的html标记中获取单个文本值以显示数据库中的数据? - how do i fetch a single text value from html tag used in while loop of php to display data from database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM