note 128638 added to function.mysql-query

From: Date: Mon, 26 Jun 2023 04:36:23 +0000
Subject: note 128638 added to function.mysql-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-220598@lists.php.net to get a copy of this message
<?php $servername = "localhost"; $username = "root"; $password = ""; $database = "meinedatenbank"; $conn = new mysqli($servername, $username, $password, $database); //Erstellt 5 würfel und zeigt Zahlen an if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully <br>"; $würfel = array(); if(isset($_REQUEST["submit"])){ for ($i = 0; $i < 5; $i++) { $würfelzahl = rand(1,6); array_push($würfel, $würfelzahl); } echo(implode(" ", $würfel). "<br>"); $stmt = $conn->prepare("INSERT INTO würfe(w1, w2, w3, w4, w5) VALUES (?, ?, ?, ?, ?)"); $stmt->bind_param("iiiii", ...$würfel); $stmt->execute(); $zahlen = array_count_values($würfel); foreach ($zahlen as $zahl => $anzahl) { $result = $conn->query("SELECT COUNT(*) AS count FROM würfe WHERE w1 = $zahl OR w2 = $zahl OR w3 = $zahl OR w4 = $zahl OR w5 = $zahl"); $row = $result->fetch_assoc(); $gewürfelteZahl = $row['count']; echo "Die Zahl $zahl wurde bereits $gewürfelteZahl Mal gewürfelt.<br>"; } } ?> <form method="post"> <input type="submit" name="submit" value="Werfen"> </form> ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.13.130 (proxied: 79.195.18.142) ---- Manual Page -- https://php.net/manual/en/function.mysql-query.php Edit -- https://main.php.net/note/edit/128638 Del: integrated -- https://main.php.net/note/delete/128638/integrated Del: useless -- https://main.php.net/note/delete/128638/useless Del: bad code -- https://main.php.net/note/delete/128638/bad+code Del: spam -- https://main.php.net/note/delete/128638/spam Del: non-english -- https://main.php.net/note/delete/128638/non-english Del: in docs -- https://main.php.net/note/delete/128638/in+docs Del: other reasons-- https://main.php.net/note/delete/128638 Reject -- https://main.php.net/note/reject/128638 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220598) next »