Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear
create table tbl1 ( id int, val varchar(64) ); insert into tbl1 values (1, 'Test1');

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php function uniquedoesexist($dbHandle, $tablename, $fieldname, $value) { $sql = 'SELECT EXISTS(SELECT * FROM `'.$tablename.'` WHERE `'.$fieldname.'` = ? LIMIT 1)'; $stmt = mysqli_prepare($dbHandle, $sql); mysqli_stmt_bind_param($stmt, 's',$value); $sqlResult = mysqli_stmt_execute($stmt); echo '$sqlResult: ' . $sqlResult.$br; return $sqlResult; } uniquedoesexist($mysqli, 'tbl1', 'val', 'Test1');
Copy Clear