Hi i am a newbie trying to learn php programming. I am facing a challenge inserting data into a database . when i click on <input id ="" type="image" name="button4" src="img/Zoona.JPG" alt="Submit" style="width:25%" />
nothing happens. I have four submit images each attached to an event. Were could i be getting it wrong?.You help will be much appreciated.Here is my code below
<?php
session_start();
if(!isset($_SESSION['phonenumber']) || empty($_SESSION['phonenumber'])){
header("location: login.php");
exit;
}
$amount = "";
$amount_err = "";
$charge = "";
$airtelcode = "";
$airtel = "";
$mtnlcode = "";
$mtn = "";
$zamtellcode ="";
$zamtel ="";
$zoonacode = "";
$zoona = "";
$percent = 8;
if($_SERVER["REQUEST_METHOD"] == "button1"){
if(empty(trim($_POST["amount"]))){
$amount_err = "Please enter amount.";
} else {$_POST["charge"]=($percent/100) *$amount;
}
$amount = trim($_POST["amount"]);
$airtelcode = $_POST["airtelcode"];
$charge = $_POST["charge"];
if(empty($amount_err)){
$sql = "INSERT INTO transdetails ( amount,platform ,platformcode, charge, ) VALUES (?, ?, ?, ?)";
if($stmt = mysqli_prepare($link, $sql)){
mysqli_stmt_bind_param($stmt, "ssss", $param_amount, $param_platform, $param_platformcode, $param_charge);
$param_amount = $amount;
$param_platform = $airtel;
$param_platformcode = $airtelcode;
$param_charge = $charge;
if(mysqli_stmt_execute($stmt)){
header("location: send.php");
} else{
echo "Something went wrong. Please try again later.";
}
}
}
} else if($_SERVER["REQUEST_METHOD"] == "button2"){
if(empty(trim($_POST["amount"]))){
$amount_err = "Please enter amount.";
} else {$_POST["charge"]=($percent/100) *$amount;
}
$amount = trim($_POST["amount"]);
$mtncode = $_POST["mtncode"];
$charge = $_POST["charge"];
if(empty($amount_err)){
$sql = "INSERT INTO transdetails ( amount,platform ,platformcode, charge, ) VALUES (?, ?, ?, ?)";
if($stmt = mysqli_prepare($link, $sql)){
mysqli_stmt_bind_param($stmt, "ssss", $param_amount, $param_platform, $param_platformcode, $param_charge);
$param_amount = $amount;
$param_platform = $mtn;
$param_platformcode = $mtntelcode;
$param_charge = $charge;
if(mysqli_stmt_execute($stmt)){
header("location: send.php");
} else{
echo "Something went wrong. Please try again later.";
}
}
}
}else if($_SERVER["REQUEST_METHOD"] == "button3"){
if(empty(trim($_POST["amount"]))){
$amount_err = "Please enter amount.";
}else {$_POST["charge"]=($percent/100) *$amount;
}
$amount = trim($_POST["amount"]);
$zamtelcode = $_POST["zamtelcode"];
$charge = $_POST["charge"];
if(empty($amount_err)){
$sql = "INSERT INTO transdetails ( amount,platform ,platformcode, charge, ) VALUES (?, ?, ?, ?)";
if($stmt = mysqli_prepare($link, $sql)){
mysqli_stmt_bind_param($stmt, "ssss", $param_amount, $param_platform, $param_platformcode, $param_charge);
$param_amount = $amount;
$param_platform= $zamtel;
$param_platformcode = $zamtellcode;
$param_charge = $charge;
if(mysqli_stmt_execute($stmt)){
header("location: send.php");
} else{
echo "Something went wrong. Please try again later.";
}
}
}
} else if($_SERVER["REQUEST_METHOD"] == "booton4"){
if(empty(trim($_POST["amount"]))){
$amount_err = "Please enter amount.";
}else {$_POST["charge"]=($percent/100) *$amount;
}
$amount = trim($_POST["amount"]);
$zoonacode = $_POST["zoonacode"];
$charge = $_POST["charge"];
if(empty($amount_err)){
$sql = "INSERT INTO transdetails(amount, platform ,platformcode, charge, ) VALUES (?, ?, ?, ?)";
if($stmt = mysqli_prepare($link, $sql)){
mysqli_stmt_bind_param($stmt, "ssss", $param_amount, $param_platform, $param_platformcode, $param_charge);
$param_amount = $amount;
$param_platform = $zoona;
$param_platformcode = $zoonacode;
$param_charge = $charge; if(mysqli_stmt_execute($stmt)){
header("location: send.php");
} else{echo "Something went wrong. Please try again later.";
}
}
}
mysqli_close($link);
}
?>