@mano7859
$reqSteName=mysql_query("SELECT name_User,first_User,age_User FROM Users WHERE id_users='1'") or die(mysql_error));
You do have a DB that's good but there's an error in your SELECT what error do you get?
public function insertData()
You are using object oriented programming (OOP).
Are you using any PHP Frameworks?
I haven't learn OOP yet, I still working and learn Smarty on my own.
At first I thought it was a foreach () issue but now after see the whole code it's more than that.
Was the array part of the problem above or you just create the array?
$tab1=array('nom_test=','prenom_test=','age_test=');
$exceptions=array('hide','submitForm');
Let's organized this:
1) This is the form:
<form action="#" method="post" enctype="multipart/form-data">
<label>Your name:</label><input type="text" name="name" /><br/>
<label>Your firstname:</label><input type="text" name="firstname" /><br/>
<input type="hidden" name="hide" value="test">
<label>Your age:</label><input type="text" name="age" /></br>
<input type="submit" name="submitForm" value="Submit">
</form>
2) This the Insert:
public function insertData($chpSql,$except){
$postForm='';
$listSql='';
if($this->type=='$_POST'){
foreach($_POST as $key=>$val){
if(!in_array($key,$except)){
$postForm .= "'".$val."',";
}
}
foreach($chpSql as $val){
$listSql.= $val.", ";
}
$reqInsert=mysql_query("INSERT INTO ".$this->table." (".substr($listSql,0,-2).") VALUE (".substr($postForm,0,-1).")") or die(mysql_error());
}
}
3) This is the Update:
$tab1=array('name','first','age');
$exceptions=array('hide','submitForm');
$test='';
foreach($tab1 as $val){
$test .=$val.'=';
foreach($_POST as $key=>$value){
if(!in_array($value,$exceptions)){
$test.=$value.'';
}
}
}
echo $test;
I've already create a php class to insert and I wanted to do the same with the update.
Since you used public function insertData() for Number 2.
You need to used public function update() for Number 3.
in order for it to work!