0

I am trying to insert data using a form into my database, but I see the data being shown on the URL tab instead of my database table, here's my code can anyone tell me what is wrong with it please

<?php 
if(isset($_POST['submit'])){
 
$Coupon_title = $_POST['Coupon_title'];
$Coupon_cat = $_POST['Coupon_cat'];
$Coupon_code = $_POST['Coupon_code'];
$Coupon_value = $_POST['Coupon_value'];
$Coupon_status = $_POST['Coupon_status'];
$Coupon_date = $_POST['Coupon_date'];
$Coupon_limit = $_POST['Coupon_limit'];
$Coupon_used = $_POST['Coupon_used'];
$Coupon_price = $_POST['Coupon_price'];

$Coupon_image = $_FILES['Coupon_image']['name'];

$temp_name = $_FILES['Coupon_image']['temp_name'];

move_uploaded_file($temp_name,"Coupon_image/$Coupon_image");


$insert_coupon = "INSERT INTO coupon_master (Coupon_title,Coupon_cat,Coupon_code,Coupon_value,Coupon_status,Coupon_date,Coupon_limit,Coupon_used,Coupon_price) values('$Coupon_title','$Coupon_cat','$Coupon_code','$Coupon_value','$Coupon_status',NOW(),'$Coupon_limit','$Coupon_used','$Coupon_price',)";


if($run_coupon){
    echo "<script>alert('Product has been inserted successfully')</script>";
    echo "<script>window.open('insert_coupons.php','_self')</script>";
}

}
?>
Qirel
  • 25,449
  • 7
  • 45
  • 62
  • If you see your data in the url your `
    ` element is missing the `method="POST"` attribute. Please also read [How can I prevent SQL injection in PHP?](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php?rq=1) And you currently only set a string `$insert_coupon` with your query, you should also execute it somewhere
    – brombeer Jul 08 '20 at 09:16
  • I have put the method post but still no change – Hillary Okello Jul 08 '20 at 09:20
  • why do you have an extra comma(,) at the end of the query – Hirumina Jul 08 '20 at 09:24
  • let me remove it – Hillary Okello Jul 08 '20 at 09:26
  • 1
    You are not making any actual database query in your code, all you did was assign text to a variable named `$insert_coupon`. Please go and work through a beginner tutorial that explains the basics of this, it should not be our job to do that here. – CBroe Jul 08 '20 at 09:28
  • alright let me do that, Thank you – Hillary Okello Jul 08 '20 at 09:31
  • Thank you guys so much, I have made an actual database query and it works now. Thank you @CBroe – Hillary Okello Jul 08 '20 at 10:09

0 Answers0