sorry for the bulk of code :)
I need to input a client name in the input textfield name clientname then i need to output the client information from my database when i click a button name loadcliinfo. But the problem is i don't know how will i get the data inputted in clientname? so I used $_POST['clientname']. The code is not working.
the code i pasted below is located on the same file.
<tr>
<td width="6"></td>
<td width="155">Client Name<font color="#990000">*</font></td>
<td width="218"><input type="text" name="clientname" id="clientname" required= "required" class="forinput" value="<?php echo $clientname ?>"/></td>
<td width="148"><input type="button" name="loadcliinfo" value="Load Client Info" onClick="loadclientinfo()"/></td>
</tr>
<tr>
<td width="6"></td>
<td width="155">Client Address<font color="#990000">*</font></td>
<td width="218"><p id="clientadd" class="readonly"></p></td>
<td width="148">Contact Name<font color="#990000">*</font></td>
<td width="230"><p id="clientcontactname" class="readonly"></p></td>
<td width="8"></td>
</tr>
<tr class="shade">
<td width="6"></td>
<td width="155">Email Address<font color="#990000">*</font></td>
<td width="218"><p id="clientemail" class="readonly"></p></td>
<td width="148">Contact No<font color="#990000">*</font></td>
<td width="230"><p id="clientaddcontact" class="readonly"></p></td>
<td width="8"></td>
</tr>
my php code
<?php
$name=isset($_POST['clientname'])? $_POST['clientname'] : '';
I get the data using this statement isset($_POST['clientname'])? $_POST['clientname'] : '' and store it in the variable $name but when i output the variable its empty.
$csql="Select address, email, contactperson, contactno from client where name='$name'";
$result=$db->prepare($csql);
$result->execute();
while($resu= $result->fetch(PDO::FETCH_ASSOC))
{
echo '<input type="hidden" id="add" value="'.$resu['address'].'"/>';
echo '<input type="hidden" id="email" value="'.$resu['email'].'"/>';
echo '<input type="hidden" id="contactperson" value="'.$resu['contactperson'].'"/>';
echo '<input type="hidden" id="contactno" value="'.$resu['contactno'].'"/>';
}
?>
My loadclientinfo function
<script>
function loadclientinfo()
{
var add=document.getElementById("add");
var email=document.getElementById("email");
var contactperson=document.getElementById("contactperson");
var contactno=document.getElementById("contactno");
document.getElementById("clientadd").innerHTML = add.value;
document.getElementById("clientemail").innerHTML = email.value;
document.getElementById("clientcontactname").innerHTML = contactperson.value;
document.getElementById("clientcontact").innerHTML = contactno.value;
}
</script>
I think getting data from clientname is the problem. Is there any way i could get the data from clientname on the same page? thanks :D
$name=var_dump(isset($_POST['clientname']));but it output bool(false)