php - Error message if record exist is not working -


i trying check if record exist before inserted. code checking is:

$query = "select * firm ( name = '" . mysql_real_escape_string( $name ) . "' , area = '" . mysql_real_escape_string( $areaname ) . "' )"; $rs = mysql_query( $query );      if ( !$rs ) {        echo "the firm area exist.";        trigger_error( mysql_error() );     } else {        echo "saved.";     } 

my insert code is:

$result = array();  mysqli_autocommit( $dbc, false );  $sql1 ="insert `firm`(name, area, vat, active) values ('$name', '$areaname', '$vat', '$active')";  //echo $sql1; $result[] = mysqli_query( $dbc, $sql1 ) ;  $sql2 = "insert `area`(name, hub_name, fk_hub_id) values ('$areaname'          ,(select `name` hub name = '$hub_name')          ,(select `id` hub name = '$hub_name'))         "; //echo $sql2; $result[] = mysqli_query($dbc,$sql2);        $success = true;  if ( is_array( $results ) ) {     foreach( $results $result ) {        if ( !$result ) {            $success = false;        }     }     if ( !$success ) {        mysqli_rollback( $dbc );     } else {        mysqli_commit( $dbc );     } } 

my problem error message not working. when submit form , record exist says saved though not inserted. can tell me going wrong?

use mysql_num_rows() count results.

$query = "select * firm (name = '" . mysql_real_escape_string($name) . "' , area = '" . mysql_real_escape_string($areaname) . "' )";     $rs = mysql_num_rows(mysql_query($query));      if ($rs != 0) {             echo "the firm area exist.";             trigger_error(mysql_error());         }     else {      echo "saved.";} 

note usage of mysql_* functions deprectaded

have on pdo

http://php.net/manual/de/book.pdo.php

and try porting code on pdo fast possible.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -