MySql - Fehler beim update!

Seven Secrets

Erfahrenes Mitglied
Hallo,

ich habe folgendes Script geschrieben, bei dem in die entpsrechenden Textfelder der Inhalt von einem Datensatz eingetragen wird. Danach sollen die bearbeiteten Werte gespeichert werde, was aus irgendeinem Grund nicht funktioniert.

PHP:
/* List the offers in the database for editng. */ 
Function Update_Listing () {
echo "<FORM METHOD=\"POST\" ACTION=\"offers-admin.php\">";
$result = mysql_query("SELECT uid, desguation, description, places, free, payment, age, worktime FROM care_offers ORDER BY desguation");
echo "<TABLE BORDER = 1 CELLPADDING = 2 CELLSPACING = 3>";
$total_rows = mysql_num_rows($result); $counter = 0;
echo "<TR><TD class=\"inhalt\"><B>Auswahl</TD>
		  <TD class=\"inhalt\"><B>Bezeichnung</TD>
		  <TD class=\"inhalt\"><B>Beschreibung</TD>
	  </TR>";
while($counter < $total_rows):
$uid = mysql_result($result,$counter,"uid");
echo "<TR><TD class=\"inhalt\"><div align=\"center\">";
echo "<INPUT TYPE=\"radio\" NAME=\"uid\" VALUE=\"$uid\">";
echo "</TD>";
echo "<TD WIDTH=\"160\" VALIGN=\"top\" class=\"inhalt\">";
echo mysql_result($result,$counter,"desguation");
echo "</TD>";
echo "<TD class=\"inhalt\"><div align=\"justify\">";
echo mysql_result($result,$counter,"description");
echo "</div><br>";
echo "<b>freie Stellen:</b> ". mysql_result($result,$counter,"places");
echo "<br><b>frei ab:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b> ". mysql_result($result,$counter,"free");
echo "<br><b>Bezahlung:&nbsp;&nbsp;&nbsp;</b> ". mysql_result($result,$counter,"payment");
echo "<br><b>Alter:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b> ". mysql_result($result,$counter,"age");
echo "<br><b>Arbeitszeit:&nbsp;&nbsp;&nbsp;</b> ". mysql_result($result,$counter,"worktime");
echo "<br><br></TD></TR>";
$counter = $counter + 1;
endwhile;
echo "</TABLE><br>";
echo "<INPUT TYPE = \"hidden\" NAME = \"state\" VALUE = \"Update_Now\">\n";  
echo "<INPUT TYPE=\"submit\" VALUE=\"Ausführen\">";
};

/* Save updates to database. */
Function Commit_Update ($uid, $desguation, $description, $places, $free, $payment, $age, $worktime){
$result = mysql_query("UPDATE care_offers SET desguation = '$desguation', description = '$description', places = '$places', free ='$free', paymnet ='$payment', age ='$age', worktime ='$worktime', WHERE uid = '".$uid."';");
$state = "";
Print_Offer($uid);
};

/* Save new contact information to database. */
Function Commit_Save ($desguation, $description, $places, $free, $payment, $age, $worktime) {
$result = mysql_query("INSERT INTO care_offers (desguation, description, places, free, payment, age, worktime) VALUES ('$desguation', '$description', '$places', '$free', '$payment', '$age', '$worktime')");
$uid = mysql_insert_id();
$state = "";
Print_Offer($uid);
};

/* This function displays the contact Information in a form.  It is used for both the create and update contact options. */
Function Offers_Form ($state, $uid){
if($state == "Update_Now"){
$state = "Commit_Update";
$result = mysql_query("SELECT * FROM care_offers WHERE uid = '".$uid."';");
$desguation = mysql_result($result,0,"desguation"); 
$description = mysql_result($result,0,"description"); 
$places = mysql_result($result,0,"places"); 
$free = mysql_result($result,0,"free"); 
$payment = mysql_result($result,0,"payment"); 
$age = mysql_result($result,0,"age"); 
$worktime = mysql_result($result,0,"worktime"); 
}
else {
$state = "Commit_Save";
}
echo "<div align=\"center\">Angebot eingeben </div>
<FORM METHOD = \"POST\" ACTION=\"offers-admin.php\">
<p align=\"center\"> 
  <INPUT TYPE = \"HIDDEN\" NAME = \"uid\" VALUE = \"$uid\">
  <INPUT TYPE = \"HIDDEN\" NAME = \"state\" VALUE = \"$state\">
</p>
<p align=\"center\">Bezeichnung:&nbsp&nbsp 
  <INPUT TYPE = \"TEXT\" NAME=\"desguation\" VALUE = \"$desguation\">
</p>
<p align=\"center\"> Beschreibung: &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<br>
  <BR>
  <textarea name=\"description\" VALUE = \"$description\" cols=\"35\" rows=\"5\">".$description."</textarea>
</p>
<p align=\"center\"> offene Stellen: 
  <INPUT TYPE = \"TEXT\" NAME=\"places\" VALUE = \"$places\">
</p>
<p align=\"center\"> frai ab: &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
  <INPUT TYPE = \"TEXT\" NAME=\"free\" VALUE = \"$free\">
</p>
<p align=\"center\"> Gehalt: &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
  <INPUT TYPE = \"TEXT\" NAME=\"payment\" VALUE = \"$payment\">
</p>
<p align=\"center\"> Alter: &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
  <INPUT TYPE = \"TEXT\" NAME=\"age\" VALUE = \"$age\">
</p>
<p align=\"center\"> Arbeitszeit: &nbsp&nbsp&nbsp&nbsp
  <INPUT TYPE = \"TEXT\" NAME=\"worktime\" VALUE = \"$worktime\">
  <br>
  <br>
  <INPUT TYPE=\"submit\" VALUE=\"Speichern\">
</p>";
};
 
Das kann eigentlich nicht sein, da mit dem if in der Funktion offers die Variable $state überprüft wird.

PHP:
Function Offers_Form ($state, $uid){ 
if($state == "Update_Now"){ 
$state = "Commit_Update"; 
$result = mysql_query("SELECT * FROM care_offers WHERE uid = '".$uid."';"); 
$desguation = mysql_result($result,0,"desguation");  
$description = mysql_result($result,0,"description");  
$places = mysql_result($result,0,"places");  
$free = mysql_result($result,0,"free");  
$payment = mysql_result($result,0,"payment");  
$age = mysql_result($result,0,"age");  
$worktime = mysql_result($result,0,"worktime");  
} 
else { 
$state = "Commit_Save"; 
} 
echo "...";

Und kontrolliert wird, ob bei der Funktion:

PHP:
Function Update_Listing () { 
echo "<FORM METHOD=\"POST\" ACTION=\"offers-admin.php\">"; 
....
echo "</TABLE><br>"; 
echo "<INPUT TYPE = \"hidden\" NAME = \"state\" VALUE = \"Update_Now\">\n";   
echo "<INPUT TYPE=\"submit\" VALUE=\"Ausführen\">"; 
};

Das State auf Update_Now gesetzt wurde. Somit müßte dies doch correkt ausgeführt werden oder?
 
Kann es vieleicht daran liegen, daß hier:

PHP:
if($state == "Update_Now"){ 
$state = "Commit_Update"; 
$result = mysql_query("SELECT * FROM care_offers WHERE uid = '".$uid."';"); 
$desguation = mysql_result($result,0,"desguation");  
$description = mysql_result($result,0,"description");  
$places = mysql_result($result,0,"places");  
$free = mysql_result($result,0,"free");  
$payment = mysql_result($result,0,"payment");  
$age = mysql_result($result,0,"age");  
$worktime = mysql_result($result,0,"worktime");  
} 
else { 
$state = "Commit_Save"; 
} 
echo "..."

Der Inhalt beim Update in die Variablen gespeichert wird, das was ich aber hier:

PHP:
echo "<div align=\"center\">Angebot eingeben </div> 
<FORM METHOD = \"POST\" ACTION=\"offers-admin.php\"> 
<p align=\"center\">  
  <INPUT TYPE = \"HIDDEN\" NAME = \"uid\" VALUE = \"$uid\"> 
  <INPUT TYPE = \"HIDDEN\" NAME = \"state\" VALUE = \"$state\"> 
</p> 
<p align=\"center\">Bezeichnung:&nbsp&nbsp  
  <INPUT TYPE = \"TEXT\" NAME=\"desguation\" VALUE = \"$desguation\"> 
</p> 
<p align=\"center\"> Beschreibung: &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<br> 
  <BR> 
  <textarea name=\"description\" VALUE = \"$description\" cols=\"35\" rows=\"5\">".$description."</textarea> 
</p> 
<p align=\"center\"> offene Stellen:  
  <INPUT TYPE = \"TEXT\" NAME=\"places\" VALUE = \"$places\"> 
</p> 
<p align=\"center\"> frai ab: &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 
  <INPUT TYPE = \"TEXT\" NAME=\"free\" VALUE = \"$free\"> 
</p> 
<p align=\"center\"> Gehalt: &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 
  <INPUT TYPE = \"TEXT\" NAME=\"payment\" VALUE = \"$payment\"> 
</p> 
<p align=\"center\"> Alter: &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 
  <INPUT TYPE = \"TEXT\" NAME=\"age\" VALUE = \"$age\"> 
</p> 
<p align=\"center\"> Arbeitszeit: &nbsp&nbsp&nbsp&nbsp 
  <INPUT TYPE = \"TEXT\" NAME=\"worktime\" VALUE = \"$worktime\"> 
  <br> 
  <br> 
  <INPUT TYPE=\"submit\" VALUE=\"Speichern\"> 
</p>";

in den Textfeldern dann eingebe nicht geändert und übernommen wird?
 
Okay, alles zurück, der Fehler muß hier liegen:

PHP:
Function Commit_Update ($uid, $desguation, $description, $places, $free, $payment, $age, $worktime){ 
$result = mysql_query("UPDATE care_offers SET desguation = '$desguation', description = '$description', places = '$places', free ='$free', paymnet ='$payment', age ='$age', worktime ='$worktime', WHERE uid = '".$uid."';"); 
$state = ""; 
Print_Offer($uid);

und zwar in der Updatefunktion! Denn wenn ich das nehme:
PHP:
Function Commit_Update ($uid, $desguation, $description, $places, $free, $payment, $age, $worktime){
echo $uid; echo $desguation; echo $description; echo $places; echo $free; echo $payment; echo $age; echo $worktime;
exit ();
Print_Offer($uid);

Quasi als blanke Anzeige, dann stehen die geänderten Werte da. Worann kann es liegen?
 
Okay, die Lösung war dann doch ganz einfach! Es war ein Buchstabendreher in den Zuardnung der Tabelle! Manchmal sieht man den Wald vor Bäumen nicht! Trotzdem Danke!
 
Zurück