Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $con = mysqli_connect(
- "xxxxxxxxxxxxxxxx",
- "xxxxxxxxxxxxxxxx",
- "xxxxxxxxxxxxxxxx",
- "xxxxxxxxxxxxxxxx" );
- if( $con == FALSE ) {
- echo "Failed to connect to MySQL: " . mysqli_connect_errno();
- }
- else {
- echo "Connection successfull!";
- }
- $items = json_decode( $_POST[ 'json' ], true );
- foreach ( $items as $i ) {
- $pName = $i["name"];
- $pURL = $i["url"];
- $pCountbox = $i["countbox"];
- $pPriceOld = $i["price_old"];
- $pPriceNew = $i["price_new"];
- $pActive = $i["active"];
- $result = mysqli_query( $con, "SELECT id FROM c_products WHERE c_products.name='" . $pName . "'" );
- $num_rows = mysqli_num_rows( $result );
- if( $num_rows == 0 ) {
- // insert
- $q = "INSERT INTO c_products(name,url,countdown,price_init,price_discount,active) VALUES (";
- $q = $q . "'" . $pName . "',";
- $q = $q . "'" . $pURL . "',";
- $q = $q . "'" . $pCountbox . "',";
- $q = $q . "'" . $pPriceOld . "',";
- $q = $q . "'" . $pPriceNew . "',";
- $q = $q . "'" . $pActive . "')";
- if( $result = mysqli_query( $con, $q ) ) {
- print_r( "New item inserted.\n" );
- mysqli_free_result($result);
- }
- else {
- print_r( "Error insert: " . $result->error . "\n" );
- }
- }
- }
- mysqli_close( $con );
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement