Jump to content

using select statement as a loop to insert data


bruckerrlb

Recommended Posts

Hello,

 

I am not exactly sure what i'm doing wrong here, but I am trying to make mysql find the specific user with a select statement, and then insert data about this user into his record. This is my code

//this top connection part is not the problem, it's after the brown

$qry = "INSERT INTO products

(productid, productname, telefone, fetchaalta, fetchabaja, clientid)

VALUES

('$_POST[productnumber]', '$_POST[productname]', '$_POST[telefone]', '$_POST[desde]', '$_POST[hasta]', '$_POST[clientid]')";

 

 

 

 

if (!@mysql_query ($qry)) {

die(mysql_error());

}

else {

 

$client = $_POST[cliente];

 

 

$getuser = 'SELECT id FROM login WHERE id = '$client'';

 

if ($r = mysql_query ($getuser)) {

 

while ($row = mysql_fetch_array ($r)) {

//Create INSERT query

$query = "INSERT INTO login

(fetchaalta, fetchabaja)

VALUES

('$_POST[altacliente]', '$_POST[bajacliente]')";

if (!@mysql_query ($query)) {

die("possible problem here".mysql_error()."problem in loginquery");

}

}

}

else {

 

 

header("location: admin_menu.php");

exit;

}

}

I am getting the dreded parse error, unexpected T_Variable, but the main problem is i'm pretty sure my logic is not right, and I am wondering how to go about setting this up

iif anyone is good with mysql logic it would be a great help to me, thanks in advance!

First of all make sure that ur php variable are interpreted and if not , try this

VALUES ('{$_POST['productnumber']}',..............)

 

is this what u r looking for  ur second insert query

INSERT INTO login   (fetchaalta, fetchabaja)   VALUES   ('$_POST[altacliente]', '$_POST[bajacliente]') where id=ANY (SELECT id FROM login WHERE id = '$client')

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.