Aperçu: update choix d'une table
Bonjour,
Je souhaite mise à jours selon le choix de table. J'ai crée une variable pour choisir le nom de table, et modifier la table. La modification s'effectue en écrivant le nom de table , mais avec la variable pour choisir une table, il y a un problème. j'ai besoin de votre aide merci.
<form method="post" name="formul" action="">
Nom table : <input type="text" id="texte1" name="texte1" value=" "/>
<input type="submit" id="ok" name="ok" value="Selectionner"/>
</form>
<?php
//error_reporting(0);
$c= mysql_connect('localhost','root','') or die ("connection impossible");
mysql_select_db('test', $c) or die ("connection impossible a la base");
$tab="";
if(isset ($_POST['ok']))
{
if(isset ($_POST['texte1']))
{
$tab = $_POST['texte1'];
$sql="select id, nom, prenom from ".$tab."";
$rs=mysql_query($sql,$c);
?><table align="center">
<tr>
<td>Nom </td>
<td>Prenom </td>
</tr>
<tr><td>Nom Table</td><td><input type="text" id="texte1" name="texte1" value="<?php if(isset($_POST['texte1'])) { echo $_POST['texte1'];} ?> "/></td></tr>
<form action="" method="post" name="formul">
<input type="hidden" name="modife" value="ok" />
<?php
$i=1;
while($data=mysql_fetch_array($rs)){ $nom=$data['nom']; $prenom=$data['prenom']; $id=$data['id']; $array[]=$id; //on peut remplacer $array par $_session...
?>
<tr><td><input type="text" name="<?php echo 'nom'.$id;?>" value="<?php echo $nom;?>" /></td>
<td><input type="text" name="<?php echo 'prenom'.$id;?>" value="<?php echo $prenom; ?>" /></td>
<?php $i=$i+1;
}
//echo $array[3];
?>
</tr>
<tr><td align="center"><input type="submit" name="modif" value="modif" /></td></tr></form>
</table>
<?php
for($t=0;$t<count($array);$t++){
if(isset ($_POST['modif'] )&& $_POST['modif']){
$id=$array[$t];// $_POST['id'.$array[$t]];
$nom=$_POST['nom'.$array[$t]];
$prenom=$_POST['prenom'.$array[$t]];
$update="UPDATE ".$tab." SET nom ='".$nom."',prenom='".$prenom."'WHERE id=".$array[$t];
$result=mysql_query($update,$c) or die( mysql_error() );
if(mysql_query($update)){
header("Location:updatetotal.php");
}else{
echo "pas de modification ";
}
}
}
}}
?>