مشکل insert php
https://lamtakam.com/qanda/7149/مشکل-insert-php 1<?php
include('config.php');?>
<html>
<body>
<head>
<meta charset="UTF-8">
</head>
<form method="POST" action="add-post.php" enctype="multipart/form-data">
Name: <input type="text" name="titlenews">
<select name="catnews">
<option value="">Select Category</option>
<?php $query = "SELECT * FROM tblcategory"; ?>
<?php foreach($con->query($query)as $row){
echo $row['cat_name'];
echo "<option value='".$row['id']."'>".$row['catname']." </option>";
}
?>
</select>
<select name="subcat">
<option value="">Select Category</option>
<?php $query = "SELECT * FROM tblsubcategory"; ?>
<?php foreach($con->query($query)as $row){
echo $row['subcatname'];
echo "<option value='".$row['SubCategoryId']."'>".$row['subcatname']." </option>";
}
?>
</select>
Name: <input type="text" name="newsdesc">
Name: <input type="file" name="postimage">
<td><input type="submit" name="post" value=" ارسال مطلب"/></td>
</form>
</body>
</html>
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
if(isset($_POST['post']))
{
$titlenews=$_POST['titlenews'];
$catnews=$_POST['catnews'];
$subcat=$_POST['subcat'];
$newsdesc=$_POST['newsdesc'];
$arr = explode(" ",$titlenews);
$url=implode("-",$arr);
$imgfile=$_FILES["postimage"]["name"];
$extension = substr($imgfile,strlen($imgfile)-4,strlen($imgfile));
$allowed_extensions = array(".jpg","jpeg",".png",".gif");
if(!in_array($extension,$allowed_extensions))
{
echo "<script>alert('Invalid format. Only jpg / jpeg/ png /gif format allowed');</script>";
}
else
{
$imgnewfile=md5($imgfile).$extension;
move_uploaded_file($_FILES["postimage"]["tmp_name"],"postimages/".$imgnewfile);
$newsview=1;
$newsdate=time();
$query="INSERT INTO `tblnews`(`titlenews`, `catnews`, `subcat`, `newsdesc`,`postimage`, `newsview`) VALUES ($titlenews','$catnews','$subcat','$newsdesc','$imgnewfile','$newsview')";
$query_run=mysqli_query($con,$query);
if ($query_run){
echo "<script>alert('ok');</script> ";
}
else{
echo "no run";
}
}
}
?>
لطفا سوالتون رو ویرایش کنید و ذکر کنید که چه اروری میگیرید ــ ساناز رضایی در 9 ماه قبل |