Click here to Skip to main content
15,908,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to search from database table and display on the HTMl form but those values are not assigning to php declared variables

What I have tried:

<?php
    
    
if(isset($_POST['search']))
{
    
    $connect= mysqli_connect("localhost","root","1234","latgsjason");
    if (mysqli_connect_error()){
    echo"Failed to Connect";
    }
//    $result=mysqli_query($connect,"SELECT * FROM customer WHERE veh_regno='$_POST[V_Regno]'");
    $Vregno = $_POST['V_Regno'];
    $query="SELECT 'nic','fullname','address','contact','color' FROM customer WHERE 'veh_regno'=$Vregno LIMIT 1"; 
    $result=mysqli_query($connect,$query);

    while ($row=mysqli_fetch_array($result))
        {
            $VReg=$row['veh_regno'];
            $Nic=$row['nic'];
            $FName=$row['fullname'];
            $Address=$row['address'];
            $Contact=$row['contact'];
            $Color=$row['color'];
        }
        
        mysqli_free_result($result);
        mysqli_close($connect);
}
else
{
    $VReg="";
    $Nic="";
    $FName="";
    $Address="";
    $Contact="";
    $Color="";
}

?>


<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Manage Account</title>
        <link rel="stylesheet" type="text/css" href="CSS/Style SheetGeneral.css">
    </head>
<body>
<br><br><br>

<table background="Images/Back Ground Images/BG1.jpg" border="2" align="center" width ="825" height="820">

    <th align=center valign=center>

        <form action="ManageAccount.php" method="POST"/>

        <div class="textcenter1">
            <h2>Manage An Account</h2>
        </div>
        <br><br>

        <table border="0"; align="center" width ="655" height="550" >
        <tr>
            <td>
                VEHICLE REGISTRATION NUMBER :
            </td>
            <td>
                <input type="text" name="V_Regno" size="40" value="<?php echo $VReg; ?>">
            </td>
        </tr>
        
        <tr>
            <td>
                NATIONAL ID :
            </td>
            <td>
                <input type="text" name="Nic"  size="40" value="<?php echo $Nic; ?>">
            </td>
        </tr>
        
        <tr>
            <td>
                FULL NAME :
            </td>
            <td>
                <input type="text" name="F_Name"  size="40" value="<?php echo $FName; ?>">
            </td>
        </tr>
        
        <tr>
            <td>
                ADDRESS :
            </td>
            <td>
                <input type="text" name="Address" size="40" value="<?php echo $Address; ?>">
            </td>
        </tr>
        
        <tr>
            <td>
                TELEPHONE NUMBER/MOBILE NUMBER :
            </td>
            <td>
                <input type="text" name="Contact" size="40" value="<?php echo $Contact; ?>">
            </td>
        </tr>
        
        <tr>
            <td>
                COLOR :
            </td>
            <td>
                <input type="text" name="Color" size="40" value="<?php echo $Color; ?>">
            </td>
        </tr>
        
<tr>
<td>
NIC Attachment :<select name="NicChk">
                <option selected="" value="">(New Document?)</option>
                <option value="yes">YES</option>
                <option value="no">NO</option>
                </select>
</td>
<td>
    <input type="file" name="Nic_Img" accept="image/*">
</td>
</tr>
<tr>
<td>
Registration Certificate :  <select name="RCcheck">
                            <option selected="" value="">(New Document?)</option>
                            <option value="yes">YES</option>
                            <option value="no">NO</option>
                            </select>
</td>
<td>
    <input type="file" name="Reg_Cer" accept="image/*">
</td>
</tr>

<tr>
<td></td>
<td>
    <input align="left" type="image" src="Images/Buttons/button_search.png" alt="button" name="search" value="Search" width="110" height="50"/>
</form> 
        
 <!--if submit button and reset button in same <form> will perform the formvalidation which leads the reset button also work as a submit button(wont reset anything)-->
 
 <form action="UpdateAccount.php" method="POST"/>
    <input align="center" type="image" src="Images/Buttons/button_update.png" alt="" name="reset" value="reset" width="110" height="50"/>
</td>
</tr>

</form>
 
</table>


</th>
</table>
<br><br>

</body>
</html>
Posted
Updated 16-Jul-17 0:46am
v2

1 solution

If nothing else you have some typo...
PHP
while ($row=mysqli_fetch_array($result)) // $row here
PHP
$Nic=$raw['nic'];
$FName=$raw['fullname'];
$Address=$raw['address'];
$Contact=$raw['contact'];
$Color=$raw['color']; // and $raw here
 
Share this answer
 
v2
Comments
Member 13049972 16-Jul-17 5:09am    
i changed like this too still there are error messages
Kornfeld Eliyahu Peter 16-Jul-17 5:19am    
Changed what? You still using $row and $raw!!!
Member 13049972 16-Jul-17 6:12am    
<?php


if(isset($_POST['search']))
{

$connect= mysqli_connect("localhost","root","1234","latgsjason");
if (mysqli_connect_error()){
echo"Failed to Connect";
}
// $result=mysqli_query($connect,"SELECT * FROM customer WHERE veh_regno='$_POST[V_Regno]'");
$Vregno = $_POST['V_Regno'];
$query="SELECT 'nic','fullname','address','contact','color' FROM customer WHERE 'veh_regno'=$Vregno LIMIT 1";
$result=mysqli_query($connect,$query);
if (!$result) {
printf("Error: %s\n", mysqli_error($connect));
exit();
}
while ($row=mysqli_fetch_array($result))
{
$VReg=$row['veh_regno'];
$Nic=$row['nic'];
$FName=$row['fullname'];
$Address=$row['address'];
$Contact=$row['contact'];
$Color=$row['color'];
}

mysqli_free_result($result);
mysqli_close($connect);
}
else
{
$VReg="";
$Nic="";
$FName="";
$Address="";
$Contact="";
$Color="";
}

?>
Member 13049972 16-Jul-17 6:12am    
but now there are no any error messages but the fields are fill with messages like this

Notice: Undefined variable: VReg in C:\xampp\htdocs\LATGS\ManageAccount.php on line 73

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900