Create Page: Final Project
<link href="../../../Resource/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="../../../Resource/css/style.css" rel="stylesheet">
</head>
<body>
<div align="center">
<h4>Add Your Hobby's</h4>
<br>
<form id="bg" style="text-align: center" action="store.php" method="post"class="form-inline">
<div class="form-group">
<label for="Enter Name Here">Enter Name</label>
<input required="required" autofocus=""autofocus" type="text" name="name" class="form-control" id="Enter Name Here" placeholder="Enter Name">
</div><br><br>
<div class="form-group">
<label for="Enter email Here">Select Hobby's</label>
<input type="checkbox" name="hobby[]" />Cricket
<input type="checkbox" name="hobby[]"/>Football
<input type="checkbox" name="hobby[]"/>Hocky
</div><br><br>
<button type="submit" class="btn btn-default">Save</button>
<button type="submit" class="btn btn-default">Save & Add Again</button>
<button type="reset" class="btn btn-default">Reset</button>
</form>
<br>
<a class="btn btn-link" href="javascript:history.go(-1)">Back</a> <a class="btn btn-link" href="index.php">Go To List</a> <a class="btn btn-link" href="javascript:history.go(-2)">Go To Project Page</a>
</div>
</body>
</html>
i want to pass data via checkbox. but this format is not right. how can i change it? please give the right format of it.
Store Page:
<?php
//ini_set('display_errors','Off');
include_once("../../../vendor/autoload.php"); //using relative path
//include_once($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'AtomicProject'.DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.'autoload.php'); //using absolute path
use \App\BITM\SEIP106611\Hobby\Hobby;
$hobby = new Hobby($_POST);
$hobby->store();
i want to pass data via checkbox. but this format is not right. how can i change it? please give the right format of it.
Class Page:
<?php
namespace App\BITM\SEIP106611\Hobby;
use \App\BITM\SEIP106611\Utility\Utility;
class Hobby {
public $id = "";
public $name = "";
public $hobby = "";
//public $created = "";
///public $modified = "";
// public $created_by = "";
// public $modified_by = "";
// public $deleted_at = ""; //soft delete
public function __construct($data = false){
$this->name = $data['name'];
$this->hobby = $data['hobby'];
}
public function index(){
$hobbys = array();
$conn = mysql_connect("localhost","root","") or die("Cannot connect database.");
$lnk = mysql_select_db("finalproject") or die("Cannot select database.");
$query = "SELECT * FROM `hobbys`";
$result = mysql_query($query);
while($row = mysql_fetch_object($result)){
$hobbys[] = $row;
}
return $hobbys;
}
public function store(){
$conn = mysql_connect("localhost","root","") or die("Cannot connect database.");
$lnk = mysql_select_db("finalproject") or die("Cannot select database.");
$query = "INSERT INTO `finalproject`.`hobbys` ( `name`,`hobby`) VALUES ( '".$this->name."','".$this->hobby."')";
$result = mysql_query($query);
if($result){
$_message = "Name is added successfully.";
}else{
$_message = "There is an error while saving data. Please try again later.";
}
Utility::redirect('index.php');
}
}
?>
i want to pass data via checkbox. but this format is not right. how can i change it? please give the right format of it.
Aucun commentaire:
Enregistrer un commentaire