Search code examples
phpstringfetch

I write code simple update and its run but name field value not proper fetch in input box, it is only fetch before white space string


<?php

include ('bcpdb.php'); if (isset($_POST['ok']));

$ern=$_POST['erno'];
$cname=$_POST['name'];
$cb=$_POST['branch'];
$cay=$_POST['admyear'];

$iq= "UPDATE stuinfo SET ERNO=$ern, SNAME='$cname',BRANCH='$cb',ADMYEAR='$cay' WHERE ERNO=$ern";
 $query=mysqli_query($con,$iq);


 mysqli_close($con);
 echo '<script> window.location="stulist.php"</script>';

<! DOCTYPE html>
<html>
<head><title>Update</title>
<script type="text/javascript" src="vForm.js"></script> 

</head>
<body>
<?php
include 'menu.php'; ?>
<?php
include 'bcpdb.php';

$erno=$_GET['erpass']; 
$nm=$_GET['npass']; 
$br=$_GET['bpass']; 
$ay=$_GET['ypass']; 

?>

<form name="f1" method="post" action="updatestu.php" onsubmit="return vForm()" >
     
    <table border=0>
    <tr><td colspan=2 ><center><h3>UPDATE STUDENT PROFILE</h3></center></td></tr>
    
    <tr>
        <td><label for="fname">Enrollnment No</label></td>
        <td><input type="text" name="erno" value=<?php echo "$erno"; ?> ></td>
        
    </tr>
    <tr>
        <td><label for="fname">Name</label></td>
        <td><input type="text" name="name" value=<?php echo "$nm"; ?>  ></td>
              
    <tr>
    <td><label for="fname">Branch</label></td>
        <td><input type="text" name="branch"  value=<?php echo "$br"; ?> ></td>
        
        </select></td>
    </tr>
    <tr>
        <td><label for="fname">Addmision Year</label></td>
        <td><input type="text" name="admyear" value=<?php echo "$ay"; ?> ></td>
    </tr>

    <td colspan=2 align=center>
    <button type="submit" name="ok">SUBMIT </button></td>
    </table>
    </form>

</body>
</html> 

?>enter image description here


Solution

  • You are using wrong PHP tag.

    <td><input type="text" name="admyear" value=<?php echo "$ay"; ?> ></td>
    

    It should be:

    <td><input type="text" name="admyear" value="<?php echo $ay; ?>" ></td>