logo
down
shadow

php mysql insert values and select


php mysql insert values and select

Content Index :

php mysql insert values and select
Tag : php , By : DarrenBeck
Date : November 23 2020, 01:01 AM

I think the issue was by ths following , In your query syntax error is there. syntax is told you by @Orel Eraki...
So your SQL should be:
$sql="INSERT INTO `table1` (`1`, `2`, `3`, `4`, `5`) 
 SELECT `1`, `2`, `3`, `4`, '$variable' FROM `table2` WHERE `table2`.`3`=3;";

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

insert incremental values in an insert ... select statement mysql


Tag : php , By : jazzyfox
Date : March 29 2020, 07:55 AM
To fix this issue I am trying to select a number of rows in a table, reverse the values in one column and reinsert them into the table. Here is an example of what I am doing, say I have the following data: , try this
    INSERT INTO myTable(`porder`, x, y) SELECT (SELECT MAX(`porder`) FROM myTable) - `porder`, x, y FROM myTable

MySQL INSERT [...] SELECT with mixed data (from SELECT clause and hand-inserted values)?


Tag : mysql , By : suresh
Date : March 29 2020, 07:55 AM
around this issue I'm trying to modify a table from OpenCart, a PHP-based e-cart solution. I currently have the oc_product_to_store table populated with the 1300+ product catalog we currently offer. We created a second store and I want to update that table for every product_id to have a second row pointing to the second store (so, in practical reality, I want to insert the 1 value into the store_id field for each new row, while preserving the product_id value). , So you mean?
 INSERT oc_product_to_store (productid, storeid)
 SELECT productid, 2
 FROM oc_product_to_store 
 WHERE storedid=1

mysql select to insert two values from one specific row and plus two values (paired) from some random row


Tag : mysql , By : Naveen
Date : March 29 2020, 07:55 AM
this one helps. I think you were pretty close.
In this case rather than getting caught up in the joins (except for the first one you needed) and the subqueries you can use simple variable assignment and a UNION clause. The only other thing missing that was causing an issue was that you need to use INSERT INTO...SELECT syntax vs. INSERT INTO...VALUES syntax (Reference).
INSERT INTO friends (user, friend) 
SELECT @user1:=users.user as user1, invited.user as user2 
    FROM users 
    INNER JOIN invited 
    ON users.email=invited.invitee
    WHERE invited.invitee = 'baz@bar.com'
UNION ALL
(SELECT @user1 as user1, user 
FROM users 
ORDER BY RAND() LIMIT 2)

Using INSERT INTO SELECT and VALUES MYSQL PDO


Tag : php , By : robinator
Date : March 29 2020, 07:55 AM
To fix this issue After a lot of googling and running around the different questions in StackOverflow, I haven't really found a solution that solves my problem. , You said:
<?php

/*
 * ============================================================
 * Set error reporting level and display errors on screen.
 * Use it ONLY ON A DEVELOPMENT SYSTEM, NEVER ON PRODUCTION!
 * If you activate it on a live system, then the users will see
 * all the errors of your system. And you don't want this!
 * ============================================================
 */
error_reporting(E_ALL);
ini_set('display_errors', 1);

try {
    // Read needed variables.
    // TODO: Provide your values.
    $user_cart_table_name = 'user_cart_table_name';
    $user_name = 'user name value';
    $order_name = 'order name value';
    $order_address = 'order address value';
    $order_phone = 'order phone value';

    // Create a PDO instance as db connection.
    // TODO: Delete this and use your own connection. 
    //       But use the first two driver options that I defined here as
    //       the options on your connection.
    $conn = new PDO(
            'mysql:host=localhost;port=3306;dbname=mydb;charset=utf8'
            , 'myuser'
            , 'mypass'
            , array(
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_EMULATE_PREPARES => FALSE,
        PDO::ATTR_PERSISTENT => TRUE,
            )
    );

    /*
     * The sql statement - it will be prepared.
     * 
     * Familiarize yourself with the sprintf() function.
     * It is your very good friend when building complex
     * sql statements.
     */
    $sql = sprintf('INSERT INTO user_orders (
                        order_item_id,
                        order_item,
                        order_quantity,
                        order_user,
                        order_name,
                        order_address,
                        order_phone
                    ) 
                    SELECT 
                        item_ID,
                        item_name,
                        item_quantity,
                        user_name,
                        "%s",
                        "%s",
                        "%s" 
                    FROM 
                        %s,
                        user_main 
                    WHERE 
                        item_status = "carted" 
                        AND user_name = :user_name'
            , $order_name
            , $order_address
            , $order_phone
            , $user_cart_table_name
    );

    // Prepare the sql statement.
    $stmt = $conn->prepare($sql);

    // Bind the input parameters to the prepared statement.
    $bound = $stmt->bindValue(':user_name', $user_name, PDO::PARAM_STR);

    // Execute the prepared statement.
    $executed = $stmt->execute();

    // Get the last insert id.
    $lastInsertId = $conn->lastInsertId();

    // Display last insert id.
    echo 'Record added with id ' . $lastInsertId;

    // Close connection.
    $conn = NULL;
} catch (PDOException $exc) {
    echo $exc->getMessage();
    exit();
} catch (Exception $exc) {
    echo $exc->getMessage();
    exit();
}

How to Insert SELECT ALL values or SELECTED checkboxes values into different columns in mysql?


Tag : php , By : user170635
Date : March 29 2020, 07:55 AM
may help you . Before inserting into mysql check if the value is exist in $_POST['addbook'] do this for all the checkboxes. You can also use array of checkbox.
     <?php
       // Do this for rest of the values also.

            if (isset($_POST['addbook'])){

               $addbook=$_POST['addbook'];

            }else{

               $addbook = "default value"

            }
    ?>
Related Posts Related QUESTIONS :
  • How to fix errors counting words in text plain with PHP?
  • How to get View data in Laravel in custom helper or directive
  • Creating a new data entry into a database with eloquent and trying to access the variable in the url
  • How to test authentication using Laravel Dusk?
  • PHP parse_str not getting all $_GET variables
  • Variable issues in php class
  • Get orders between dates in Codeigniter
  • Eloquent Special Chars Issue
  • Keeping leading zeros column Mysql
  • Current level navigation in Wordpress
  • Add a custom text to WooCommerce cart items if the product has a specific shipping class
  • Error connecting to CommissionJunction Token : [60] SSL certificate problem: unable to get local issuer certificate
  • How do I add a new key value pair to an object in PHP?
  • Http post request to php with dart
  • How to add a route in with blade into parameters of a component
  • How can i get the source of a 777 - CHMOD php file?
  • Convert 2010-04-16 16:30:00 to "Tomorrow Afternoon"
  • How can I hide a $_GET variable to be more secured in PHP?
  • Login to Gmail Inbox using Curl?
  • Upload Excel or CSV file to MySQL with PHP
  • Outlook Marking Email as Junk Email
  • Upload an image using class.upload.php via AJAX, display image in form using jQuery
  • mysql_connect() causes page to not display (WAMP)
  • How to limit a users uploaded image size using PHP
  • What's the difference whether or not to run PHP in safe mode?
  • Logging in to a website cURL
  • Using php to create a password system with chinese characters
  • PHP is not called properly in IE using set interval function in Javascript
  • How to read pdf, ppt, xl, doc files content into a string in php/python
  • php script for currency conversion
  • In PHP... best way to turn string representation of a folder structure into nested array
  • PayPal for Indian Rupees (INR) any solution
  • PHP Deployment to Live Server
  • Ideal Multi-Developer Lamp Stack?
  • How can I save an image from a file input field using PHP & MySQL?
  • Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in
  • Connecting to external MySQL DB from a web server not running MySQL
  • Is it possible to add custom fields to a Drupal taxonomy term?
  • PHP 6.0 - Roadmap?
  • jQuery wait for ajax call to be over before continuing
  • checkUnique function?
  • How to define an n-m relation in doctrine?
  • Sort the unsorted text file and rewrite to same text file in sorted order
  • Version control a content management system?
  • How can i run Single PHP File using apache-tomcat-6.0.18?
  • Array of objects is empty when I come to retrieve one from the array
  • PHP Library: Calculate a bounding box for a given lat/lng location
  • Good Wordpress Theme/plugin for showing off code examples and scripts
  • Replace all spaces and special symbols with dash in URL using PHP language
  • globally get any field value in user table of logged in user
  • Can you get a job if you know XHTML, CSS and Basic PHP?
  • HTML Upload Form will only upload files found in the directory of the PHP file
  • Determine if a PHP array uses keys or indices
  • Are frameworks really necessary for beginners/intermediates?
  • PHP File Downloading Questions
  • Who owns a php exec tar extracted file?
  • Best way to get timezone of user based on area code
  • Mysql BETWEEN clause being ignored. No syntax error
  • Zend Framework: Getting request object in bootstrap
  • PHP + GD: imagetruecolortopalette not keeping transparency
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com