Saturday, 22 February 2020

Dynamic Combobox

Dear all

Using this code a combo box can be dynamically populated using php code.

-------------------------
<?php
if($con=mysql_connect("localhost","root",""))
{
//echo"connected";
}
else
{
//echo"not connected";
}
mysql_select_db("fjc");



//start combo box code.

function showcombobox($tablename,$valuefield,$showfield)
{

$sql="select $valuefield,$showfield from $tablename";
echo $sql;
$data=mysql_query($sql);
$retvalue='';
while($row=mysql_fetch_array($data))
{

$retvalue=$retvalue."<option value='".$row[$valuefield]."'>".$row[$showfield]."</option>";

}

return $retvalue;
}

//start combo box code.

?>
-------------------------------

Sunday, 9 February 2020

MVC in core PHP

Hi All,
This is a post dedicated for creating MVC program using core PHP

////View

<html>
<head>
<form action="controller.php" method=post>
<b>  NAME <input type="text" name="name">
ADDRESS <input type="text" name="address">
COURSE<input type="text" name="course"></b>
<input type="submit" name=btnsub value="OK">
</form>
</html>


/////Controller

<?php
include ('model.php');
 if(isset($_POST["btnsub"]))
 {
echo "entered";
 $con=mysql_connect("localhost","root","");
 mysql_select_db("mvc",$con);
 $s=new student();
 $name=$_POST['name'];
 $address=$_POST['address'];
 $course=$_POST['course'];
 $s->insert($name,$address,$course);
  //header('location: model.php');



 }
 ?>


/////Model

<?php
class student {
function __construct() {

}

function insert($name,$address,$course ) {
echo "insert worked";
$sql=("insert into student values('$name','$address','$course')");
mysql_query($sql);

}
}
?>