PHP und MySQL! Dateneintragfehler!

Seven Secrets

Erfahrenes Mitglied
Hallo, ich habe folgendes Script:

Code:
/* The main screen. Printed when $state is empty. */
Function Main_Menu () {
echo "Es gibt folgende Möglichkeiten:";
echo "<FORM METHOD=\"POST\" ACTION=\"offers.php\">";
echo "<INPUT CHECKED TYPE=\"radio\" NAME=\"state\" VALUE=\"Listing\"><B>Anzeige der Stellenangebote.<BR>";
echo "<INPUT TYPE=\"radio\" NAME=\"state\" VALUE=\"Create\"><B>Ein neues Angebot eingeben.<P>";
echo "<INPUT TYPE=\"submit\" VALUE=\"Make New\">";
echo "";
};

/* List the offers in the database. */ 
Function Listing () {
echo "<CENTER><H2>Stellenangebote<P>";
mysql_connect($hosthame,$user,$password);
$result = mysql("care_offers","SELECT uid, desguation, discription FROM care_offers ORDER BY desguation");
echo "<TABLE BORDER = 10 CELLPADDING = 2>";
$total_rows = mysql_numrows($result); $counter = 0;
echo "<TR><TD><B>Bezeichnung<TD><B>Beschreibung";
while($counter < $total_rows):
$uid = mysql_result($result,$counter,"uid"); echo "<TR><TD>\n";
echo "<A HREF=offers.php?uid=$uid=Print_Contact>"; 
echo mysql_result($result,$counter,"discription");
echo "\n";
echo "<TD>\n";
echo mysql_result($result,$counter,"discription"); echo "<TD>\n";
$counter = $counter + 1;
endwhile;
echo "";
};

/* Save updates to database.  Call Print_Contact to list new information for updated contact entry. */
Function Commit_Update ($uid, $desguation, $ddiscription){
mysql_connect($hosthame,$user,$password);
$result = mysql("care_offers","UPDATE care_offers SET desguation = '$desguation',
discription = '$discription' WHERE uid = $uid");
$state = "";
Print_Contact($uid);
};

/* Save new contact information to database.  Call Print_Contact to display new contact entry. */
Function Commit_Save ($desguation, $discription) {
mysql_connect($hostname,$user,$password);
$result = mysql("care_offers","INSERT INTO care_offers (desguation, discription) VALUES ('$desguation', '$discription')");
$new_uid = mysql_insert_id();
$state = "";
Print_Offer($new_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"){
$state = "Commit_Update";
$result = mysql("care_offers","SELECT * FROM care_offers WHERE uid = $uid");
$last_name = mysql_result($result,0,"desguation"); 
$first_name = mysql_result($result,0,"discription"); 
}
else {
$state = "Commit_Save";
}
echo "<CENTER><H2>Angebot eingeben<P>\n";
echo "<FORM METHOD = \"POST\" ACTION=\"offers.php\">\n";
echo "   <INPUT TYPE = \"HIDDEN\" NAME = \"uid\" VALUE = \"$uid\">\n";
echo "   <INPUT TYPE = \"HIDDEN\" NAME = \"state\" VALUE = \"$state\">\n";
echo "   Bezeichnung: <BR><INPUT TYPE = \"TEXT\" NAME=\"desguation\" \n";
echo "   VALUE = \"$desguation\" MAXLENGTH = 20><BR>\n";
echo "   Beschreibung: <BR><INPUT TYPE = \"TEXT\" NAME=\"discription\"\n";
echo "   VALUE = \"$discription\" MAXLENGTH = 750 SIZE = 75><BR>\n";
echo "   <CENTER><INPUT TYPE=\"submit\" VALUE=\"Submit Contact\">\n"; 
echo "\n";
};


/* Print address and comments for a contact.  Also give option to update. */
Function Print_Offer ($uid) {
mysql_connect($hosthame,$user,$password);
echo "<TABLE BORDER = 10 CELLPADDING = 2>";
echo "<TR><TD>Sie haben folgende Daten eingetragen:";
echo "<TD>";
$result = mysql("care_offers","SELECT * FROM care_offers WHERE uid = $uid");
echo "<TR><TD>Bezeichnung";
echo "<TD>";
echo mysql_result($result,0,"desguation"); echo "\n";
echo "<TR><TD>Beschreibung";
echo "<TD>";
echo mysql_result($result,0,"discription");
echo "\n";
echo "\n";
echo "";
echo "<FORM METHOD = \"POST\" ACTION=\"offers.php\">";
echo "<INPUT TYPE = \"HIDDEN\" NAME = \"uid\" VALUE = \"$uid\">\n";
echo "<INPUT TYPE = \"HIDDEN\" NAME = \"state\" VALUE = \"Update\">\n"; 
echo "<CENTER><INPUT TYPE=\"submit\" VALUE=\"Update Contact Information\">";
echo "<FORM METHOD = \"POST\" ACTION=\"offers.php\">"; 
echo "<CENTER><INPUT TYPE=\"submit\" VALUE=\"Return To Main Menu\">";
echo "\n";
};

/* The main loop.  Call functions based on the value of $state, which gets set via a hidden INPUT TYPE. */

switch($state):
case "";
Main_Menu();
break;
case "Listing";
Listing();
break;
case "Create";
Offers_Form($state, $uid);
break;
case "Update";
Contact_Form($state, $uid);
break;
case "Commit_Update";
Commit_Update($uid, $desguation, $ddiscription);
break;
case "Commit_Save";
Commit_Save($desguation, $discription);
break;
case "Print_Offer";
Print_Offer($uid);
endswitch;
?>

Nur leider verstehe ich nicht, warum er nicht in die angegebene Datenbank schreibt! :confused:
 
Ich habe meinen Fehler gefunden, das ist aber allerdings mit einem neuen Verbunden. Was muß ich dabei unternehmen?

Die SQL-Anweisung gibt mir folgenden fehler aus: Fehler: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
 
Kaldorias hat gesagt.:
kann mich ja irren (5 uhr morgens...) aber ich sehe nur die Funktion mysql_connect(), aber mysql_select_db() nicht.


Du hats Recht, aber das verursacht nicht den Fehler!
Ich glaube das hat was mit dem Benutzer zu tun mit dem du dich Connectest. Was hast du als Host und was als User Angegeben?

Gruß BSA
 
Also die mysql_connect gibt es in der Function Listing! Ich habe auch einfach mal ein Script getestet, bei dem nur connectet wird und dann einfach die Liste der Einträge wiedergeben sollte. Dabei kam dan der oben genannte Fehler. Es ist ein Server bei 1 und 1! Woran kann es liegen?
 
Hallo!

Was soll dieses eigentlich bewirken?
Code:
$result = mysql("care_offers","SELECT........
Laut php.net gibt es keine Funktion mysql().

Gruss Dr Dau
 
Okay, das ist mein Fehler! HAbe eben nur mal wieder die hälfte umgesetzt. Habe das ganze jetzt ausgetauscht gegen:

Code:
$conn_id = mysql_connect($hosthame, $user, $password);
mysql_select_db("dbo144533750",$conn_id);
$result = mysql_query("SELECT uid, desguation, discription FROM care_offers");

Das sieht dann auch logischer aus?! So! Nun ist für mich die Frage, warum kommt trozdem der Fehler: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) Habe ich da noch irgendeinen Fehler?
 
Es tut mir leid, dass ich thread jetzt doch nochmal hoch holen muß, aber mir ist leider noch nicht geholfen bei meinem Problem. Ich ahbe das script jetzt so geändert:

PHP:
<HTML>
<?PHP

/* Wichtige Variablen */
$hostname = "localhost";
$password = "pass";
$user = "user";

/* The main screen. Printed when $state is empty. */
Function Main_Menu () {
echo "Es gibt folgende Möglichkeiten:";
echo "<FORM METHOD=\"POST\" ACTION=\"offers.php\">";
echo "<INPUT CHECKED TYPE=\"radio\" NAME=\"state\" VALUE=\"Listing\"><B>Anzeige der Stellenangebote.<BR>";
echo "<INPUT TYPE=\"radio\" NAME=\"state\" VALUE=\"Create\"><B>Ein neues Angebot eingeben.<P>";
echo "<INPUT TYPE=\"submit\" VALUE=\"Make New\">";
echo "";
};

/* List the offers in the database. */ 
Function Listing () {
echo "<CENTER><H2>Stellenangebote<P>";
$conn_id = mysql_connect($hosthame, $user, $password);
mysql_select_db("dbo144533750",$conn_id);
$result = mysql_query("SELECT uid, desguation, discription FROM care_offers"); //ORDER BY desguation
echo "<TABLE BORDER = 10 CELLPADDING = 2>";
$total_rows = mysql_numrows($result); $counter = 0;
echo "<TR><TD><B>Bezeichnung<TD><B>Beschreibung";
while($counter < $total_rows):
$uid = mysql_result($result,$counter,"uid"); echo "<TR><TD>\n";
echo "<A HREF=offers.php?uid=$uid=Print_Contact>"; 
echo mysql_result($result,$counter,"discription");
echo "\n";
echo "<TD>\n";
echo mysql_result($result,$counter,"discription"); echo "<TD>\n";
$counter = $counter + 1;
endwhile;
echo "Fehler: " . mysql_error();
};

/* Save updates to database.  Call Print_Contact to list new information for updated contact entry. */
Function Commit_Update ($uid, $desguation, $ddiscription){
mysql_connect($hosthame,$user,$password);
$result = mysql_query("care_offers","UPDATE care_offers SET desguation = '$desguation',
discription = '$discription' WHERE uid = $uid");
$state = "";
Print_Contact($uid);
};

/* Save new contact information to database.  Call Print_Contact to display new contact entry. */
Function Commit_Save ($desguation, $discription) {
mysql_connect($hostname,$user,$password);
$result = mysql_query("care_offers","INSERT INTO care_offers (desguation, discription) VALUES ('$desguation', '$discription')");
$new_uid = mysql_insert_id();
$state = "";
Print_Offer($new_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"){
$state = "Commit_Update";
$result = mysql_query("care_offers","SELECT * FROM care_offers WHERE uid = $uid");
$last_name = mysql_result($result,0,"desguation"); 
$first_name = mysql_result($result,0,"discription"); 
}
else {
$state = "Commit_Save";
}
echo "<CENTER><H2>Angebot eingeben<P>\n";
echo "<FORM METHOD = \"POST\" ACTION=\"offers.php\">\n";
echo "   <INPUT TYPE = \"HIDDEN\" NAME = \"uid\" VALUE = \"$uid\">\n";
echo "   <INPUT TYPE = \"HIDDEN\" NAME = \"state\" VALUE = \"$state\">\n";
echo "   Bezeichnung: <BR><INPUT TYPE = \"TEXT\" NAME=\"desguation\" \n";
echo "   VALUE = \"$desguation\" MAXLENGTH = 20><BR>\n";
echo "   Beschreibung: <BR><INPUT TYPE = \"TEXT\" NAME=\"discription\"\n";
echo "   VALUE = \"$discription\" MAXLENGTH = 750 SIZE = 75><BR>\n";
echo "   <CENTER><INPUT TYPE=\"submit\" VALUE=\"Submit Contact\">\n"; 
echo "\n";
};


/* Print address and comments for a contact.  Also give option to update. */
Function Print_Offer ($uid) {
mysql_connect($hosthame,$user,$password);
echo "<TABLE BORDER = 10 CELLPADDING = 2>";
echo "<TR><TD>Sie haben folgende Daten eingetragen:";
echo "<TD>";
$result = mysql_query("care_offers","SELECT * FROM care_offers WHERE uid = $uid");
echo "<TR><TD>Bezeichnung";
echo "<TD>";
echo mysql_result($result,0,"desguation"); echo "\n";
echo "<TR><TD>Beschreibung";
echo "<TD>";
echo mysql_result($result,0,"discription");
echo "\n";
echo "\n";
echo "";
echo "<FORM METHOD = \"POST\" ACTION=\"offers.php\">";
echo "<INPUT TYPE = \"HIDDEN\" NAME = \"uid\" VALUE = \"$uid\">\n";
echo "<INPUT TYPE = \"HIDDEN\" NAME = \"state\" VALUE = \"Update\">\n"; 
echo "<CENTER><INPUT TYPE=\"submit\" VALUE=\"Update Contact Information\">";
echo "<FORM METHOD = \"POST\" ACTION=\"offers.php\">"; 
echo "<CENTER><INPUT TYPE=\"submit\" VALUE=\"Return To Main Menu\">";
echo "\n";
};

/* The main loop.  Call functions based on the value of $state, which gets set via a hidden INPUT TYPE. */

switch($state):
case "";
Main_Menu();
break;
case "Listing";
Listing();
break;
case "Create";
Offers_Form($state, $uid);
break;
case "Update";
Contact_Form($state, $uid);
break;
case "Commit_Update";
Commit_Update($uid, $desguation, $ddiscription);
break;
case "Commit_Save";
Commit_Save($desguation, $discription);
break;
case "Print_Offer";
Print_Offer($uid);
endswitch;
?>

Nur leider bringt das Script nicht den Zugriff auf die Datenbank. Sind meine SQL-Befehle überhaubt richtig?
 
Zuletzt bearbeitet:
Zurück