使用HTML表单和PHP更新MySQL数据库字段数据 [英] Update a MySQL database field data with HTML form and PHP

查看:192
本文介绍了使用HTML表单和PHP更新MySQL数据库字段数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我尝试使用html表单和一些PHP代码更新数据库字段,但是我无法使其正常工作,它不会引发任何错误但不会更新该字段?网页上的那个字段?似乎所要做的就是打印失败消息.

So I am trying to update a database field using a html form and some PHP code, but I cannot get it to work, it throws no errors but does not update the field?, Im not sure if its because im also echoing that field on the webpage? All it seems to do is print the fail message.

HTML:

<html>
    <form method="post" name="update" action="updateform.php" />

    Description:

    <input type="text"  name="description" />

            <input type="submit" name="Submit" Value="update" />
    </form>

    </html>

PHP:

<?php 
mysql_connect("localhost", "root", "*****") or die("Connection Failed"); 
mysql_select_db("Days")or die("Connection Failed"); 
$description = $_POST['description']; 
$query = "UPDATE test SET description = '$description' ";
if(mysql_query($query)){ echo "updated";} else{ echo "fail";} ?> 

我的回声(有效):

             <?php
include("include/session.php");
//connect to the server
$connect = mysql_connect("localhost","root","*****");

//connect to the database
mysql_select_db("days");

//query the database
$query = mysql_query("SELECT * FROM hobby WHERE id = '1' ");

//ferch the results / convert results into an array

    WHILE($rows = mysql_fetch_array($query)):

        $description = $rows['description'];

    echo "<div style ='font:15px/21px Arial,tahoma,sans-serif;color:#cf5c3f     </h>'>$description";
    endwhile;






?>

推荐答案

UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value

更新查询示例,但我没有得到您的sql ..您缺少您的where子句

Update query sample but i don't get your sql ..you missing your where clause

这篇关于使用HTML表单和PHP更新MySQL数据库字段数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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