hallo.
erstmal mal am anfang - mein script:
PHP-Code:
<?php
#-------------------------FUNKTIONEN---------------------------#
function useSQL($aktion)
{
$host = "";
$user = "";
$pass = "";
$db = "";
//connect
$con = mysql_connect($host,$user,$pass);
if( ! $con)
{ die("Connect Failed. SQLerror: " . mysql_error()); }
//db waehlen
mysql_select_db($db, $con)
or die ( "Konnte $db nicht oeffnen: " .mysql_error() );
//was soll getan werden
mysql_query($aktion, $con)
or die ( "Konnte mysql_query nicht ausführen: " .mysql_error() );
//verbindung trennen
mysql_close($con)
or die ( "Konnte close nicht ausführen: " .mysql_error() );
//ok
return true;
}
#------------------------------------------------------------------#
if ( ! isset($_REQUEST['submit'])) { $mitteilung = "Schreibe was rein! \n
"; }
if (isset($_REQUEST['submit']) && $_REQUEST['submit']=="hinzufuegen")
{
$tabName = "laj_artikel";
$query = "INSERT INTO ". $tabName . " (p_name,p_beschreibung,p_eh_preis,p_gh_preis,p_pr_preis)";
$query.= " VALUES ('".$_REQUEST['name']."', '".$_REQUEST['beschreibung']."', '".$_REQUEST['eh_preis']."', '".$_REQUEST['gh_preis']."', '".$_REQUEST['pr_preis']."')";
if(useSQL($query))
{
$mitteilung = "Daten wurden geschreiben! \n
".
"Query: $query
".
"Requests: ".$_REQUEST['name'].", ".$_REQUEST['beschreibung'].", ".
$_REQUEST['eh_preis'].", ".$_REQUEST['gh_preis'].", ".
$_REQUEST['pr_preis'];
}
}
?>
<html>
<head>
<title>Was möglich ist</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php print $mitteilung; ?>
<form action="<?php print $_SERVER['PHP_SELF']; ?>" method="post" name="produktFormular">
Neuen Artikel hinzufügen: </p>
<table width="400" border="0" cellspacing="0" cellpadding="3">
<tr>
<td width="163"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Name
des Artikels:</font></td>
<td width="225"> <input name="name" type="text" id="name"> </td>
</tr>
<tr>
<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Beschreibung
des Artikels:</font></td>
<td> <input name="beschreibung" type="text" id="beschreibung"> </td>
</tr>
<tr>
<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif"> Preis für:</font></td>
<td> </td>
</tr>
<tr>
<td align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Einzelhandel:</font></td>
<td> <input name="eh_preis" type="text" id="eh_preis"> </td>
</tr>
<tr>
<td align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Großhandel:</font></td>
<td> <input name="gh_preis" type="text" id="gh_preis"> </td>
</tr>
<tr>
<td align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Privatkunde:</font></td>
<td> <input name="pr_preis" type="text" id="pr_preis"> </td>
</tr>
</table>
<input name="submit" type="submit" id="submit" value="hinzufuegen">
</p>
</form>
</body>
</html>
so dann meine frage:
was muss ich unter dem fehler verstehen, was mache ich falsch?
Code:
Konnte mysql_query nicht ausführen: Duplicate entry '0' for key 1
mfg embee