Ich habe Probleme mit dem folgenden Code. Ich brauche mein Formular, um Informationen über 2 Seiten in meine MySQL-Tabelle einzufügen. Ich habe etwas recherchiert und mit Hilfe bin ich auf folgendes gekommen.PHP Formular in MySQL Tabelle über 2 Seiten senden
Erste Seite PHP
<?php
ob_start();
session_start();
require_once 'dbconnect.php';
if(!isset($_SESSION['client'])) {
header("Location: homepage_login.php");
exit;
}
// select loggedin users detail
$res=mysql_query("SELECT * FROM clients WHERE client_id=".$_SESSION['client']);
$userRow=mysql_fetch_array($res);
if(isset($_POST['btn-nxt-page'])) {
$client_student_id = trim($_POST['client_student_id']);
$ss_name = trim($_POST['ss_name']);
$client_student_id = strip_tags($client_student_id);
$ss_name = strip_tags($ss_name);
if ($_SELF) {
$query = "";
$res = mysql_query($query);
if ($res) {
$errTyp = "success";
} else {
$errTyp = "danger";
}
}
function redirect($where){
header("Location: $where");
}
if ($_REQUEST['ss_name'] == 'John') {
header("Location: http://localhost/homepage_loggedin_book_john.php");
} else if ($_REQUEST['ss_name'] == 'Smith') {
header("Location: http://localhost/homepage_loggedin_book_smith.php");
} else if ($_REQUEST['ss_name'] == 'Greg') {
header("Location: http://localhost/homepage_loggedin_book_greg.php");
} else if ($_REQUEST['ss_name'] == 'Jess') {
header("Location: http://localhost/homepage_loggedin_book_jess.php");
}}
?>
Erste Seite HTML
<form action"" method="post">
<div class="form-group">
<div class="input-group">
<input type="text" name="client_student_id" class="form-control" placeholder="Enter your Student ID" required />
</div>
</div>
<br>
<br>
<label for="ss_name" id="menu">Select a teacher</label>
<select name="ss_name" id="#menu">
<option value="John">John</option>
<option value="Smith">Smith</option>
<option value="Greg">Greg</option>
<option value="Jess">Jess</option>
</select>
<br>
<br>
<div class="form-group">
<button type="submit" class="btn btn-block btn-primary" name="btn-nxt-page">Next Page</button>
</div>
</form>
Das alles funktioniert gut, aber die Informationen der Benutzer in (Studentenausweis und den Lehrer) setzt nicht geh in meine Datenbank.
Das ist mein zweite Seite PHP:
<?php
ob_start();
session_start();
require_once 'dbconnect.php';
if(!isset($_SESSION['client'])) {
header("Location: homepage_login.php");
exit;
}
// select loggedin users detail
$res=mysql_query("SELECT * FROM clients WHERE client_id=".$_SESSION['client']);
$userRow=mysql_fetch_array($res);
$_SESSION['client_student_id'] = $_POST['client_student_id'];
$_SESSION['ss_name'] = $_POST['ss_name'];
if(isset($_POST['btn-book'])) {
if ($_SELF) {
$query = "";
$res = mysql_query($query);
if ($res) {
$errTyp = "success";
} else {
$errTyp = "danger";
}
}
}
?>
<?php
$ss_name = $_SESSION['ss_name'];
$client_student_id = $_SESSION['client_student_id'];
$reason = $_SESSION['reason'];
$slot_date = $_SESSION['slot_date'] ;
$slot_line =$_SESSION['slot_line'];
?>
<?php
$query="INSERT INTO appointments (,
ss_name,
client_student_id,
reason,
slot_date,
slot_line,
)
VALUES('NULL',
'".mysql_real_escape_string($ss_name)."',
'".mysql_real_escape_string($client_student_id)."',
'".mysql_real_escape_string($reason)."',
'".mysql_real_escape_string($slot_date)."',
'".mysql_real_escape_string($slot_line)."','
)";
echo $query;
mysql_query($query) or die ('Error updating database');
?>
Und meine zweite Seite HTML:
<form action"" method="post">
<p>Date: <input type="text" id="datepicker" name="slot_date"></p>
<br>
<br>
Select a line:
<ol id="selectable" name="slot_line">
<li class="ui-widget-content">Line 1</li>
<li class="ui-widget-content">Line 2</li>
<li class="ui-widget-content">Line 3</li>
<li class="ui-widget-content">Line 4</li>
<li class="ui-widget-content">Line 5</li>
<li class="ui-widget-content">Line 6</li>
<li class="ui-widget-content">Line 7</li>
</ol>
<br>
<br>
<p>Reason for appointment: <input type="text" name="reason"></p>
<div class="form-group">
<button type="submit" class="btn btn-block btn-primary" name="btn-book">Book</button>
</div>
</form>
Ich habe empfohlen, die zweite Seite PHP-Code setzen die setzen Informationen in eine separate Seite, aber ich kann die Seiten nicht verbinden.
Also, meine Frage ist:
Wie erhalte ich die Informationen in der Datenbank-Tabelle (genannt Termine) über meine zwei Formularseiten einfügen?
Miss, fügen Sie PHP-Skripte zu Ihren Formularen – madalinivascu