954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to save data from a variable to a table.

Hi everyone!

I have traced the variables that stores the data. All i have to do is to save all these in a table. Pls help. Here are the variables and its content:

Variables:
$pmaster_id = get_param("master_id");
//test------------------------------
print "master ID = $pmaster_id";
$master_id = $pmaster_id;
$id = explode("-", $master_id);
echo "
client id = $id[0]\n";
echo "
subject id = $id[1]";
echo "
matter id = $id[2]";
echo "
extra = $id[3]";
//test end---------------------------

$bsnum=get_param("bsnum");
//test------------------------------------------------------------------
echo "
BS Number: $bsnum";
//tets end--------------------------------------------------------------

Output:

master ID = 0708-11-0001-00
client id = 0708
subject id = 11
matter id = 0001
extra = 00
BS Number: 000001

Please help me on how to save these values into database. I am new both to Php4 and MySQL as well as to the third party that is the Code Charge Studio. Thanks...

dudegio
Junior Poster in Training
66 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

Hi everyone! I have traced the variables that stores the data. All i have to do is to save all these in a table. Pls help. Here are the variables and its content: Variables: $pmaster_id = get_param("master_id"); //test------------------------------ print "master ID = $pmaster_id"; $master_id = $pmaster_id; $id = explode("-", $master_id); echo "
client id = $id[0]\n"; echo "
subject id = $id[1]"; echo "
matter id = $id[2]"; echo "
extra = $id[3]"; //test end--------------------------- $bsnum=get_param("bsnum"); //test------------------------------------------------------------------ echo "
BS Number: $bsnum"; //tets end-------------------------------------------------------------- Output: master ID = 0708-11-0001-00 client id = 0708 subject id = 11 matter id = 0001 extra = 00 BS Number: 000001

Please help me on how to save these values into database. I am new both to Php4 and MySQL as well as to the third party that is the Code Charge Studio. Thanks...


once you have your array of values ($id) you only then need to use this to construct your sql statement, in this case ...
"insert into table values '{$id[0]}', '{$id[1]}', '$id[2]}', '$id[3]}','$bsnum'".
As long as there are no other fields in the table, apart from the master_id,client_id,subject_id,matter_id,extra and BSNumber, this should save fine (I am also making the assumption that the field types are text since it appears you want to preserve the zero paddings).

you could achieve the same effect less verbosely with the following ... "insert into table values ( ' " . implode (" ',' ", $id) . " ' ) ".

Hope this helps :)

binaryten
Newbie Poster
2 posts since Jun 2007
Reputation Points: 10
Solved Threads: 1
 

Thanks for help. I already find solution to my problem through internet searching. I did the same thing like what you have suggested. I very much appreciate your help. Thanks a lot buddy!

dudegio
Junior Poster in Training
66 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You