php.de

Zurück   php.de > Webentwicklung > Datenbanken

Datenbanken SQL und Co

Antwort
 
LinkBack Themen-Optionen Thema bewerten
Alt 26.02.2005, 18:17  
Gast
 
Beiträge: n/a
Standard [Erledigt] Schreiben in DB geht nicht

Ich habe ein großes Problem. Ich mir eine Art Gästebuch gebastelt und jetzt schreibt die datei Änderungen nicht in die Datenbank. Hier sind mal die Codes:

index_gb.php
PHP-Code:
<?php
echo "<div align='center'><h1>Gästebuch</h1></div>";
echo 
"<form action='gb_start.php'>";
$connection=mysql_connect("localhost","root","*****");
$gb_auslesen="select * from gast";
$ergebnis=mysql_db_query("db_gb",$gb_auslesen,$connection);
while(list(
$name,$hp,$email,$icq,$msg)=mysql_fetch_array($ergebnis))
{
echo 
"<table width='40%' border='1' align='center' bgcolor='#EEEEEE'>
  <tr>
    <td>
      <table width='100%' border='0' bgcolor='#CCCCCC'>
        <tr>
          <th>
            <div align='left'>Name: "
.$name."</div>
          </th>
          <td width='50'>
            <div align='right'>"
;

if(
$email != "") echo "[email='".$email."'][img]bilder/email.gif[/img][/email] ";

if(
$hp != "") echo "[url='http://".$hp."'][img]bilder/home.gif[/img][/url]";

echo 
"      </div>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td>"
.$msg."</td>
  </tr>
</table>

"
;
}
mysql_close($connection);
echo 
"<div align='center'><input type='submit'  value='Eintrag erstellen'></input></div>";
?>


gb_start.php
PHP-Code:
<?php
echo "<form action='gb_ende.php' method='POST'>";

echo 
"<table width='40%' align='center' bgcolor='#CCCCCC'>
    <tr>
           <td align='center'>[b]Gästebucheintrag erstellen[b]</td>
         </tr>
     </table>

"
;

echo 
"<table width='40%' align='center' bgcolor='#EEEEEE'>
    <tr>
           <td>Name: </td>
           <td><input typ='text' name='name' size='25' maxlength='50'></input></td>
         </tr>
         <tr>
           <td>Homepage: </td>
           <td><input typ='text' name='hp' size='25' maxlength='50'> (ohne http:// )</input></td>
         </tr>
         <tr>
           <td>e-mail: </td>
           <td><input typ='text' name='email' size='25' maxlength='50'></input></td>
         </tr>
         <tr>
           <td>Icq: </td>
           <td><input typ='text' name='icq' size='25' maxlength='9'></input></td>
         </tr>
         <tr>
           <td>Nachricht: </td>
           <td><textarea name='msg' cols='25' rows='7'></textarea></td>
         </tr>
      </table>


   <div align='center'><input type='submit' value='Absenden'>  </input>
   <input type='reset'  value='Löschen'></input></div>"
;
?>


ende_gb.php
PHP-Code:
<?php
echo "<form action='index_gb.php'>";

$name=$_POST[name];
$hp=$_POST[hp];
$email=$_POST[email];
$icq=$_POST[icq];
$msg=$_POST[msg];

$connection=mysql_connect("localhost""root""*****");
$sqlbefehl="insert into gast values ($name, $hp, $email, $icq, $msg)";

mysql_db_query("db_gb"$sqlbefehl$connection);
mysql_close($connection);

echo 
"<table width='40%' border='1' align='center' bgcolor='#EEEEEE'>
  <tr>
    <td>
      <table width='100%' border='0' bgcolor='#CCCCCC'>
        <tr>
          <th>
            <div align='left'>Name: "
.$name."</div>
          </th>
          <td width='50'>
            <div align='right'>"
;

if(
$email != "") echo "[email='".$email."'][img]bilder/email.gif[/img][/email] ";

if(
$hp != "") echo "[url='http://".$hp."'][img]bilder/home.gif[/img][/url]";

echo 
"      </div>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td>"
.$msg."</td>
  </tr>
</table>

"
;



echo 
"<div align='center'><input type='submit' value='Zurück zum Gästebuch'></input></div>";
?>
Ich weis leider nicht wo der fehler liegt, da ich auch keine Fehlermeldung bekomme.
Vielleicht kann mir jemand helfen.
  Mit Zitat antworten
Sponsor Mitteilung
PHP Code Flüsterer

Registriert seit: 21.08.2005
Beiträge: 4682
PHP-Kenntnisse:
Fortgeschritten

Alt 26.02.2005, 18:20  
Erfahrener Benutzer
 
Registriert seit: 09.03.2004
Beiträge: 601
Webunni.de
Webunni.de eine Nachricht über ICQ schicken
Standard

vielleicht machst du auch einfach mal ein mysql_error() dahin
__________________
yeah montag ab nach holland
Webunni.de ist offline   Mit Zitat antworten
Alt 26.02.2005, 18:24  
Gast
 
Beiträge: n/a
Standard

16.14. Warum soll ich nicht SELECT * schreiben?
http://www.php-faq.de/q/q-sql-select.html

mysql_db_query ist veraltet, siehe

http://de3.php.net/manual/de/functio...-select_db.php
http://de3.php.net/manual/de/function.mysql-query.php

Gruß
phpfan
  Mit Zitat antworten
Alt 28.02.2005, 00:58  
Gast
 
Beiträge: n/a
Standard

ich hab die datei gb_ende.php jetzt also abgeänder wie folgt:

PHP-Code:
<?php
echo "<form action='index_gb.php'>";

$name=$_POST[name];
$hp=$_POST[hp];
$email=$_POST[email];
$icq=$_POST[icq];
$msg=$_POST[msg];

$connection=mysql_connect("localhost""root""*****") or die (mysql_error());
$sqlbefehl="insert into gast (name, hp, email, icq, msg) values ($name, $hp, $email, $icq, $msg)";

mysql_select_db("db_gb"$connection) or die (mysql_error());
mysql_query($sqlbefehl$connection) or die (mysql_error());
mysql_close($connection) or die (mysql_error());

echo 
"<div align='center'>

Folgendes wurde ins Gästebuch geschrieben:</p></div>"
;

echo 
"<table width='40%' border='1' align='center' bgcolor='#EEEEEE'>
  <tr>
    <td>
      <table width='100%' border='0' bgcolor='#CCCCCC'>
        <tr>
          <th>
            <div align='left'>Name: "
.$name."</div>
          </th>
          <td width='50'>
            <div align='right'>"
;

if(
$email != "") echo "[email='".$email."'][img]bilder/email.gif[/img][/email] ";

if(
$hp != "") echo "[url='http://".$hp."'][img]bilder/home.gif[/img][/url]";

echo 
"      </div>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td>"
.$msg."</td>
  </tr>
</table>

"
;


echo 
"<div align='center'><input type='submit' value='Zurück zum 

Gästebuch'></input></div>"
;
?>

wenn ich jetzt was eingeb bekomme ich die fehlermeldung:

Unknown column 'testname' in 'field list'

leider ist mein englisch nicht besonders und ich weiß mit der fehler meldung nix anzufangen. könnt ihr mir da noch weiter helfen???
  Mit Zitat antworten
Alt 28.02.2005, 08:15  
Erfahrener Benutzer
 
Registriert seit: 18.09.2003
Beiträge: 13.598
PHP-Kenntnisse:
Fortgeschritten
imported_Ben ist zur Zeit noch ein unbeschriebenes Blatt
Standard

der Thread wurde auf Wunsch geschlossen:
http://phpfriend.de/ftopic33498.html

-------
Probleme mit dem Englischen:
http://dict.leo.org/

Kurz: Die Spalte "testname" gibt es nicht!
imported_Ben ist offline   Mit Zitat antworten
Alt 28.02.2005, 08:25  
Gast
 
Beiträge: n/a
Standard

thx fürs schließen.

was hab ich dann falsch gemacht??? testuser soll er ja in die spalte name eintragen. ist ja das input vom formular. hab ich da einen befehl falsch verwendet???
  Mit Zitat antworten
Alt 28.02.2005, 08:32  
Erfahrener Benutzer
 
Registriert seit: 18.09.2003
Beiträge: 13.598
PHP-Kenntnisse:
Fortgeschritten
imported_Ben ist zur Zeit noch ein unbeschriebenes Blatt
Standard

Gib uns mal per
Code:
echo '<pre>';
echo $sql;
echo '</pre>';
die SQL-Anweisung .. und eventuell merkst Du dadurch auch schon selbst, woran es hakt.
Wenn Dir gesagt wird, dass es die Tabellenspalte in der Tabelle nicht gibt .. na .. was hast Du dann falsch gemacht?
imported_Ben ist offline   Mit Zitat antworten
Alt 28.02.2005, 14:28  
Gast
 
Beiträge: n/a
Standard

also jetzt bekomme ich folgende meldung:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@home.de, 106498719, testnachricht)' at line 1

tja ich verstehe zwar den inhalt, das also meine syntax falsch sind. aber wo bitte??? ich bin noch ein neuling.

also derzeit schaut die datei so aus:

PHP-Code:
<?php
echo "<form action='index_gb.php'>";

$name=$_POST[name];
$hp=$_POST[hp];
$email=$_POST[email];
$icq=$_POST[icq];
$msg=$_POST[msg];

$connection=mysql_connect("localhost""root""*****") or die (mysql_error());
$sqlbefehl="insert into gast (name, hp, email, icq, msg) values ($name, $hp, $email, $icq, 

$msg)"
;

mysql_select_db("db_gb"$connection) or die (mysql_error());
mysql_query($sqlbefehl$connection) or die (mysql_error());
mysql_close($connection) or die (mysql_error());

echo 
"<div align='center'>

Folgendes wurde ins Gästebuch geschrieben:</p></div>"
;

echo 
"<table width='40%' border='1' align='center' bgcolor='#EEEEEE'>
  <tr>
    <td>
      <table width='100%' border='0' bgcolor='#CCCCCC'>
        <tr>
          <th>
            <div align='left'>Name: "
.$name."</div>
          </th>
          <td width='50'>
            <div align='right'>"
;

if(
$email != "") echo "[email='".$email."'][img]bilder/email.gif[/img][/email] ";

if(
$hp != "") echo "[url='http://".$hp."'][img]bilder/home.gif[/img][/url]";

echo 
"      </div>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td>"
.$msg."</td>
  </tr>
</table>

"
;


echo 
"<div align='center'><input type='submit' value='Zurück zum 

Gästebuch'></input></div>"
;
echo 
'<pre>'
echo 
$sql
echo 
'</pre>';
?>
@Ben: Thx für die hilfe bis jetzt.
  Mit Zitat antworten
Alt 28.02.2005, 15:47  
Gast
 
Beiträge: n/a
Standard

habs endlich gefunden.

statt:
PHP-Code:
<?php
$sqlbefehl
="insert into gast (name, hp, email, icq, msg) values ($name, $hp, $email, $icq, $msg)"
?>
gehört:
PHP-Code:
<?php
$sqlbefehl
="insert into gast (name, hp, email, icq, msg) values ('$name', '$hp', '$email', '$icq', '$msg')"
?>
thx an alle die mir geholfen haben.

thread kann geschlossen werden.
  Mit Zitat antworten
Antwort


Themen-Optionen
Thema bewerten
Thema bewerten:

Forumregeln
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are an
Gehe zu

Besucher kamen über folgende Suchanfragen bei Google auf diese Seite
\gästebucheintrag erstellen\ \name\ \e-mail\ \icq\, input typ=\text\ width

Alle Zeitangaben in WEZ +2. Es ist jetzt 05:36 Uhr.




Powered by vBulletin® Version 3.7.2 (Deutsch)
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Aprilia-Forum, Aquaristik-Forum, Liebeskummer-Forum, Zierfisch-Forum, Geizkragen-Forum

Creative Commons License
Dieser Inhalt ist unter einer Creative Commons-Lizenz lizenziert.