PHP handler for SQL Error 1022 -
can me sql query/php handler?
i'm trying customise error message mysql_errno() 1022 says "serial number exists" rather saying "error: duplicate entry 'test' key 'ser'".
i've tried changing handler following had no joy.
$result = mysqli_query($con, $sql); if ($result === false) { if (mysql_errno() == 1022) { die("username exists"); } else { die("error:" . mysql_error($con)); } } my code:
<?php // create connection $con = mysqli_connect("127.0.0.1", "user", "password", "assets"); // check connection if (mysqli_connect_errno($con)) { echo "failed connect mysql: " . mysqli_connect_error(); } $sql="insert barts (project, system, ser, assets, tdate) values ('$_post[element_3]','$_post[element_4]','$_post[element_1]','$_post[element_2]','$_post[tdate]')"; if (!mysqli_query($con,$sql)) { die('error: ' . mysqli_error($con)); } echo "1 record added"; mysqli_close($con); ?>
you're using mysqli_query() (mind 'i') check error code regular/deprecated mysql_errno() function. in addition need pass connection use ($con).
try this:
$result = mysqli_query($con, $sql); if ($result === false) { if (mysqli_errno($con) == 1022) { die("username exists"); } else { die('error:' . mysqli_error($con)); } }
Comments
Post a Comment