简体   繁体   中英

Unable to save submitted data in a MySQL database using PHP

Please may I ask for some assistance on this as I have been trying to fix for days now.It is accepting data when i key in but not appearing in the database when i check.

Here is my code

if ($_SERVER["REQUEST_METHOD"] == "POST") {

if (isset($_POST["btnSave"])) {

    $db = new \dbPlayer\dbPlayer();
    $msg = $db->open();
    //echo '<script type="text/javascript"> alert("'.$msg.'");</script>';
    if ($msg = "true") {
        $userIds = $db->getAutoId("U");
        $flup = new fileUploader\fileUploader();
        $perPhoto = $flup->upload("/hms/files/photos/",$_FILES['perPhoto'], $userIds[1]);
       // var_dump($perPhoto);
        $handyCam=new \handyCam\handyCam();
       if (strpos($perPhoto, 'Error:') === false) {
            $dateNow=date("Y-m-d");
            $data = array(
                'userId' => $userIds[1],
                'name' => $_POST['name'],
                'studentId' => $_POST['studentId'],
                'cellNo' => $_POST['cellNo'],
                'gender' => $_POST['gender'],
                'dob' => $handyCam->parseAppDate($_POST['dob']),
                'passportNo' => $_POST['passportNo'],
                'fatherName' => $_POST['fatherName'],
                'fatherCellNo' => $_POST['fatherCellNo'],
                'perPhoto' => $perPhoto,
                'isActive' => 'Y'
            );
            $result = $db->insertData("studentinfo",$data);
            if($result>=0) {
                 $id =intval($userIds[0])+1;

                    $query="UPDATE auto_id set number=".$id." where prefix='U';";
                    $result=$db->update($query)

Use this form to fix your problem

     if(isset($_POST["btn-pub"]))
{
    $title = $_POST["title"];
    $cat = $_POST["postCat"];
    $Author = "Imran AKKI";
    $ImgName = $_FILES['PostImg']['name'];
    $ImgTemp = $_FILES['PostImg']['tmp_name'];
    $cont = $_POST["postCon"];
    if (empty($title) || empty($cont)){ 
        ?> 
        <div class="alert alert-danger"><?php echo "Please fill in the fields";  ?>
        </div> 
        <?php
        }elseif($cont > 10000){
            ?> 
        <div class="alert alert-warning"><?php echo "The content of the post is very large";  ?>
        </div> 
        <?php
        }else{
            $postImage = rand(0,10000)."_".$ImgName;
            move_uploaded_file($ImgTemp,"Uploads\postImges\\" .$postImage);

        $query = "INSERT INTO posts(PostTitle, PostCat, PostImg, PostContent,PostAuthor) VALUES ('$title','$cat','$postImage','$cont','$Author')";
        $res=mysqli_query($conn,$query);
        if(isset($res)){
        ?>
        <div class="alert alert-success"><?php echo "The article was added successfully";  ?> </div>
        <?php
        }else{
            ?>
        <div class="alert alert-danger"><?php echo "An error occurred during addition";  ?> </div>
        <?php
        }
    }

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM