Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php mysql if not exists insert

$mysqli = new mysqli(SERVER, DBUSER, DBPASS, DATABASE);
$result = $mysqli->query("SELECT id FROM mytable WHERE city = 'c7'");
if($result->num_rows == 0) {
     // row not found, do stuff...
} else {
    // do other stuff...
}
$mysqli->close();
Comment

php sql insert into if not exists

INSERT IGNORE INTO `transcripts`
SET `ensembl_transcript_id` = 'ENSORGT00000000001',
`transcript_chrom_start` = 12345,
`transcript_chrom_end` = 12678;
Comment

PHP MySQL Insert record if not exists in table

<?php  
 $connect = mysqli_connect("localhost", "root", "", "zzz");  
 $messsage = '';  
 if(isset($_POST["add"]))  
 {  
      if(!empty($_POST["brand"]))  
      {  
           $sql = "  
                INSERT INTO brand (brand_name)  
                SELECT '".$_POST["brand"]."' FROM brand  
                WHERE NOT EXIST(  
                 SELECT brand_name FROM brand WHERE brand_name = '".$_POST["brand"]."'  
                ) LIMIT 1  
           ";  
           if(mysqli_query($connect, $sql))  
           {  
                $insert_id = mysqli_insert_id($connect);  
                if($insert_id != '')  
                {  
                     header("location:data_already_inserted.php?inserted=1");  
                }  
                else  
                {  
                     header("location:data_already_inserted.php?already=1");  
                }  
           }  
      }  
      else  
      {  
           header("location:data_already_inserted.php?required=1");  
      }  
 }  
 if(isset($_GET["inserted"]))  
 {  
      $message = "Brand inserted";  
 }  
 if(isset($_GET["already"]))  
 {  
      $message = "Brand Already inserted";  
 }  
 if(isset($_GET["required"]))  
 {  
      $message = "Brand Name Required";  
 }  
 ?>  
 <!DOCTYPE html>  
 <html>  
      <head>  
           <title>Webslesson Tutorial | MySQL Insert record if not exists in table</title>  
           <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>  
           <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
           <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>  
      </head>  
      <body>  
           <br />  
           <div class="container" style="width:500px;">  
                <label class="text-danger">  
                <?php  
                if($message!= '')  
                {  
                     echo $message;  
                }  
                ?>  
                </label>  
                <h3 align="">Insert Data</h3><br />                 
                <form method="post">  
                     <label>Enter Brand Name</label>  
                     <input type="text" name="brand" class="form-control" />  
                     <br />  
                     <input type="submit" name="add" class="btn btn-info" value="Add" />  
                </form>  
           </div>  
           <br />  
      </body>  
 </html>
Comment

PREVIOUS NEXT
Code Example
Php :: how to pass value from one php page to another using session 
Php :: last insert id in laravel 
Php :: Laravael Blog Project 
Php :: Laravel9 Failed to listen on 127.0.0.1:8000 (reason: ?) 
Php :: laravel validation alphanumeric with spaces 
Php :: laravel share 
Php :: serialise php 
Php :: create a product stripe 
Php :: can i install php7.4 inside vagrant homestead 
Php :: 12 hrs for preg match with single and double digit in php 
Php :: tackel discount in javascript 
Java :: minecraft bedrock file location 
Java :: import java math 
Java :: how to see list of java of versions in mac 
Java :: import android.support.v4.app.ActivityCompat; 
Java :: random item from arraylist 
Java :: how to set the java_home in mac 
Java :: install java apt 
Java :: add retrofit dependency android 
Java :: change visibility of textview andoird 
Java :: datentypen java 
Java :: java get current date string 
Java :: java random max and min 
Java :: Java android studio int to string 
Java :: moving text in textview android 
Java :: java find substring between two strings 
Java :: install java with brew 
Java :: get long from date java 
Java :: how to clear stringbuilder in java 
Java :: error when making java variable 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =