My code works only for one value, for the first one, after I try to add a second user, he no longer defines duplicates sees one element of the array, I understand what I need somehow through the cycle, but I don’t understand how .;
$app->get('/addtodb', function () use($app) { $name = $app -> request()-> get('name'); // connecting to db $db = new dbconnect(); $query = "SELECT id FROM users WHERE name='$name'"; $res = mysql_query($query); $row = mysql_fetch_array($res); echo $row['name']; if (!empty($row['id'])) { echo 'error'; } else { $result = mysql_query("INSERT INTO users (name) VALUES ('$name')"); }; }); $app->run();
users(phoneint (11) NOT NULL,nametext NOT NULL,secondnametext NOT NULL,passtext text NOT NULL,user_typeint (11) NOT NULL,idint (11) NOT NULL AUTO_INCREMENT, KEYid(id), KEYid_2(id)) - Yegor Krotenko