insert into from query select

Codes here !

Moderators: macek, egami, gesf

lelemkop
New php-forum User
New php-forum User
Posts: 1
Joined: Tue Jul 23, 2013 12:11 am

insert into from query select

Postby lelemkop » Tue Jul 23, 2013 12:14 am

1) under this research the data I selected and prints them on the screen. Obviously not enter anything in the table
$ query = "SELECT * FROM actions WHERE 1 = 1";
$ w_cliente = ""; if ($ customer! = "") {$ w_cliente = "AND customer LIKE '%". $ client. "%'";} $ w_cognome = ""; if ($ name! = "" ) {$ w_cognome = "AND name LIKE '%". $ name. "%'";} $ w_nome = ""; if ($ name! = "") {$ w_nome = "AND name LIKE '%". $ name. "% '";}
$ query. = $ w_tipologia. $ w_cognome. $ w_nome. "ORDER BY id";
$ q = "INSERT INTO $ query time";
$ res = mysql_query ($ query) or die ('Error: Something went wrong'); $ exists = mysql_num_rows ($ res);

2) This sub inserts the data sought in the table but I would print the results
$ query = "INSERT INTO time SELECT * FROM actions WHERE 1 = 1";
$ w_cliente = ""; if ($ customer! = "") {$ w_cliente = "AND customer LIKE '%". $ client. "%'";} $ w_cognome = ""; if ($ name! = "" ) {$ w_cognome = "AND name LIKE '%". $ name. "%'";} $ w_nome = ""; if ($ name! = "") {$ w_nome = "AND name LIKE '%". $ name. "% '";}
$ query. = $ w_tipologia. $ w_cognome. $ w_nome. "ORDER BY id"; $ res = mysql_query ($ query) or die ('Error: Something went wrong');
$ exists = mysql_num_rows ($ res);

in the second case ie when inserting and does not print anything on the screen I get this warning
Warning: mysql_num_rows () Expects parameter 1 to be resource, boolean given in / var/www/cerca2.php on line 47
this is the line 47
$ exists = mysql_num_rows ($ res);

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: insert into from query select

Postby johnj » Tue Jul 23, 2013 9:12 pm

First, your code did not execute properly. Your query failed, check why it failed. That is why num rows function is failing.


Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 4 guests