اذهب إلى المحتوى

السؤال

نشر

عندي صفحتين في  php اضافة insert وتحديث update  الى قاعدة البيانات كان يعمل الكود  لاكن الان اصبح يدخل احيانن فقط مدخل وبعدها لايدخل شي او مايدخل شيء نهائيا مع ان الكود صحيح مايظهر اي ايرور والاتصال بقاعدة البيانات يعمل 

وكذلك مع التحديث مره يحدث ومره لا  !!!

ملاحظة عندي صفحات ثانيه بنفس المشروع اضافه وتحديث تعمل عادي 

Recommended Posts

  • 0
نشر
بتاريخ 13 ساعات قال بلال زيادة:

هل يمكنك إرفاق الكود الذي تتوقع أن تكون به المشكلة ؟ 

if (isset($_POST['submit'])) {

  $name=$_POST['name'];
  $descr=$_POST['descr'];
  $info=$_POST['info'];
  $price=$_POST['price'];
  $qty=$_POST['qty'];
  $sku=$_POST['SKU'];
  $si=$_POST['size'];
  $chkt=implode(",",$si);
  $descrebtion =$_POST['descrebtion'];
  $discount =$_POST['discount'];
  $created_at= date('Y-m-d H:i:s');
  $img_name = $_FILES['uploadfile1']['name'];
  $img_type = $_FILES['uploadfile1']['type'];
  $tmp_name = $_FILES['uploadfile1']['tmp_name'];

  $img_name2 = $_FILES['uploadfile2']['name'];
  $img_type2 = $_FILES['uploadfile2']['type'];
  $tmp_name2 = $_FILES['uploadfile2']['tmp_name'];

  $img_name3 = $_FILES['uploadfile3']['name'];
  $img_type3 = $_FILES['uploadfile3']['type'];
  $tmp_name3 = $_FILES['uploadfile3']['tmp_name'];

  $img_name4 = $_FILES['uploadfile4']['name'];
  $img_type4 = $_FILES['uploadfile4']['type'];
  $tmp_name4 = $_FILES['uploadfile4']['tmp_name'];


  $img_explode = explode(".",$img_name);
  $img_ext = end($img_explode);

  $img_explode2 = explode(".",$img_name2);
  $img_ext2 = end($img_explode2);

  $img_explode3 = explode(".",$img_name3);
  $img_ext3 = end($img_explode3);

  $img_explode4 = explode(".",$img_name4);
  $img_ext4 = end($img_explode4);





  $extension= ['png','jpeg','jpg','gif'];
  $Get_image_name = $_FILES['uploadfile1']['name'];
  $image_Path = "img/".basename($Get_image_name);
  $Get_image_name2 = $_FILES['uploadfile2']['name'];
  $image_Path2 = "img/".basename($Get_image_name2);
  $Get_image_name3 = $_FILES['uploadfile3']['name'];
  $image_Path3 = "img/".basename($Get_image_name3);
  $Get_image_name4 = $_FILES['uploadfile4']['name'];
  $image_Path4 = "img/".basename($Get_image_name4);


$sql ="INSERT INTO product(name,descr,info, price ,qty ,img1 ,img2 ,img3 ,img4 ,SKU, size,disc_id ,cate_id,created_at) VALUES ('$name','$descr' ,'$info', '$price','$qty' ,'$Get_image_name','$Get_image_name2' ,'$Get_image_name3' ,'$Get_image_name4' ,'$sku' ,'$chkt' ,'$discount','$descrebtion','$created_at')";
mysqli_query($conn,$sql);
//mysqli_query($conn,("ALTER TABLE `product` DROP FOREIGN KEY `cat`; ALTER TABLE `product` ADD CONSTRAINT `cat` FOREIGN KEY (`cate_id`) REFERENCES `productcategory`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; ALTER TABLE `product` DROP FOREIGN KEY `disc`; ALTER TABLE `product` ADD CONSTRAINT `disc` FOREIGN KEY (`disc_id`) REFERENCES `discount`(`id`) ON DELETE CASCADE ON UPDATE CASCADE"));


  if (move_uploaded_file($_FILES['uploadfile1']['tmp_name'], $image_Path)){
    echo "<script>alert('Uploaded Successfully');</script>
      <script>window.location.href = 'addprodect.php'</script>";
  }else{
   echo  "Not Insert Image";
   }
  if (move_uploaded_file($_FILES['uploadfile2']['tmp_name'], $image_Path2)){
    echo "<script>alert('Uploaded Successfully');</script>
      <script>window.location.href = 'addprodect.php'</script>";
  }else{
   echo  "Not Insert Image";
   }
  if (move_uploaded_file($_FILES['uploadfile3']['tmp_name'], $image_Path3)){
    echo "<script>alert('Uploaded Successfully');</script>
      <script>window.location.href = 'addprodect.php'</script>";
  }else{
   echo  "Not Insert Image";
   }
  if(move_uploaded_file($_FILES['uploadfile4']['tmp_name'], $image_Path4)){
    echo "<script>alert('Uploaded Successfully');</script>
      <script>window.location.href = 'addprodect.php'</script>";

  }else{
   echo  "Not Insert Image";
   }


   echo "<script>alert('Uploaded Successfully');</script>
     <script>window.location.href = 'addprodect.php'</script>";

}

كود insert  ^^ 

if (isset($_POST["update"])) {
$id= $_GET['id'];
$name=$_POST['name'];
$descr=$_POST['descr'];
$info=$_POST['info'];
$price=$_POST['price'];
$descrebtion=$_POST['descrebtion'];
$sku=$_POST['sku'];
 $siz=$_POST['size'];
 $discount =$_POST['discount'];
 $chkt=implode(",",$siz);
 $created_at= date('Y-m-d H:i:s');

  $img1=$_FILES["uploadfile1"]["name"];
  $img2=$_FILES["uploadfile2"]["name"];
  $img3=$_FILES["uploadfile3"]["name"];
  $img4=$_FILES["uploadfile4"]["name"];

  if ($img1 =="" ) {
    $sql="UPDATE product set  name= '$name' ,descr ='$descr', info= '$info', price=$price, cate_id='$descrebtion' ,disc_id='$discount', SKU='$sku' , size='$chkt'  , created_at='$created_at'  where id=$id ";
   mysqli_query($conn, $sql);
  }else {
    $Get_image_name = $_FILES['uploadfile1']['name'];
    $image_Path = "img/".basename($Get_image_name);
    $sql="UPDATE product set img1='$Get_image_name' , name= '$name' ,descr ='$descr', info= '$info', price=$price, cate_id='$descrebtion' ,disc_id='$discount', SKU='$sku'  , size='$chkt' , created_at='$created_at' where id=$id ";
    mysqli_query($conn, $sql);
    if (move_uploaded_file($_FILES['uploadfile1']['tmp_name'], $image_Path)){
      echo "<script>alert('Updated Successfully');</script>
        <script>window.location.href = 'editprod.php'</script>";
    }else{
     echo  "Not Insert Image";
     }
}

if ($img2 =="" ) {
  $sql="UPDATE product set name= '$name' ,descr ='$descr', info= '$info', price=$price, cate_id='$descrebtion' ,disc_id='$discount', SKU='$sku'  ,size='$chkt' , created_at='$created_at' where id=$id ";
mysqli_query($conn, $sql);
}else {
  $Get_image_name2 = $_FILES['uploadfile2']['name'];
  $image_Path2 = "img/".basename($Get_image_name2);
  $sql="UPDATE product set img2='$Get_image_name2' , name= '$name' ,descr ='$descr', info= '$info', price=$price, cate_id='$descrebtion' ,disc_id='$discount', SKU='$sku' , size='$chkt' , created_at='$created_at' where id=$id ";
  mysqli_query($conn, $sql);
  if (move_uploaded_file($_FILES['uploadfile2']['tmp_name'], $image_Path2)){
    echo "<script>alert('Updated Successfully');</script>
      <script>window.location.href = 'editprod.php'</script>";
  }else{
   echo  "Not Insert Image";
   }
}

if ($img3 =="" ) {
  $sql="UPDATE product set  name= '$name' ,descr ='$descr', info= '$info', price=$price, cate_id='$descrebtion' ,disc_id='$discount', SKU='$sku' , size='$chkt' , created_at='$created_at' where id=$id ";
mysqli_query($conn, $sql);
}else {
  $Get_image_name3 = $_FILES['uploadfile3']['name'];
  $image_Path3 = "img/".basename($Get_image_name3);
  $sql="UPDATE product set img3='$Get_image_name3' , name= '$name' ,descr ='$descr', info= '$info', price=$price, cate_id='$descrebtion' ,disc_id='$discount', SKU='$sku' , size='$chkt' , created_at='$created_at' where id=$id ";
  mysqli_query($conn, $sql);
  if (move_uploaded_file($_FILES['uploadfile3']['tmp_name'], $image_Path3)){
    echo "<script>alert('Updated Successfully');</script>
      <script>window.location.href = 'editprod.php'</script>";
  }else{
   echo  "Not Insert Image";
   }
}

if ($img4 =="" ) {
  $sql="UPDATE product set name= '$name' ,descr ='$descr', info= '$info', price=$price, cate_id='$descrebtion' ,disc_id='$discount', SKU='$sku'  , size='$chkt'  , created_at='$created_at' where id=$id ";
  mysqli_query($conn, $sql);
}else {
  $Get_image_name4 = $_FILES['uploadfile4']['name'];
  $image_Path4 = "img/".basename($Get_image_name4);
  $sql="UPDATE product set img4='$Get_image_name4' , name= '$name' ,descr ='$descr', info= '$info', price=$price, cate_id='$descrebtion' ,disc_id='$discount', SKU='$sku' , size='$chkt' , created_at='$created_at' where id=$id ";
  mysqli_query($conn, $sql);
  if (move_uploaded_file($_FILES['uploadfile4']['tmp_name'], $image_Path4)){
    echo "<script>alert('Updated Successfully');</script>
      <script>window.location.href = 'editprod.php'</script>";
  }else{
   echo  "Not Insert Image";
   }
}

echo "<script>alert('Updated final Successfully');</script>
  <script>window.location.href = 'editprod.php'</script>";
}

كود update ^^

descrebtion  و discount هي FK 

 

  • 0
نشر
بتاريخ On 12‏/4‏/2022 at 21:31 قال ellylalla:

if (isset($_POST['submit'])) {

  $name=$_POST['name'];
  $descr=$_POST['descr'];
  $info=$_POST['info'];
  $price=$_POST['price'];
  $qty=$_POST['qty'];
  $sku=$_POST['SKU'];
  $si=$_POST['size'];
  $chkt=implode(",",$si);
  $descrebtion =$_POST['descrebtion'];
  $discount =$_POST['discount'];
  $created_at= date('Y-m-d H:i:s');
  $img_name = $_FILES['uploadfile1']['name'];
  $img_type = $_FILES['uploadfile1']['type'];
  $tmp_name = $_FILES['uploadfile1']['tmp_name'];

  $img_name2 = $_FILES['uploadfile2']['name'];
  $img_type2 = $_FILES['uploadfile2']['type'];
  $tmp_name2 = $_FILES['uploadfile2']['tmp_name'];

  $img_name3 = $_FILES['uploadfile3']['name'];
  $img_type3 = $_FILES['uploadfile3']['type'];
  $tmp_name3 = $_FILES['uploadfile3']['tmp_name'];

  $img_name4 = $_FILES['uploadfile4']['name'];
  $img_type4 = $_FILES['uploadfile4']['type'];
  $tmp_name4 = $_FILES['uploadfile4']['tmp_name'];


  $img_explode = explode(".",$img_name);
  $img_ext = end($img_explode);

  $img_explode2 = explode(".",$img_name2);
  $img_ext2 = end($img_explode2);

  $img_explode3 = explode(".",$img_name3);
  $img_ext3 = end($img_explode3);

  $img_explode4 = explode(".",$img_name4);
  $img_ext4 = end($img_explode4);





  $extension= ['png','jpeg','jpg','gif'];
  $Get_image_name = $_FILES['uploadfile1']['name'];
  $image_Path = "img/".basename($Get_image_name);
  $Get_image_name2 = $_FILES['uploadfile2']['name'];
  $image_Path2 = "img/".basename($Get_image_name2);
  $Get_image_name3 = $_FILES['uploadfile3']['name'];
  $image_Path3 = "img/".basename($Get_image_name3);
  $Get_image_name4 = $_FILES['uploadfile4']['name'];
  $image_Path4 = "img/".basename($Get_image_name4);


$sql ="INSERT INTO product(name,descr,info, price ,qty ,img1 ,img2 ,img3 ,img4 ,SKU, size,disc_id ,cate_id,created_at) VALUES ('$name','$descr' ,'$info', '$price','$qty' ,'$Get_image_name','$Get_image_name2' ,'$Get_image_name3' ,'$Get_image_name4' ,'$sku' ,'$chkt' ,'$discount','$descrebtion','$created_at')";
mysqli_query($conn,$sql);
//mysqli_query($conn,("ALTER TABLE `product` DROP FOREIGN KEY `cat`; ALTER TABLE `product` ADD CONSTRAINT `cat` FOREIGN KEY (`cate_id`) REFERENCES `productcategory`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; ALTER TABLE `product` DROP FOREIGN KEY `disc`; ALTER TABLE `product` ADD CONSTRAINT `disc` FOREIGN KEY (`disc_id`) REFERENCES `discount`(`id`) ON DELETE CASCADE ON UPDATE CASCADE"));


  if (move_uploaded_file($_FILES['uploadfile1']['tmp_name'], $image_Path)){
    echo "<script>alert('Uploaded Successfully');</script>
      <script>window.location.href = 'addprodect.php'</script>";
  }else{
   echo  "Not Insert Image";
   }
  if (move_uploaded_file($_FILES['uploadfile2']['tmp_name'], $image_Path2)){
    echo "<script>alert('Uploaded Successfully');</script>
      <script>window.location.href = 'addprodect.php'</script>";
  }else{
   echo  "Not Insert Image";
   }
  if (move_uploaded_file($_FILES['uploadfile3']['tmp_name'], $image_Path3)){
    echo "<script>alert('Uploaded Successfully');</script>
      <script>window.location.href = 'addprodect.php'</script>";
  }else{
   echo  "Not Insert Image";
   }
  if(move_uploaded_file($_FILES['uploadfile4']['tmp_name'], $image_Path4)){
    echo "<script>alert('Uploaded Successfully');</script>
      <script>window.location.href = 'addprodect.php'</script>";

  }else{
   echo  "Not Insert Image";
   }


   echo "<script>alert('Uploaded Successfully');</script>
     <script>window.location.href = 'addprodect.php'</script>";

}

كود insert  ^^ 


if (isset($_POST["update"])) {
$id= $_GET['id'];
$name=$_POST['name'];
$descr=$_POST['descr'];
$info=$_POST['info'];
$price=$_POST['price'];
$descrebtion=$_POST['descrebtion'];
$sku=$_POST['sku'];
 $siz=$_POST['size'];
 $discount =$_POST['discount'];
 $chkt=implode(",",$siz);
 $created_at= date('Y-m-d H:i:s');

  $img1=$_FILES["uploadfile1"]["name"];
  $img2=$_FILES["uploadfile2"]["name"];
  $img3=$_FILES["uploadfile3"]["name"];
  $img4=$_FILES["uploadfile4"]["name"];

  if ($img1 =="" ) {
    $sql="UPDATE product set  name= '$name' ,descr ='$descr', info= '$info', price=$price, cate_id='$descrebtion' ,disc_id='$discount', SKU='$sku' , size='$chkt'  , created_at='$created_at'  where id=$id ";
   mysqli_query($conn, $sql);
  }else {
    $Get_image_name = $_FILES['uploadfile1']['name'];
    $image_Path = "img/".basename($Get_image_name);
    $sql="UPDATE product set img1='$Get_image_name' , name= '$name' ,descr ='$descr', info= '$info', price=$price, cate_id='$descrebtion' ,disc_id='$discount', SKU='$sku'  , size='$chkt' , created_at='$created_at' where id=$id ";
    mysqli_query($conn, $sql);
    if (move_uploaded_file($_FILES['uploadfile1']['tmp_name'], $image_Path)){
      echo "<script>alert('Updated Successfully');</script>
        <script>window.location.href = 'editprod.php'</script>";
    }else{
     echo  "Not Insert Image";
     }
}

if ($img2 =="" ) {
  $sql="UPDATE product set name= '$name' ,descr ='$descr', info= '$info', price=$price, cate_id='$descrebtion' ,disc_id='$discount', SKU='$sku'  ,size='$chkt' , created_at='$created_at' where id=$id ";
mysqli_query($conn, $sql);
}else {
  $Get_image_name2 = $_FILES['uploadfile2']['name'];
  $image_Path2 = "img/".basename($Get_image_name2);
  $sql="UPDATE product set img2='$Get_image_name2' , name= '$name' ,descr ='$descr', info= '$info', price=$price, cate_id='$descrebtion' ,disc_id='$discount', SKU='$sku' , size='$chkt' , created_at='$created_at' where id=$id ";
  mysqli_query($conn, $sql);
  if (move_uploaded_file($_FILES['uploadfile2']['tmp_name'], $image_Path2)){
    echo "<script>alert('Updated Successfully');</script>
      <script>window.location.href = 'editprod.php'</script>";
  }else{
   echo  "Not Insert Image";
   }
}

if ($img3 =="" ) {
  $sql="UPDATE product set  name= '$name' ,descr ='$descr', info= '$info', price=$price, cate_id='$descrebtion' ,disc_id='$discount', SKU='$sku' , size='$chkt' , created_at='$created_at' where id=$id ";
mysqli_query($conn, $sql);
}else {
  $Get_image_name3 = $_FILES['uploadfile3']['name'];
  $image_Path3 = "img/".basename($Get_image_name3);
  $sql="UPDATE product set img3='$Get_image_name3' , name= '$name' ,descr ='$descr', info= '$info', price=$price, cate_id='$descrebtion' ,disc_id='$discount', SKU='$sku' , size='$chkt' , created_at='$created_at' where id=$id ";
  mysqli_query($conn, $sql);
  if (move_uploaded_file($_FILES['uploadfile3']['tmp_name'], $image_Path3)){
    echo "<script>alert('Updated Successfully');</script>
      <script>window.location.href = 'editprod.php'</script>";
  }else{
   echo  "Not Insert Image";
   }
}

if ($img4 =="" ) {
  $sql="UPDATE product set name= '$name' ,descr ='$descr', info= '$info', price=$price, cate_id='$descrebtion' ,disc_id='$discount', SKU='$sku'  , size='$chkt'  , created_at='$created_at' where id=$id ";
  mysqli_query($conn, $sql);
}else {
  $Get_image_name4 = $_FILES['uploadfile4']['name'];
  $image_Path4 = "img/".basename($Get_image_name4);
  $sql="UPDATE product set img4='$Get_image_name4' , name= '$name' ,descr ='$descr', info= '$info', price=$price, cate_id='$descrebtion' ,disc_id='$discount', SKU='$sku' , size='$chkt' , created_at='$created_at' where id=$id ";
  mysqli_query($conn, $sql);
  if (move_uploaded_file($_FILES['uploadfile4']['tmp_name'], $image_Path4)){
    echo "<script>alert('Updated Successfully');</script>
      <script>window.location.href = 'editprod.php'</script>";
  }else{
   echo  "Not Insert Image";
   }
}

echo "<script>alert('Updated final Successfully');</script>
  <script>window.location.href = 'editprod.php'</script>";
}

كود update ^^

descrebtion  و discount هي FK 

لم أجد في الكود أي خلل واضح ، لذلك هل يمكنك أن تتأكد بأن حقل id في جداول قاعدة البيانات يأخذ القيمة auto increment ليتم زيادة حقل id بمقدار 1 كل عملية إضافة . أيضا هل يمكنك إرفاق جداول قاعدة البيانات ؟ 

  • 0
نشر (معدل)
بتاريخ منذ ساعة مضت قال بلال زيادة:

لم أجد في الكود أي خلل واضح ، لذلك هل يمكنك أن تتأكد بأن حقل id في جداول قاعدة البيانات يأخذ القيمة auto increment ليتم زيادة حقل id بمقدار 1 كل عملية إضافة . أيضا هل يمكنك إرفاق جداول قاعدة البيانات ؟ 

حذفت الكلام اللي كنت حاطه هنا داخل textarea وضبط صار يضيف ويحدث بس ان شاء الله يكون هذا السبب مايعلق مره ثانيه 62578a6c6c6c4_--...thumb.png.d02585e809528f6231a849b30f6c55ec.png

 

‏لقطة الشاشة ١٤٤٣-٠٩-١٣ في ٥.٢٣.٢٦ ص.png

‏لقطة الشاشة ١٤٤٣-٠٩-١٣ في ٥.٢٣.٤٩ ص.png

تم التعديل في بواسطة ellylalla
  • 0
نشر
بتاريخ 5 ساعات قال ellylalla:

حذفت الكلام اللي كنت حاطه هنا داخل textarea وضبط صار يضيف ويحدث بس ان شاء الله يكون هذا السبب مايعلق مره ثانيه 

لم ترفق كود html لذلك ربما كان هناك مشكلة ما فيه ، ولكن هل حللت المشكلة ؟ 

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...