what could be the problem with this code some data is npt being submitted to database

Discussion in 'PHP' started by shizzledizzleeee, Oct 3, 2016.

  1. #1
    what could be the problem with this code some data is npt being submitted to database.

    <?php
    $host = 'localhost';
    $username = 'root';
    $password = '';
    $datadase = 'registerfinal';
    $connect = mysqli_connect($host, $username, $password) or die ('error to connect to datadase'.mysqli_error());
    if ($connect) {
        echo 'mysqli connect succsessfull';
    }
    echo '<br /><br />';
    $selectdb = mysqli_select_db($connect, $datadase) or die ('unable to select datadase'.mysqli_error());
    if($selectdb) {
        echo 'database selected succsessfully';
    }
    
    if(isset($_POST['savedetails'])) {
           
        $firstname = $_POST['firstname'];
        $lastname = $_POST['lastname'];
        $username = $_POST['username'];
        $password = $_POST['password'];
        $repeat_password = $_POST['repeat_password'];
        $gender = $_POST['gender'];
        $country = $_POST['country'];
       
       
        if(isset($_POST['food'])) {
        $food = $_POST['food'];
        $favfood = "";
        foreach($food as $meal ) {
        $favfood = $meal.",";   
        print_r($favfood);
        }
    }
       
        if(isset($_POST['imageUpload'])) {
        $imageUploadname = $_FILES['imageUpload']['name'];
        $imageUploadsize = $_FILES['imageUpload']['size'];
        $imageUploadtmp_name = $_FILES['imageUpload']['tmp_name'];
        $imageUploadtype = $_FILES['imageUpload']['type'];
        $uploadFolder = "uploadFolder/";
        $destinationName = rand(1000, 10000).$imageUploadname;   
       
        move_uploaded_file($imageUploadtmp_name, $uploadFolder.$destinationName);
        echo "$imageUploadname";
        echo "$imageUploadsize";
        echo "$imageUploadtmp_name";
        echo "$imageUploadtype";
        echo "$destinationName";
       
        }
       
        var_dump($_FILES['imageUpload']) ;
        $sqltwo = "INSERT INTO `registerfinaltable` (`id`, `firstname`, `lastname`, `username`, `password`, `repeat_password`,
        `gender`, `food`, `country`, `imageUploadname`, `imageUploadsize`, `imageUploadtype`)
        VALUES (NULL, '$firstname', '$lastname', '$username', '$password', '$repeat_password', '$gender', '$favfood', '$country',
        '$destinationName', '$imageUploadsize', '$imageUploadtype')";
       
        $results = mysqli_query($connect, $sqltwo) ;
        if($results){
           
        echo "inserted successfully";
        }
        echo "$sqltwo";
    }
    
    ?>
    
    
    <html>
    <head>
    <title>register</title>
    
    </head>
    
    <body>
    <form action = "" method = "post"  enctype = "multipart/form-data"  >
    <label>first name : <input type = "text" name = "firstname" /> </label> <br /><br />
    <label>last name : <input type = "text" name = "lastname" /> </label><br /><br />
    <label>username : <input type = "text" name = "username" /> </label><br /><br />
    <label>password : <input type = "password" name = "password" /> </label><br /><br />
    <label>repeat password : <input type = "password" name = "repeat_password" /> </label><br /><br />
    <label>Male :   <input type = "radio" name = "gender" value = "Male" /> </label><br /><br />
    <label>Female : <input type = "radio" name = "gender"  value = "Female" /> </label><br /><br />
    <label>pizza : <input type = "checkbox" name = "food[]" value = "pizza"/> </label><br /><br />
    <label>burger : <input type = "checkbox" name = "food[]" value = "burger"/> </label><br /><br />
    <label>chips : <input type = "checkbox" name = "food[]" value = "chips"/> </label><br /><br />
    <label>sausage : <input type = "checkbox" name = "food[]" value = "sausage"/> </label><br /><br />
    <label>sandwich : <input type = "checkbox" name = "food[]" value = "sandwich"/> </label><br /><br />
    <label>Image : <input type = "file" name = "imageUpload" /> </label><br /><br />
    <select name = "country">
    <?php
    $sql = 'SELECT * FROM `countrie` ';
    $querry = mysqli_query($connect, $sql);
    while($country = mysqli_fetch_array($querry)):;
    
    ?>
    
    <option value = "<?php echo $country['country']; ?>"><?php echo $country['country']; ?></option>
    <?php endwhile;?>
    
    
    </select> <br />
    
    
    <input type = "submit" name = "savedetails" />
    
    
    
    </form>
    <table border = "1" bgcolor = "" width = "100%">
    <tr><th>id</th><th>Firstname</th><th>Lastname</th><th>Username</th><th>Password</th><th>Password 2</th><th>Gender</th><th>Fav. Food</th> <th>Image</th> <th>Country</th><th>imageUploadname</th><th>imageUploadsize</th><th>imageUploadtype</th></tr>
    <?php
    $sqldata = "SELECT * FROM registerfinaltable";
    $querysqldata = mysqli_query($connect, $sqldata);
    while($rows = mysqli_fetch_array($querysqldata) ):;
    ?>
    <tr>
    <td><?php echo $rows['id'];?></td>
    <td><?php echo $rows['firstname'];?></td>
    <td><?php echo $rows['lastname'];?></td>
    <td><?php echo $rows['username'];?></td>
    <td><?php echo $rows['password'];?></td>
    <td><?php echo $rows['repeat_password'];?></td>
    <td><?php echo $rows['lastname'];?></td>
    <td><?php echo $rows['gender'];?></td>
    <td><?php echo $rows['food'];?></td>
    <td><?php echo $rows['country'];?></td>
    <td><?php echo $rows['imageUploadname'];?></td>
    <td><?php echo $rows['imageUploadsize'];?></td>
    <td><?php echo $rows['imageUploadtype'];?></td>
    <?php endwhile;?>
    </tr>
    </table>
    </body>
    </html>
    PHP:
    [​IMG]

    [​IMG]


    this is the browser echoed data

    [​IMG]
     
    shizzledizzleeee, Oct 3, 2016 IP
  2. wordplucker

    wordplucker Well-Known Member

    Messages:
    205
    Likes Received:
    38
    Best Answers:
    1
    Trophy Points:
    105
    #2
    line 57, $destinationName? not $imageUploadName?

    line 55 seems to be missing the 'destintationName'

    Shouldn't the variables be matching, although PHP isn't my strong suit
     
    wordplucker, Oct 3, 2016 IP
  3. shizzledizzleeee

    shizzledizzleeee Member

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    i have concatenated it with the random numbers (php - rand() function ) and its been held in this variable $destinationName
     
    shizzledizzleeee, Oct 3, 2016 IP