Creating a web app using mvc and codeigniter. In the view, on the click of a button it calls a javascript method. This method should take the source of 3 images as parameters, and pass them to a controller method. The controller method then turns them into a single $record and passes it to a function in the model, which will then insert the record contents into a database.
View button:
<input type="submit" class="btn btn-primary" value="Assemble bot" onclick="insertAssembled()"></input>
Javascript function:
function assemble(var head, var body, var legs) {
var head = document.getElementById("HeadImage".src);
var body = document.getElementById("BodyImage".src);
var legs = document.getElementById("FeetImage".src);
// call controller function here, passing head body and legs
}
Controller method:
public function insertAssembled($head, $body, $legs) {
//Build record and send to saveBot
$record['id'] = 1;
$record['head'] = $head;
$record['body'] = $body;
$record['legs'] = $legs;
$this->Robotsdata->saveBot($record);
}
Model method (very rough, help not needed just trying to pass parameters):
public function saveBot($record) {
$con = mysql_connect("localhost","root@localhost","");
mysql_select_db("factory", $con);
$bot_id = $_POST['id'];
$bot_head = $_POST['head'];
$bot_body = $_POST['body'];
$bot_legs = $_POST['legs'];
$query = "INSERT INTO `factory`.`assembledbots` ('id', 'head', 'body', 'legs') "
. "VALUES ('$bot_id', '$bot_head', '$bot_body', '$bot_legs');";
mysql_query($query);
mysql_close($con);
}