SELECT * FROM admin where company='test & test'
I am running this query but getting error due to &.while printing Its showing
SELECT * FROM admin where company='test ',not accepting & in sql query
Can we run using & in query
need suggestion.
SELECT * FROM admin where company='test & test'
I am running this query but getting error due to &.while printing Its showing
SELECT * FROM admin where company='test ',not accepting & in sql query
Can we run using & in query
need suggestion.
For : MySQL will happily store and match strings that contain an ampersand β as and observed, the same SELECT works in phpMyAdmin. When the value prints as truncated at the ampersand inside a PHP script (showing "test " only) the ampersand is being handled before the SQL runs β typically while building a URL/query string or due to incorrect encoding/escaping in PHP/HTML rather than a MySQL limitation (as suspected).
Quick diagnostic checklist and fixes:
Minimal examples:
# build URL safely
$url = 'search.php?' . http_build_query(['company' => $company]);
header('Location: ' . $url);
# use a prepared statement (PDO)
$pdo = new PDO($dsn, $user, $pass, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
$stmt = $pdo->prepare('SELECT * FROM admin WHERE company = :company');
$stmt->execute(['company' => $company]);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC); Notes: if not using prepared statements, use mysqli_real_escape_string before interpolation. For a quick confirmation of the problem source, log the raw incoming request and the exact URL being generated; if the ampersand is lost there, the solution is URL-encoding (or switching to POST / using http_build_query).
Jump to Post— chrishea 182I just tried a query in phpmyadmin with a '&' in the query and it accepted it just fine. I don't have any data with an & in the data so I didn't get any results but it did accept it.
I just tried a query in phpmyadmin with a '&' in the query and it accepted it just fine. I don't have any data with an & in the data so I didn't get any results but it did accept it.
I tried your both query. It works fine.
SELECT * FROM admin where company='test & test'
I am running this query but getting error due to &.while printing Its showing
SELECT * FROM admin where company='test ',not accepting & in sql queryCan we run using & in query
need suggestion.
I've had this issue before. It would work doing a simple SQL statement in phpMyAdmin for example but wouldn't work within my PHP script. Is this your problem as well?
I don't know the solution as I haven't encountered it again lately.
its not working with in PHP script.but working fine in my sql.
SELECT * FROM admin where company='test & test'
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.