and what do you have now?
All I need to do is : onclick firstly I need to populate data if it exists and there only I need to create a form to enter those data. Now if the user wishes to update the data which exists then he needs to fill the form, and now on submission of this form I need to delete the previous data and update with the new one.
Any suggestions please.??
On click of existing card details I need to show existing data as shown in the image. As you can see that there are input type text boxes where user can put new card details.
Now all I want is when I enter the data it must update/delete previous record.
then make a form that contains the ID + all the fields to update and on submit do update table(cols, ...) values(?, ...) where id = ?
$sql = "SELECT * FROM bta_card_details WHERE tgi_id = '".$username."'";
$result = mysqli_query($conn, $sql);
if($result){
echo '<form id="myForm" action = "bta_generate_request.php" method = "POST" onsubmit = insertDetails();><h1>Your Card Details are:</h1><table id="msgs"><caption><b>Important Messages</b></caption><thead><tr><th>Card Number</th><th class="wider">Card Expiry Date</th><th>Bank Name</th></tr></thead><tbody>';
while($row = mysqli_fetch_assoc($result)) {
echo '<tr><td width="120">' .$row["bta_card_num"]. '</td><td width="120">' .$row["bta_card_expiry_dt"]. '</td><td contenteditable="true">' .$row["bta_card_bankName"]. '</td></tr>';
}
echo '<div id="input1" style="margin-bottom:4px;" class="clonedInput">
Card Number: <input type="text" name="name1" id="name1" />
Expiry Date: <input type="date" name="date" id="expirydate" />
Bank Name: <input type="text" name="name2" id="bankName" />
<input type="hidden" name="bta_submit" id="bta_submit" value="Submit" style="width:60px;"/>
</div> </tbody></table>
</form>';
}
function insertDetails(){
if((isset($_POST['bta_submit'])) || (isset($_POST['exists'])) || (isset($_POST['cardDetails']))) {
$cardNum = $_POST['name1'];
$expiryDate = $_POST['expirydate'];
$bankName = $_POST['bankName'];
$sql = mysqli_query($link, "INSERT INTO bta_card_details (`bta_card_num`,`bta_card_expiry_dt`,`bta_card_bankName`,`tgi_id`,`status`) VALUES('".$cardNum."', '".$expiryDate."', '".$bankName."', '".$username."', '1')");
echo "INSERT INTO bta_card_details (`bta_card_num`,`bta_card_expiry_dt`,`bta_card_bankName`,`tgi_id`,`status`) VALUES('".$cardNum."', '".$expiryDate."', '".$bankName."', '".$username."', '1')";
if($sql){
echo "Inserted";
}
else{
echo "Failed";
}
}
}
nice that it works for you?
It is not working. I have written the code in this form but I am not quite sure as to where am i going wrong.
And what does that mean? What did you try to find the error by yourself? What did you try to solve your problem? You should reflect that other people don’t sit in front of your screen, don’t have insights of your brain and can’t reproduce anything as you are only posting random snippets that depend other codes.
I will post the files you can check it. Below is the div where I am clicking on showdata function to fetch card details from database.
<div id="Cardform"><input type="checkbox" class="group" name="card" id ="cardDetails" onclick = "showData();">Existing Currency Card</div>
JS File
function showData()
{
var $checks = $('input:checkbox.group');
$.ajax({
type:'POST',
url:'ajaxData.php',
success: function(data){
if(!$checks.filter(':checked').length == 0) {
console.log(data);
$('#exists').html(data);
$('#exists').show();
}
else{
$('#exists').hide();
}
},
error: function(){
alert(" No Card details");
}
});
}
My ajaxdata.php file is as shown above which I will re-post it and you can see it:
$sql = "SELECT * FROM bta_card_details WHERE tgi_id = '".$username."'";
$result = mysqli_query($conn, $sql);
if($result){
echo '<form id="myForm" action = "bta_generate_request.php" method = "POST" onsubmit = insertDetails();><h1>Your Card Details are:</h1><table id="msgs"><caption><b>Important Messages</b></caption><thead><tr><th>Card Number</th><th class="wider">Card Expiry Date</th><th>Bank Name</th></tr></thead><tbody>';
while($row = mysqli_fetch_assoc($result)) {
echo '<tr><td width="120">' .$row["bta_card_num"]. '</td><td width="120">' .$row["bta_card_expiry_dt"]. '</td><td contenteditable="true">' .$row["bta_card_bankName"]. '</td></tr>';
}
echo '<div id="input1" style="margin-bottom:4px;" class="clonedInput">
Card Number: <input type="text" name="name1" id="name1" />
Expiry Date: <input type="date" name="expirydate" id="expirydate" />
Bank Name: <input type="text" name="bankName" id="bankName" />
<input name="submit" type="button" value="Submit">
</div> </tbody></table>
</form>';
}
else{
echo "Failed";
}
This is the file where I am inserting i.e., bta_generate_request.php file
And what now? There’s big bunch of dependencies i don’t have on any of my machines. You still don’t tell what you problem is and just ran over the questions i asked.
I have been trying to insert the data that I enter into the form. I get no errors as well but its still no inserting into database. I tried running the code in different page, there the data is inserting. You can see the img below img
use Prepared Statements.
WOOOOOOHHHH no. This should not be done under any circumstance! This is a security break waiting to happen and should not continue. There is far too much at risk storing what you want to store, and since you cant get an insert statement to work, you do NOT have the knowledge on the other security aspects needed to do this type of thing. There are PCI compliance requirements, security requirements, hosting requirements, all of which you do not have enough knowledge of to store any kind of payment details. Use a service like Stripe and stop doing what you are trying to do for the sake of everyone that may use this!!!
I know that but it is required I too can’t help as I am working as per requirements. So please if anyone could try to see whats wrong or any suggestions for improvement in the code would be thankful.
start asking for errors:
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
and use Prepared Statements, it’s much clearer.
Insert is usually for the first add of a new row. If you want to update the table entry then use UPDATE:
Thanks it’s already working now. Thanks all