Zunächst einmal: Ich weiß, dass diese Frage schon einmal gestellt wurde, aber ich suche jetzt seit über einer Woche nach einer funktionierenden Lösung und ich kann keine finden. Also kann mir bitte jemand helfen, anstatt nur meine Frage als Duplikat zu markieren? Danke schon !!Prüfe, ob eine mysgl-Tabelle mit PHP existiert
Die Frage ist also: Ich versuche zu überprüfen, ob eine MySQL-Tabelle in meiner Datenbank existiert (mit PHP). Weiß jemand, wie ich dieses Problem lösen kann? Dies ist mein Code so weit wie ich:
<form id="newChat" method="post">
Start a new chat:
<input type="text" name="name" />
<input type="submit" value="Search" />
</form>
<?php
function checkChat($me, $friend) {
global $conn;
$chatid = findChat($me, $friend);
$sql = 'SHOW TABLES FROM chatboxDB LIKE \'chat10\'';
$result = mysqli_query($conn, $sql) or trigger_error(mysql_error()." in ".$query);
if ($result > 0) {
echo '<script>alert("It works.");</script>';
}
}
if (isset($_POST)) {
$friend = checkInput($_POST["name"]);
unset($_POST["name"]);
checkChat($me, $friend);
}
?>
Einige Bemerkungen:
- die mysqli_query() Funktion funktioniert in anderen Teilen meines Codes
- die Verbindung $ conn meiner Datenbank arbeitet
- das Problem scheint in
if ($result > 0)
zu sein -> das scheint zu sein, immer wahr ...
Edit: Das ist jetzt mein Code und es funktioniert: (Ich fand es viel einfacher gemacht werden könnte)
<?php
function checkChat($me, $friend) {
global $conn, $dbname;
$chatid = findChat($me, $friend); # the findChat() is a query to find the name of a chat by giving the 2 persons from that chat, if one of those 2 persons does not exist, findChat will return nothing)
if (!$chatid) {
# the chat does not exist
}
}
if (isset($_POST)) {
$friend = checkInput($_POST["name"]);
$_POST = array();
checkChat($me, $friend);
}
?>
erhalten ein Array behandelt werden, um Ihren Tisch zu iterieren und gefunden? https://dev.mysql.com/doc/refman/5.7/en/show-tables.html –
Diese Art von Problem ist symptomatisch für schlechtes Design – Strawberry