我已经找到了很多方法来尝试,但我无法执行插入/更新/删除操作。我还在想办法,所以我希望有人能帮助我。谢谢!
<?php
$connection = mysql_connect('localhost', 'root', '123456'); //The Blank string is the password
mysql_select_db('album');
$query = "SELECT * FROM property"; //You don't need a ; like you do in SQL
$result = mysql_query($query);
echo "All property";
echo "<table>"; // start a table tag in the HTML
while($row = mysql_fetch_array($result)){ //Creates a loop to loop through results
echo "<tr><td>" ." Update_date: ". $row['Update_date'] . "</td><td>" ." Region: " .$row['Region'] . "</td></tr>"; //$row['index'] the index here is a field name
echo "<tr><td>" ." Street: " . $row['Street'] . "</td><td>" ." Building: " . $row['Building'] . "</td></tr>";
echo "<tr><td>" ." Unit: " . $row['Unit'] . "</td><td>";
echo "<tr><td>" ." Saleable_area: " . $row['Saleable_area']."</td><td>" ." Construction_area: " . $row['Construction_area'] . "</td></tr>";
echo "<tr><td>" ." Rent: " . $row['Rent'] . "</td><td>" ." Price: $" . $row['Price'] . "</td></tr>";
echo "<tr><td>" ." Contant_person: " . $row['Contant_person'] . "</td><td>" ." Contant_Num: " . $row['Contant_Num'] . "</td></tr>";
echo "<tr><td>" ." Layout: " . $row['Layout'] . "</td><td>" ." Decoration: " . $row['Decoration'] . "</td></tr>";
echo "<tr> <td>"."<a href='photo.php>Photo</a>"."<tD><tR>";
echo "<tr> <td>";
echo "<tr> <td>";
echo "<tr> <td>";
echo "<tr> <td>";
echo "<tr> <td>";
}
echo "</table>"; //Close the table in HTML
mysql_close(); //Make sure to close out the database connection
?>
mysql
是一个不推荐使用的扩展。请改用mysqli
或PDO
。下面是一个语句示例-
$mysqli = new mysqli("example.com", "user", "password", "database");
//insert
$mysqli->query("insert into yourtable (field_first, field_second) values ('valueFirst', 'valueSecond')");
//update
$mysqli->query("update yourtable set field_first='valueFirst' where id=2");
//delete
$mysqli->query("delete from yourtable where id = 2");
$query = "INSERT INTO property VALUES(?, ?, ?)";
$result = mysql_query($query);
注意:不要再使用mysql-*函数,因为它们已被弃用,最好使用mysqli或PDO
欲了解更多参考资料,请关注http://php.net/manual/en/mysqli.query.php
插入:
$title=$_POST['title'] ;
$author= $_POST['author'] ;
$name=$_POST['name'] ;
$copy=$_POST['copy'] ;
mysqli_query("INSERT INTO `example`(Title,Author,PublisherName,CopyrightYear)
VALUES ('$title','$author','$name','$copy')");
删除:
$id =$_REQUEST['BookID'];
mysqli_query("DELETE FROM example WHERE BookID = '$id'")
更新
$title_save = $_POST['title'];
$author_save = $_POST['author'];
$name_save = $_POST['name'];
$copy_save = $_POST['copy'];
mysqli_query("UPDATE example SET Title ='$title_save', Author ='$author_save',
PublisherName ='$name_save',CopyrightYear ='$copy_save' WHERE BookID = '$id'")
对于更新,您可以尝试。。。
$query = "UPDATE property SET
`field_name1`='$update_value1',
`field_name2`='$update_value2'
WHERE id=$id ";
$result = mysql_query($query);
插入查询
$ins="INSERT INTO `your_table_name` (`field_name1`,`field_name2`) VALUES ('value1','value2')";
$exe=mysql_query($ins);
更新查询
$update="UPDATE `table_name` SET `field_name1`='val1',`field_name2`='val2' WHERE `place_your condition`";
$exe_up=mysql_query($update);
删除查询
$delete="DELETE `tbl_name` WHERE `place_your condition`";
$exe_del=mysql_query($delete);