Welcome Guest, Not a member yet? Register   Sign In
Regarding a Form Textfield updates a Database Field
#1

[eluser]Unknown[/eluser]
I have a question regarding what i'm doing wrong in this instance. ive been trying for days to solve this issue of wanting to OO PHP, and i thought about using codeigniter but instead ive stuck with Object Orientated PHP.

SO number 1: i have a controller that is setting a function for querying a database. which is simple.

like this:

Code:
function getCurrentMessage($strMessage)
{

$DBA = new DBAccessor("localhost","root","root", "laserwatch");
$DBA->dbConnect();
$sql = mysql_query("SELECT `tableScrollingMessage`.`strMessage` AS `strMessage` FROM `tableScrollingMessage`");
  
  while($row = mysql_fetch_assoc ($sql)) {
  extract($row);
  }
  
  $DBA->dbClose();
  return $strMessage;
  }

function messageSaved($currentMessage)
{
        
  $DBA = new DBAccessor("localhost","root","root", "laserwatch");
  $sql = 'UPDATE `tableScrollingMessage` SET strMessage='.$currentMessage.';';
       //Connect to the database and execute the query
  $DBA->dbConnect();
  $DBA->executeInsertQuery($sql);
  $DBA->dbClose();
}

in the GUI i am creating an object of getCurrentMessage and i'm trying to input that one single field from a table in the database into a textfield so that i can get the message and update the message

Code:
<?php
include ('AdminController.php');

$mesg = new AdminController;
$mesg->getCurrentMessage($strMessage);
$mesg1 = new AdminController;

print_r($_POST);
$mesg = $_POST['strMessage'];
$mesg1->getCurrentMessage($strMessage);
?>
<html>
<head></head>
<body bgcolor="#898989">    
<form id="adminMessage" name="adminMessage" method="post">

<input type=image src="images/setmessage.gif"  alt="setmessage" method="post"/ >
<input type="text" name=strMessage size="95" maxlength="95" value="<?php $mesg; ?>" />
        
</form>
</body>
</html>

i'm a little stumpted as to why the message wont appear in the textbox and why the submit button isnt updating. i've dont this before and it worked fine Sad
#2

[eluser]bigtony[/eluser]
If you're using CI, you need to go back to the drawing board and get more acquainted with MVC. Here's a very brief rundown.

Database operations should go in a Model (not a controller).
Views only contain HTML, apart from where it needs to embed data.
Controllers link the other bits together, but calling model functions to get data, passing data to the view, validating input, doing any updates, etc.

Have a run through the various tutorials to give you a better idea of how to hang it all together.




Theme © iAndrew 2016 - Forum software by © MyBB