There is actually 2 problems here that i have yet to solve. The 1st problem is that when i click on the button 'next' i would like it to update my database and proceed to the next form ("newexpertise.php") at the same time. However i can only put in ("Newcustomer") in the which is my existing form in order for it to insert new customer when i click next. if i were to change the action to ("newexpertise"), it will bring me to the next page but will not insert the new data for me. Below are my codes which shows the label and textbox of inserting a new customer.
<form action = NewCustomer.php method="post">
<?php
include('CSS.php');
include('DB.php');
?>
<span class =wordtab>Name</span> <input name = newname id = 'newname' type='text'/> <br>
<span class =wordtab>IC</span><input name = newic id = 'newic' type='text'/><br>
<span class =wordtab>Number</span><input name = newnumber id = 'newnumber' type='text'/><br>
<span class =wordtab>Nationality</span><input name = newnationality id = 'newnationality' type='text'/><br>
<span class =wordtab>Status</span>
<select name = 'newstatus' id = newstatus>
<option value="Interested">Interested</option>
<option value='Not Interested'>Not Interested</option>
</select><br>
<span class =wordtab>Remarks</span><input name = newremarks id = 'newremarks' type='text'/><br>
So now when i click on the button next, it will check if the fields are empty, if it is not, it will insert the following data. alert('$message');"; }
else
{
$addquery = "INSERT INTO Particulars (Particulars_ID, Name, Identification_Number, Number, Nationality, Status, Remarks)
VALUES(LAST_INSERT_ID(),'$_POST[newname]', '$_POST[newic]','$_POST[newnumber]','$_POST[newnationality]','$_POST[newstatus]','$_POST[newremarks]')";
if ($connect->query($addquery) === TRUE)
{
}
else
{
echo "Error updating record: " . $connect->error;
}
}
}
?>
<br><br>
and here are my buttons. i have tried to included the onclick function inside the next button but it does not work.
<input type="submit" id="Next" name="Next" value = "Next" onclick="location.href='newexpertise.php';">
<br><br>
<input type="button" onclick="location.href='index.php';" value="Back to CRM" />
</form>
My second problem is that i want to store the particulars_id into a variable. As you can see in my $addquery, my id is autoincreament so i had to use LAST_INSERT_ID() in order to add in the next id. However, i do not know how to store that current id into a variable. Thanks a load!:)
Aucun commentaire:
Enregistrer un commentaire