+1 stemme til aidinMC
Svar af aidinMC løser delvist dit spørgsmål.
Der er to små fejl i aidinMC svar
}
else
$errMSG = "You already insert 5 rows";
endif;
$count = $data[0]['rows'];
if($count < 5)
{
Efter at have ændret disse to fejl Svar af aidinMC vil arbejde! Men efter at have set dine kommentarer, især Grænse for upload af dokumenter &Grænse for upload af dokumenter det vil ikke give resultatet, som du ønsker.
Så det, du ønsker, er her:-
<?php
error_reporting( ~E_NOTICE ); // avoid notice
require_once 'dbconfig.php';
if(isset($_POST['btnsave']))
{
$username = $_POST['user_name'];// user name
$userjob = $_POST['user_job'];// user email
$imgFile = $_FILES['user_image']['name'];
$tmp_dir = $_FILES['user_image']['tmp_name'];
$imgSize = $_FILES['user_image']['size'];
if(empty($username)){
$errMSG = "Please Enter Name.";
}
else if(empty($userjob)){
$errMSG = "Please Enter Description.";
}
else if(empty($imgFile)){
$errMSG = "Please Select Image File.";
}
else
{
$upload_dir = 'user_images/'; // upload directory
$imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension
// valid image extensions
$valid_extensions = array('jpeg', 'jpg', 'png', 'gif', 'txt'); // valid extensions
// rename uploading image
$userpic = rand(1000,1000000).".".$imgExt;
// allow valid image file formats
if(in_array($imgExt, $valid_extensions)){
// Check file size
if($imgSize < 10000000) {
move_uploaded_file($tmp_dir,$upload_dir.$userpic);
}
else{
$errMSG = "Sorry, your file is too large.";
}
}
else{
$errMSG = "Sorry, this file is not allowed.";
}
}
// if no error occured, continue ....
if(!isset($errMSG))
{
$stmt = $DB_con->prepare('INSERT INTO tbl_users(userName,userProfession,userPic) VALUES(:uname, :ujob, :upic)');
$stmt->bindParam(':uname',$username);
$stmt->bindParam(':ujob',$userjob);
$stmt->bindParam(':upic',$userpic);
$data = $DB_con->query("SELECT COUNT(*) AS rows FROM tbl_users WHERE 1")->fetchall();
$count = $data[0]['rows'];
if($count < 5)
{
if($stmt->execute())
{
$successMSG = "new record succesfully inserted ...";
header("refresh:1;index.php"); // redirects image view page after 1 seconds.
}
else
{
$errMSG = "error while inserting....";
}
}
else
{
$errMSG = "You already insert 5 rows";
}
}
}
?>
Jeg har lige redigeret placeringen af koder Besvaret af aidinMC og rettede nogle fejl i Svar af aidinMC .
Håber det vil virke.