简体   繁体   中英

How do i use an insert query in a file that already has a select query?

How can I use another query to insert the question_text into a database table as shown in code below?

mysql_connect ("localhost", "root","") or die ('Error : '.mysql_error());
mysql_select_db("keyword");
$first_word = current(explode(' ', $_POST['question_text']));

$qStuff=mysql_query("SELECT c.field_name,t.category_name, d.domain_name FROM category_fields c, taxonomy_category t, taxonomy_domain d WHERE c.category_id = t.category_id AND t.domain_id = d.domain_id AND c.field_name = '" . mysql_real_escape_string($first_word) . "'");
$num_rows = mysql_num_rows($qStuff);

// some print codes here

just type:

mysql_query("insert into ... values ...");

but take care of possible mysql-injections! use mysql_real_escape_string() and see: http://www.tizag.com/mysqlTutorial/mysql-php-sql-injection.php

This insert statement uses a select query to populate the values of field1 and field2:

    insert into table (field1, field2)
    select field1, field2 from table2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM