This topic is locked
[SOLVED]

 default value on

5/21/2014 9:45:25 AM
PHPRunner General questions
M
minaras author

global $conn;

$strSQLInsert = "INSERT INTO table (ref_id, description, type) VALUES (".$keys['id'].",'".

$values['description']."','".$values['type']."')";

db_exec($strSQLInsert,$conn);
how i can insert a default value at one field ?

Sergey Kornilov admin 5/21/2014

Not sure what default value do you mean. Please elaborate.

M
minaras author 5/21/2014



Not sure what default value do you mean. Please elaborate.


the code is working fine but i want at the same line at the field <type> to insert a default value let say <expense>
if i try to insert the below code it put it at next line
$sql = "INSERT INTO AnotherTable (name, email, age) values ('Bob Smith', 'bobsmith@gmail.com', 32)";

CustomQuery($sql);
thanks for the reply

Sergey Kornilov admin 5/21/2014

Like this?

$sql = "INSERT INTO AnotherTable (name, email, age, type) values ('Bob Smith', 'bobsmith@gmail.com', 32, 'expense')";

CustomQuery($sql);
M
minaras author 5/21/2014



Like this?

$sql = "INSERT INTO AnotherTable (name, email, age, type) values ('Bob Smith', 'bobsmith@gmail.com', 32, 'expense')";

CustomQuery($sql);



not exactly.
i have an add form and i use the insert into to after record added to add some values into other table . at the form i have two(2) fields but i want to insert into other table and another value which i don't have it in the form

Sergey Kornilov admin 5/21/2014

Sorry, I just don't follow. My example shows how you can insert a record into another table using some values that are not on the form.

M
minaras author 5/21/2014



Sorry, I just don't follow. My example shows how you can insert a record into another table using some values that are not on the form.


I have two tables
table1 ----id-----field1-----field2

table2 ----id-----table1_id--table1_field2-----other_field
when i add in table1 some values in field1 and field2 i want to insert them in table2 and a default value in other_field which is not at table1

M
minaras author 5/23/2014

global $conn;

$strSQLInsert = "INSERT INTO othertable (ref_id, custom_field, post_date)

VALUES (".$keys['id'].",'".

$values['custom_field']=('tax')."','".

$values['post_date']."')";

db_exec($strSQLInsert,$conn);
this is the answer thanks anyway