使用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