Mysqli "select" statement produces no results - but "update" statement with the same "where&quo
Tag : php , By : Keonne Rodriguez
Date : March 29 2020, 07:55 AM
I hope this helps you . In order to use num_rows on prepared statements you need to call store_result first. The manual also mention the above.<?php
// Your database info
$db_host = 'localhost';
$db_user = '';
$db_pass = '';
$db_name = '';
$code = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 20);
if (!isset($_POST['email']))
{
die('Please fill in the email field.');
}
if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
{
die('Invalid email address');
}
$con = new mysqli($db_host, $db_user, $db_pass, $db_name);
if ($con->connect_error)
{
die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error());
}
$sql = "SELECT first, last FROM users WHERE user = ?";
if (!$result = $con->prepare($sql))
{
die('Query failed: (' . $con->errno . ') ' . $con->error);
}
if (!$result->bind_param('s', $_POST['email']))
{
die('Binding parameters failed: (' . $result->errno . ') ' . $result->error);
}
if (!$result->execute())
{
die('Execute failed: (' . $result->errno . ') ' . $result->error);
}
$result->store_result();
if ($result->num_rows == 0)
{
die('No username found...');
}
$result->bind_result($first, $last);
$result->fetch();
// After using fetch, we can print the data
echo $first, " => ", $last;
$result->close();
$update = 'UPDATE users SET reset = ? WHERE user = ?';
if (!$stmt = $con->prepare($update))
{
die('Update query failed: (' . $con->errno . ') ' . $con->error);
}
if (!$stmt->bind_param('ss', $code, $_POST['email']))
{
die('Update binding parameters failed: (' . $stmt->errno . ') ' . $stmt->error);
}
if (!$stmt->execute())
{
die('Update execute failed: (' . $stmt->errno . ') ' . $stmt->error);
}
$stmt->close();
$con->close();
if (mail($_POST['email'], "Example.org Password Reset Code", "Dear $first $last,\n\n Please visit the following url to reset your password:\n http://www.example.org/reset.php?c=$code\n\nSincerely,\nSender", "From: noreply@example.org"))
{
echo "Email sent";
}
else
{
echo "Failed to send email";
}
|
Current MySQL IN statement strings Cats as an "OR" - Need it as an "And" statement
Date : March 29 2020, 07:55 AM
To fix this issue IN compares one value in one row against a list. What you're asking for is completely different: to find whether a separate row exists for each value in the list. You can't do that with a simple operator. (If you truly had an AND, you'd get no rows back, because the same value can't equal both 129 and 75.) You have to either join once or subquery once for every category you want. SELECT ...
FROM places
INNER JOIN places_cats pc1 ON places.PlaceID = pc1.PlaceID AND pc1.CATID = 129
INNER JOIN places_cats pc2 ON places.PlaceID = pc2.PlaceID AND pc2.CATID = 75
INNER JOIN places_cats pc3 ON places.PlaceID = pc3.PlaceID AND pc3.CATID = 104
SELECT ...
FROM places
WHERE places.PlaceID IN (SELECT PlaceID FROM places_cats WHERE CATID = 129)
AND places.PlaceID IN (SELECT PlaceID FROM places_cats WHERE CATID = 75)
AND places.PlaceID IN (SELECT PlaceID FROM places_cats WHERE CATID = 104)
SELECT ...
FROM places
WHERE EXISTS (SELECT * FROM places_cats WHERE places_cats.PlaceID = places.PlaceID AND CATID = 129)
AND EXISTS (SELECT * FROM places_cats WHERE places_cats.PlaceID = places.PlaceID AND CATID = 75)
AND EXISTS (SELECT * FROM places_cats WHERE places_cats.PlaceID = places.PlaceID AND CATID = 194)
|
MariaDB, pypyodbc, "Unknown prepared statement handler" executing "SELECT" query on table loaded wit
Date : March 29 2020, 07:55 AM
With these it helps Turned out to be a pypyodbc problem. Installed pyodbc, imported it as pypyodbc, and everything worked as it should.
|
Encountered "INSERT" at character 1, but expected: ["DELETE", "SELECT", "UPDATE"
Tag : java , By : user186435
Date : March 29 2020, 07:55 AM
wish helps you OpenJPA doesn't seem to support JPQL "INSERT" queries. But then that is not surprising since JPA DOES NOT define INSERT queries. It defines SELECT, UPDATE, DELETE queries and that is all. See the JPA spec. This is not SQL.
|
Using "Select" in "Insert" statement in MYSQL with PHP
Tag : php , By : user86493
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I have created a form that I link with PHP. I need the foreign key number to be the same with id of another table. , You can not use select inside values. Change your code from $Query="INSERT INTO musteri_ekle(tarih,musteri_ismi,urun_id)
VALUES('$Now','$Musteri_ismi',(SELECT urun_id from urun_ekle WHERE urun_ismi='$Urun_ismi'))";
$Query="INSERT INTO musteri_ekle(tarih,musteri_ismi,urun_id)
SELECT '$Now','$Musteri_ismi',urun_id from urun_ekle WHERE urun_ismi='$Urun_ismi'";
|