使用php更新mysql数据库

时间:2016-04-10 19:48:48

标签: php mysql

使用php更新mysql数据库...

嗨...我试图用PHP更新我的mysqld数据库,我得到一些错误...请帮我解决它... 这是他的错误......我是初学者,也是多普勒学生......

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "slr";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$soft_id = $_POST['soft_id'];
$soft_name = $_POST['soft_name'];
$installed_date = $_POST['installed_date'];
$expiry_date = $_POST['expiry_date'];
$product_key = $_POST['product_key'];

$sql = "UPDATE s110_pc01 ". "SET soft_name = $soft_name ". 
              "WHERE soft_id = $soft_id" ;
$retval = mysql_query( $sql, $link );


if($retval ) {
    echo "Updated data successfully\n";       
} else {
die('Could not update data: ' . mysql_error());          
mysql_close($link);
}
?>
<form method = "post" action = "<?php $_PHP_SELF ?>">
                  <table width = "400" border =" 0" cellspacing = "1" 
                     cellpadding = "2">

                     <tr>
                        <td width = "100">Software ID</td>
                        <td><input name = "soft_id" type = "text" 
                           id = "soft_id"></td>
                     </tr>

       <tr>
                        <td width = "100">Software Name</td>
                        <td><input name = "soft_name" type = "text" 
                           id = "soft_name"></td>
                     </tr>

这是我的代码:

Url.Action("action"...)

1 个答案:

答案 0 :(得分:0)

您的请求首先尝试通过这种方式进行编辑

$sql = "UPDATE s110_pc01 SET soft_name = '".$soft_name."' WHERE soft_id = $soft_id " ;
不推荐使用mysql_query函数,并且尝试使用Mysqli或PDO没有用处可能会更好 另外我看到teh $ link变量没有在给定的代码中定义