<?php
if(isset($_GET["vorname"]) && !empty($_GET["vorname"])){
$query2=$db->query("UPDATE userdaten SET material = '".$_GET["vorname"]." 'WHERE user_id = '".$id."'");
$sql = "SELECT vorname , nachname
FROM members, material
WHERE user_id = ' ".$id."'
AND material_id = '".$_GET["vorname"]."'";
}
$result = mysqli_query($sql);
echo "<table class='auswahl'>";
if($ausgabe = mysqli_fetch_object($result)){
echo "<tr>";
echo "<td>".$members->vorname."</td>";
echo "<td>".$members->nachname."</td>";
echo "</tr>\n";
}
echo "</table></p>";
?>
Asked
Active
Viewed 330 times
-4
-
total query from localhost is always o,oooooooosec. why – Richi May 06 '18 at 19:14
-
1No idea what your "question" is. Learn how to format a question, and [ask] a question. – IncredibleHat May 06 '18 at 19:18
-
Am new here but no problem. want to return data from my localhost, i receive the above title as error. my total query is always 0.00000sec. – Richi May 06 '18 at 19:25
-
// error line -> if($ausgabe = mysqli_fetch_object($result)) – Richi May 06 '18 at 19:27
-
I'd start with adding this to the very top of your script: `ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);` ... it will help some. Maybe ;) – IncredibleHat May 06 '18 at 19:39
-
$result = mysqli_query($sql); this line is still error – Richi May 06 '18 at 19:56
2 Answers
0
I'll probably get several down votes for this and this is probably not the answer you're looking for as it is in PDO but use this code and see how it works for you:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDBPDO";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
if (isset($_POST["vorname"]) && !empty($_POST["vorname"])) {
$stmt = $conn->prepare("UPDATE userdaten SET material = :material WHERE user_id = :user_id");
$stmt->bindParam(':material', $material);
$stmt->bindParam(':user_id', $user_id);
$material = $_POST['material'];
$user_id = $_POST['user_id'];
if ($stmt->execute()) {
$stmt_members = $conn->prepare("SELECT vorname, nachname FROM members, material WHERE user_id = :user_id AND material_id = :material_id");
$stmt_members->bindParam(':user_id', $user_id);
$stmt_members->bindParam(':material_id', $material_id);
$user_id = $_POST['user_id'];
$material_id = $_POST['material_id'];
if ($stmt_members->execute()) {
echo "<table class='auswahl'>";
while ($row_members = $stmt_members->fetch()) {
echo "<tr>";
echo "<td>".$row_members['vorname']."</td>";
echo "<td>".$row_members['nachname']."</td>";
echo "</tr>\n";
}
echo "</table></p>";
}
}
}
$conn = null;
?>
Also my friend, why are you using $_GET instead of $_POST?
JeanPaul98
- 502
- 6
- 18
-
thanks jeanPaul :D am using the $_GET function because the variables need to placed to url already existing file but will try the Post. thank you. – Richi May 06 '18 at 20:32
-
Are you trying to post to the same file? Meaning are you using `$_POST` and `$_GET` from file.php? @Richi – JeanPaul98 May 07 '18 at 18:10
-
different file but to the same url(provider). i needed to edit some file and place it in an already existing url. my supervisor and i have solved the problem. thank you very much :D. – Richi May 08 '18 at 20:20
0
Even if I do not see any questions here....
When $_GET["vorname"] is not set, you still execute mysqli_query($sql) where $sql will be null (and also $result will be null therefore).
You should also do some error handling (check for errors using mysqli_error()) and think about where the variable $id and $members come from as this will be your next issues.
Ebby
- 464
- 3
- 8