Einfügen Ich versuche, Daten aus einfachen Registerformular in MySQL einzufügen. Ich habe meine DB auf Amazon AWS RDS gehostet, mit DBeaver, um es zu bearbeiten. Wenn ich den Code ausführe, bekomme ich folgendeIch kann nicht herausfinden, warum mein PHP nicht in MySQL DB
affected_rows. "Daten in die Datenbank eingefügt."; } else {echo "Ein Fehler ist aufgetreten. Die Elemente wurden nicht hinzugefügt."; } $ db-> schließen(); ?>
Wie behebe ich das? Ist meine PHP falsch? Ich bin verwirrt, ob ich MySQLi verwenden kann oder nicht, wie würde ich das feststellen? Ich nehme an, Amazon RDS MySQL ist kompatibel. Hier
<?php
// create short variable names
$name=$_POST['name'];
$birthdate=$_POST['birthdate'];
$email=$_POST['email'];
$password=$_POST['password'];
$address=$_POST['address'];
$city+$_POST['city'];
if (!get_magic_quotes_gpc()) {
$name = addcslashes($name);
$birthdate = addslashes($birthdate);
$email = addcslashes($email);
$password = addcslashes($password);
$address = addcslashes($address);
$city = addcslashes($city);
}
$host='xxxxxx'
$user='admin'
$password='xxxxx'
$dbname='users'
@ $db = mysqli_connect($host,$user,$password,$dbname)
if (mysqli_connect_errno()) {
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
// Execute the query
$query = "INSERT INTO vestorinfo (name,birthdate,email,password,address,city)
VALUES ('$_POST[name]','$_POST[birthdate]','$_POST[email]','$_POST[password]','$_POST[address]','$_POST[city]')";
$result = mysqli_query($query)
or die ("Couldn't execute query."};
if ($result) {
echo $db->affected_rows." data inserted into database.";
} else {
echo "An error has occurred. The items were not added.";
}
$db->close();
?>
ist die Form aus der HTML-Seite
<div id="registerform">
<form action="php/registerprocess.php" method="post" class="form-horizontal">
<fieldset>
<!-- Form Name -->
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="name">Name</label>
<div class="col-md-4">
<input id="name" name="name" placeholder="Your name" class="form-control input-md" required="" type="text">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="birthdate">Birth Date</label>
<div class="col-md-4">
<input id="birthdate" name="birthdate" placeholder="07/04/1950" class="form-control input-md" required="" type="text">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="email">Email</label>
<div class="col-md-4">
<input id="email" name="email" placeholder="" class="form-control input-md" required="" type="text">
</div>
</div>
<!-- Password input-->
<div class="form-group">
<label class="col-md-4 control-label" for="password">Password</label>
<div class="col-md-4">
<input id="password" name="password" placeholder="" class="form-control input-md" required="" type="password">
<span class="help-block">Must be >= 8 characters including at least 1 number</span>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="email">Address</label>
<div class="col-md-4">
<input id="address" name="address" placeholder="" class="form-control input-md" required="" type="text">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="email">City</label>
<div class="col-md-4">
<input id="city" name="city" placeholder="" class="form-control input-md" required="" type="text">
</div>
</div>
</div>
</fieldset>
Es sieht aus wie Ihre PHP nicht laufen und warum nicht die realen Fehler Echo aus? –
Sie sind weit offen für die SQL-Injektion. Da Sie mysqli verwenden, nutzen Sie [prepared statements] (http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) und [bind_param] (http://php.net/ Handbuch/de/mysqli-stmt.bind-param.php). Dies wird alle lästigen Zitate beheben, die Sie möglicherweise haben. Überprüfen Sie auch auf mysqli Fehler auf dem Weg. – aynber
'$ city + $ _ POST ['city'];' sollte '$ city = $ _ POST ['city'];' Auch nachdem Sie alle diese Werte gesetzt haben, greifen Sie auf die $ _POST-Werte in Ihrer Einfügung zurück ? –