Hallo Ich habe Probleme beim Einfügen von Formulardaten in eine MySQL-Datenbank. Ich habe den Code unten, weil ich nicht einmal sicher bin, wo ich anfangen soll, das Problem herauszufinden. Die Datei unten ist discuss.php, die eine Homepage für ein Diskussionsforum ist, das ich zu implementieren versuche. Das Formular erscheint nach einem Klick und dann sollte es die Formulardetails in POST speichern und von dort in die Datenbank einfügen!Formular modal Einreichung gleiche Datei zu MySql
<table>
<tr>
<td id="discuss_nav">
<ul class="nav nav-pills">
<li><a id="general" href="#general">General</a></li>
<li><a id="parks" href="#parks">Dog Parks</a></li>
<li><a id= "events" href="#events">Events</a></li>
<li><a id="questions" href="#questions">Q&A</a></li>
<li><a id="sophos" href="#sophos">Sophos</a></li>
<li ><button id="newpost" type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal" href="#newpost">New Post</button></li>
</ul>
</td>
<td>
<div id="laptop"><p id="discuss_intro">Here you can chat with fellow Sophos dog lovers, or just people who love Sophos and their dogs. To get started, click on the discussion topics to see older posts or create a new post to start some conversation. Happy chatting!</p></div>
<div id="success_parent"></div>
</td>
<td>
<div id="success_child"></div>
</td>
<tr>
</table>
<?php
if (isset ($_POST['submit']) && $_POST['submit']=='Add To Records') {
// check if the form was submitted
//do db thing here
$hostname="localHost";
$username="removed";
$password="removed";
$dbname="removed";
$usertable="removed";
$link = mysql_connect($hostname, $username, $password);
if (!$link) {
die('Not connected : ' . mysql_error());
}
// make foo the current db
$db_selected = mysql_select_db($dbname, $link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
$title = mysql_real_escape_string($_POST['title']);
$author = mysql_real_escape_string($_POST['author']);
$content = mysql_real_escape_string($_POST['content']);
$topic = mysql_real_escape_string($_POST['topic']);
//Define the query. Note in this query we use the table "errors"
$query = "INSERT INTO discuss (title, name, content, topic) VALUES ('{$title}', '{$author}', '{$content}', '{$topic}')";
//Execute the query
mysql_query ($query);
mysql_close();
}
?>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">× </button>
<h2 class="modal-title">New Post</h2>
</div>
<div class="modal-body">
<p>
<form name= "postform" action="discuss.php" method="post" class = "newpostform">
<fieldset>
<div class="newpostform-group1">
<input autocomplete="off" autofocus class="form-control" name="post_title" placeholder="Post Title" type="text"/>
</div>
<div class="newpostform-group1">
<input class="form-control" name="author" placeholder="Author" type="text"/>
</div>
<div class="newpostform-grouplist">
<select name="topic" class ="topic_drop">
<option selected disabled>Select Topic</option>
<option value="General">General</option>
<option value="Dogparks">Dog Parks</option>
<option value="QandA">Q&A</option>
<option value="Sophos">Sophos</option>
</select>
</div>
<div class="newpostform-group2" id = "desc">
<textarea class="form-control" name="content" placeholder="Text" type="text"></textarea>
</div>
<div class="newpostform-group3">
<button class="btn btn-default" name="submit" type="submit" id="addpost">
<span aria-hidden="true" class="glyphicon glyphicon-log-in"></span>
Add Post
</button>
</div>
</fieldset>
</form>
<br>
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Und was ist der Fehler, den Sie haben? –
Sie haben als jQuery getaggt, aber es gibt keinen Code, der die Frage unterstützt. –
Sie haben dies vor 2 Tagen gepostet, kamen aber nicht zurück. Ich habe eine Antwort gepostet, unter der einige Numbnuts herabgestimmt haben. * Mh *, wie auch immer ... was kannst du dagegen tun, richtig? * pffft * –