php查询、插入、删除、修改记录

插入记录

<?php

$my_con = mysql_connect("127.0.0.1","userName","pwd");
mysql_select_db("yuding_renshu",$my_conn);    
$xianlu_name=$_POST[xianlu_name];
$xianlu_id=$_POST[xianlu_id];
$yuding_renshu_riqi=$_POST[day];
$yuding_renshu_num=$_POST[yuding_renshu_num];
$sql ="INSERT INTO    yuding_renshu(`xianlu_id`,`xianlu_name`,`yuding_renshu_riqi`,`yuding_renshu_num`) VALUES('$xianlu_id','$xianlu_name','$yuding_renshu_riqi','$yuding_renshu_num')";

mysql_query($sql);     mysql_close($my_con);
    

备注:values 里面的数据如果是变量,则用引文单引号    '    '     包起来,如果是字符串,则用引文双引号    "     "    包起来;

数据表里面的字段则要用数字键1 左边的那个点    `    ` 包起来,否则插入不进去!



删除记录

<?php
$con = mysql_connect("127.0.0.1","userName","pwd");
mysql_select_db("db_cencencen", $con);
$result = mysql_query("DELETE FROM lvcha_user WHERE id=1");
mysql_close($con);
echo "删除记录";
?>

查询记录

<?php
$con = mysql_connect("127.0.0.1","userName","pwd");
mysql_select_db("db_cencencen", $con);
$result = mysql_query("SELECT * FROM lvcha_user");
while($row = mysql_fetch_array($result))
{
echo $row['id'] . " " . $row['userName'];
echo "<br />";
}

mysql_close($con);
echo "查询记录";
?>

    

php修改记录


<?php
$jiesuan=$_POST[jiesuan]; $dd_day2=$_POST[day2];$dd_crrs=$_POST[crrs];    
$con = mysql_connect("127.0.0.1","userName","pwd");mysql_select_db("db_cencencen", $con);
mysql_query("UPDATE dingdan    SET    jiesuan='{$jiesuan}',dd_day2='{$dd_day2}',dd_crrs='{$dd_crrs}'    WHERE    dd_id='{$_POST[dd_id]}' ") ;
mysql_close($con);?>
update 语句中 给字段赋值的变量要写成这样        '{变量}'

你可能感兴趣的:(职场,休闲,php语句)