Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

displaying in forms data inserted into database

I created this table that part of it takes input from the user and save it in the database..

I'm trying to make the data put by the user in the tags remain shown. Basically the input form becoming both input/output source. Any help on how to do so?

switch ($selected){
    case 'University':
        $stmt = $conn->prepare("SELECT employees.afnumber,employees.name,employees.actualpost,university.brevet FROM employees,university WHERE employees.status='Employed' AND employees.afnumber=university.afnumber ORDER BY employees.afnumber DESC LIMIT :start,:end");
        $stmt->bindParam(':start', $pages->limit_start, PDO::PARAM_INT);
        $stmt->bindParam(':end', $pages->limit_end, PDO::PARAM_INT);
        $stmt->execute();
        $result = $stmt->fetchAll();
        $selectedtable  = "<form method='post' action=''>\n";
        $selectedtable .= "<table class='sortable'>\n<tr><th>Description</th><th>A</th><th>B</th><th>C</th><th>D</th></tr>\n";
        foreach($result as $row) {
            $selectedtable .= "<tr><th>Brevet</th><td><input type='text' name='Brevet1' style=' padding: 10px; margin-top:1px; border: solid 2px #c9c9c9; width:50px; height:2px;'></td><td>".$row[0]."</td><td>".$row[2]."</td><td>".$row[3]."</td></tr>
                       <tr><th>Baccalaureat/BT</th><td><input type='text' name='Baccalaureatbt' style=' padding: 10px; font-size:16px; margin-top:1px; border: solid 2px #c9c9c9; width:50px; height:2px;'></td><td>".$row[1]."</td><td>$row[2]</td><td>$row[3]</td></tr>
                       <tr><th>License/TS</th><td><input type='text' name='Licensets' style=' padding: 10px; margin-top:1px; border: solid 2px #c9c9c9; width:50px; height:2px;'></td><td>".$row[1]."</td><td>".$row[2]."</td><td>$row[3]</td></tr>
                       <tr><th>M1</th><td><input type='text' name='M1' style=' padding: 10px; margin-top:1px; border: solid 2px #c9c9c9; width:50px; height:2px;'></td><td>".$row[1]."</td><td>".$row[2]."</td><td>".$row[3]."</td></tr>
                       <tr><th>Master's Degree</th><td><input type='text' name='Mastersdegree' style=' padding: 10px; margin-top:1px; border: solid 2px #c9c9c9; width:50px; height:2px;'></td><td>".$row[1]."</td><td>".$row[2]."</td><td>".$row[3]."</td></tr>
                       <tr><th>PHD</th><td><input type='text' name='Phd' style=' padding: 10px; margin-top:1px; border: solid 2px #c9c9c9; width:50px; height:2px;'></td><td>".$row[1]."</td><td>".$row[2]."</td><td>".$row[3]."</td></tr>";

    }
    $selectedtable .= "</table>\n"; 
    $selectedtable .= "<input type='submit' name='submit' value='Submit' style='width:80px; height:30px; text-align:center; padding:0px;'>\n";
    $selectedtable .= "</form>\n";

        if(isset($_POST['submit']))
    {   $brevet1 = $_POST['Brevet1'];
        $baccalaureatbt = $_POST['Baccalaureatbt'];
        $licensets = $_POST['Licensets'];
        $m1 = $_POST['M1'];
        $mastersdegree = $_POST['Mastersdegree'];
        $phd = $_POST['Phd'];


     $sql1="SELECT Brevet1,Baccalaureatbt,Licensets,M1,Mastersdegree,Phd FROM university";
if ($result=mysqli_query($con,$sql1))
  {

  $rowcount=mysqli_num_rows($result);
  }
    if($rowcount==0)
     {
 $sql="INSERT INTO university(Brevet1,Baccalaureatbt,Licensets,M1,Mastersdegree,Phd) VALUES('$brevet1','$baccalaureatbt','$licensets','$m1','$mastersdegree','$phd')";
 $result = mysql_query($sql);
     }
     else
     {
 $sql2 = "UPDATE university SET Brevet1 = '$brevet1' , Baccalaureatbt = '$baccalaureatbt', Licensets = '$licensets', M1 = '$m1', Mastersdegree = '$mastersdegree', Phd = '$phd'";
 $result2 = mysql_query($sql2);
     }

    }


    break;
like image 839
dan Avatar asked Dec 31 '25 10:12

dan


1 Answers

You can set a value to each input like this :

<input type='text' name='Brevet1' value="<?php echo $_POST['brevet_1']; ?>">

With a ternary condition : echo (!empty($_POST['brevet_1']) ? $_POST['brevet_1'] : '');

EDIT

Fetch the data from database and set the value of input just like above

like image 79
wilson Avatar answered Jan 02 '26 00:01

wilson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!