Der folgende Code fügt zwei Datensätze in meine Datenbank ein, aber ich möchte nur einen Datensatz einfügen. Warum wird die Zeile zweimal eingefügt?SQL in PHP Einfügen von zwei Zeilen anstelle von einer
<?
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$i=1;
while($i<=1)
{
if (isset($_POST['submit']))
{
$sql="INSERT INTO customers
(company, salutation, first_name,
last_name, phone, email, fax,
street, town, county, postcode,
type, notes)
VALUES
('$_POST[company]',
'$_POST[salutation]',
'$_POST[first_name]',
'$_POST[last_name]',
'$_POST[phone]',
'$_POST[fax]',
'$_POST[email]',
'$_POST[street]',
'$_POST[town]',
'$_POST[county]',
'$_POST[postcode]',
'$_POST[type]',
'$_POST[notes]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
}
$i++;
}
?>
Zuallererst sollten Sie Ihre Eingabedaten auf jeden Fall mit etwas wie mysql_real_escape_string; Zweitens, warum die While-Schleife? –
Und vielleicht eine Bestellung in Ihrem Code: P – kiewic
$ _POST [Firma] sollte sein $ _POST ['Firma'] – dar7yl