Web Analytics Made Easy -
StatCounter Some Parts Of data Not being inserted into the database - CodingForum

Announcement

Collapse
No announcement yet.

Some Parts Of data Not being inserted into the database

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Some Parts Of data Not being inserted into the database

    Code:
    <?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";
    	
    	}
    	$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";
    	}
    }
    
    ?>
    
    
    <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>
    Last edited by vinyl-junkie; Oct 3, 2016, 12:53 AM. Reason: removed indent and php tags to make post easier to read

  • #2
    https://i.gyazo.com/4c5f2ccfc3cb2e7d...357219096b.png
    Attached Files

    Comment


    • #3
      Click image for larger version

Name:	a17baebbce8a2df4f1f1efb269e8f5e1.png
Views:	1
Size:	31.9 KB
ID:	2270508

      Comment


      • #4
        There is no $_POST['imageUpload']. The uploaded file information is in $_FILES['imageUpload'], not $_POST['imageUpload'].
        Finding out HOW to do something is called research, i.e. keep searching until you find the answer. After you attempt to do something and cannot solve a problem with it yourself, would be when you ask others for help.

        Comment

        Working...
        X