hey guys,
I have been working on a data storage script.. storing into DB, using OOP php. I have a problem passing data to the initiator, and from there to the class. If i add data in the initiator then those data are parsed succefully, but i cannot pass data from an HTML form, using post.
More details below..
this is the initiator script..
//init.Store.php
<?php
include 'dataStore.class.php';
$user = new userData();
$user->storeData($name, $email, $text);
//$user->storeData('name', 'email', 'text'); - if i add simple values then these will be parsed to the class
?>
the class script..
<?php
class userData {
public $name;
public $email;
public $text;
function userData(){
$this->host = 'localhost';
$this->uname = 'root';
$this->pword = '1111';
$this->dbname = 'teststorage';
$this->dbtable = 'userData';
}
function storeData($name, $email, $text){
$this->dbConnect = mysql_connect($this->host, $this->uname, $this->pword);
if (!$this->dbConnect) die("Could not connect " . mysql_error());
mysql_select_db($this->dbname);
$sql_query = "INSERT INTO $this->dbtable VALUES('', '$name', '$email', '$text')";
$result = mysql_query($sql_query);
if ($result){
echo "Data storage succesful <br/> . $result";
}
else {
echo "Error <br/>" . mysql_error();
}
mysql_close($sql_query);
}
}
?>
and this is the form where i send data to the initiator script..
<form method='post' action="init.Store.php">
<div class="data">
<div><input type="text" name="name" class="name"/></div>
<div><input type="text" name="email" class="email"/></div>
<div><input type="text" name="text" class="text"></div>
<div><input type="submit" name="submit" value="Submit"></div>
</div>
</form>
Can someone please tell me what am i doing wrong? why can't I send data to the initiator script?
Thank you in advance.