XAMMP-Code?

Ergebnis der Datenabfrage

<HTML>
<BODY>
<h1> Ergebnis der Datenabfrage </h1>
<b1>
<?php
$mymsqli = new mysqli (''localhost'',''Jonas'', ''123456'',''uff'');
if ($mymsqli → connect_errno) {
echo ''failed'';
}
$sql = “SELECT * FROM lehrer“;
$result = $mymsqli → query ($sql);
while ($row = $result → fetch_row()) {
echo $row[0];
}
?>
</BODY>
</HTML>

Datenbank verbinden

<HTML>
<HEAD>
<TITLE> MY_SQL_DATENBANK_VERBINDEN </TITLE>
</HEAD>
<BODY>
<DIV align=CENTER>
<h1> MY_SQL_DATENBANK_VERBINDEN </h1>
<FROM action=“http://localhost/JONAS/AllesAnzeigen.php“ method=''post''>
<BR>
<TEXTAREA name='''Eingabe'' rows=“2“ cols=“4“> SELECT * FROM lehrer;
</TEXTAREA>
<BR>
<INPUT type=“submit“ name=“Senden“ value=“Senden“
</FORM>
</DIV>
</BODY>
</HTML>

Daten Eintragen

<HTML>
<HEAD>
<TITLE> MY_SQL_DATENBANK_EINTRAGEN</TITLE>
</HEAD>
<BODY>
<DIV align=CENTER>
<h1> MY_SQL_DATENBANK_VERBINDEN </h1>
<FROM action=“http://localhost/JONAS/dbtabelle.php“ method=''post''>
<BR>
<TEXTAREA name='''Eingabe'' rows=“2“ cols=“4“> INSERT INTO lehrer;
</TEXTAREA>
<BR>
<TEXTAREA name=''Name'' rows=“2“ cols=“4“>Name;
</TEXTAREA>
<BR>
<TEXTAREA name=''Vorname'' rows=“2“ cols=“4“>Vorname;
</TEXTAREA>
<BR>
<TEXTAREA name=''Alter'' rows=“2“ cols=“4“>Alter;
</TEXTAREA>
<BR>
<TEXTAREA name=''GebDatum'' rows=“2“ cols=“4“>GebDatum;
</TEXTAREA>
<BR>
<INPUT type=“submit“ name=“Senden“ value=“Senden“
</FORM>
</DIV>
</BODY>
</HTML>

dbtabelle

<?php
$mymsqli = new mysqli (''localhost'',''Jonas'', ''123456'',''uff'');
if ($mymsqli → connect_errno) {
echo ''failed'';
}
$sql = INSERT INTO lehrer (Name, Vorname, Alter, Gebdatum)
Values ('dff','dvfv','19','17.08.2003');
?>
(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
1 Answer
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
regex9
1 year ago

Your codesnippets contain a variety of errors.

Snipped 1:

  • Missing Doctype
  • Missing title head
  • There is no element called b.
  • In the PHP code, you use incorrect delimiters for your string liters several times; use either English simple or double quotes:
'String'
"String"

Snippet 2 and 3:

  • Missing Doctype
  • The alignment-Attribute no longer belongs to the current standard; instead use CSS; this guide can help you
  • The element for forms is formNot from
  • The input-Day lacks a pointed clamp (>) at the end
  • You use false delimiters for your attribute values; instead use English simple or double quote characters

Snippet 4.

  • You use false delimiters for your string liters several times (compare with above)
  • The TOTAL-Query must be in a string
$sql = "INSERT INTO lehrer (Name, Vorname, Alter, Gebdatum) VALUES ('dff', 'dvfv', '19', '17.08.2003')";
  • The TOTAL-Query is not sent to the database, hopefully you are aware; as with Snippet 1, you need transversal-Method for

In combination with Snippet 4, you do not receive the form values and use them. The first one could look like this:

By the way, I would not give a user the opportunity to prescribe specific SQL code, as it could easily abuse it. If he is between different commands (SELECT, TOTAL, ...) I would just give him a list of radiobuttons and assemble the command in the PHP code itself.

Example:

$selectedCommand = $_POST['selected-command']; // read radiobutton
switch ($selectedCommand) {
  case 'select':
    $sql = 'SELECT * FROM lehrer';
    /* send query, etc. ... */
    break;
  case 'insert':
    $sql = 'INSERT INTO lehrer (Name, Vorname, Alter, Gebdatum) VALUES (?, ?, ?, ?)';
    /* send query, etc. ... */
    break;
  /* etc. ... */
  default:
    // invalid sql command ...
    break;
}

If you want to install dynamic values in your query (as with TOTAL-Query), then use Prepared Statements.