PHP与MYSQL(增,查)

这几天写PHP大作业,简直从0开始PHP,之前因为打比赛占了很多时间,现在重新学一下,感觉和c差不多,除了经常忘记写$,当然数据库的插入的确花费了一些时间,感觉写的没什么问题就是插不到数据库中,(感觉自己能A,缺一直返回WA)

贴下数据库有关的插入和遍历结果

代码:

<?php
    $my=mysql_connect("localhost","root","123456");
    if(!$my){
        die('数据库链接出错'.$mysqli->connect_error);
    }
    header('Content-type:text/html;charset=utf-8');    
    mysql_select_db("school",$my);
    
    $un="160212";
    $tit="李五";
    $con="中";
    $conn=18;
    $connn="CS";
    
    $insertSQL="INSERT INTO student values('$un','$tit','$con','$conn','$connn')";
    $inserted=mysql_query($insertSQL,$my);
    if($inserted){
        echo "success<br/>";
    }
    else {
        echo "error 2<br>";
    }

    $qqq="160209";
    $insertSQL="select * from student where Sno='$qqq'";
    $inserted=mysql_query($insertSQL,$my);
    while($row=mysql_fetch_array($inserted)){
        $as=$row["Sno"];
        $qw=$row["Sname"];
        echo $as." ".$qw."<br/>";
    }
    
    $close = @mysql_close($my);
?>

猜你喜欢

转载自www.cnblogs.com/lalalatianlalu/p/10045098.html