Updateing a SQL select populated form
am 30.03.2008 09:16:17 von bangsundara
Dear Sir/Madam
As i am very new to PHP. i need some help from this group.
I have a form with 10 records populated from my_sql DB,
for simple say Name ,Age ,Sex,place,flg,MoveDate
(flg is chek mark)
say i have populated this info on the php form,
now i want to update only flg and MoveDate,
(MoveDate should be updated whenever flg is set)
Please advise me how to go about this in php with Pear Package
installed
Thanks in Advance
-evolu
Re: Updateing a SQL select populated form
am 30.03.2008 17:57:35 von George Maicovschi
On Mar 30, 10:16 am, bangsund...@gmail.com wrote:
> Dear Sir/Madam
>
> As i am very new to PHP. i need some help from this group.
>
> I have a form with 10 records populated from my_sql DB,
> for simple say Name ,Age ,Sex,place,flg,MoveDate
> (flg is chek mark)
>
> say i have populated this info on the php form,
> now i want to update only flg and MoveDate,
> (MoveDate should be updated whenever flg is set)
>
> Please advise me how to go about this in php with Pear Package
> installed
>
> Thanks in Advance
>
> -evolu
I didn't quite understand your request, could you please be more
speciffic? You want it updated IN the database on the POST of the form
or oyu want it updated live on the user side when the flg is changed?
Please be more speciffic, because the approach is rather different on
those two scenarios.
Re: Updateing a SQL select populated form
am 30.03.2008 19:11:45 von Jerry Stuckle
bangsundara@gmail.com wrote:
> Dear Sir/Madam
>
> As i am very new to PHP. i need some help from this group.
>
> I have a form with 10 records populated from my_sql DB,
> for simple say Name ,Age ,Sex,place,flg,MoveDate
> (flg is chek mark)
>
> say i have populated this info on the php form,
> now i want to update only flg and MoveDate,
> (MoveDate should be updated whenever flg is set)
>
> Please advise me how to go about this in php with Pear Package
> installed
>
> Thanks in Advance
>
> -evolu
>
Not hard. Fetch the data from your $_POST or $_GET array element and
use a SQL UPDATE statement to update the appropriate rows in your database.
If you want more help, you need to post what you've already tried so we
can help you with it.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Updateing a SQL select populated form
am 05.04.2008 20:52:10 von Jerry Stuckle
bangsundara@gmail.com wrote:
> Hello
> I sorry for writing late and thanks for the reply,
> this is an eg,
> what i want to do is , display all the records frm the table,
> when the "flg" column is changed i want change MoveDate
> and all the operation or over i want to update at once.
> Thanks in Advance
>
> -------------------
>
>
> test php
>
>
> Display 10 records at a time
>
> $sv = "localhost";
> $dbname = "test";
> $user = "root";
> $pass = "****";
> $enc_disp = "utf8";
> $enc_db = "utf8";
> function cnv_enc($string, $to, $from) {
> $det_enc = mb_detect_encoding($string, $from . ", " . $to);
> if ($det_enc and $det_enc != $to) {
> return mb_convert_encoding($string, $to, $det_enc);
> }
> else {
> return $string;
> }
> }
>
> $conn = mysql_connect($sv, $user, $pass) or die("DB Connect error");
> mysql_select_db($dbname) or die("DB select error");
>
> $st = 0;
> $lim = 10;
> $sql = "SELECT id, name, age, sex,place,flg,mdate FROM tbltest ORDER
> BY id LIMIT $st, $lim;";
> $res = mysql_query($sql, $conn) or die("Data extract error");
> echo "";
> echo "";
> echo "ID | ";
> echo "name | ";
> echo "age | ";
> echo "sex | ";
> echo "place | ";
> echo "flg | ";
> echo "mdate | ";
> echo "
";
> while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
> echo "";
> echo "".$row["id"]." | ";
> echo "".cnv_enc($row["name"], $enc_disp, $enc_db)." | ";
> echo "".$row["age"]." | ";
> echo "".cnv_enc($row["sex"], $enc_disp, $enc_db)." | ";
> echo "".cnv_enc($row["place"], $enc_disp, $enc_db)." | ";
> echo "".$row["flg"]." | ";
> echo "".$row["mdate"]." | ";
> echo "
";
> }
> echo "
";
> mysql_close($conn);
> ?>
>
>
> ------------------
>
OK, I'm not sure what your problem is, but I'll take a guess.
If you want the user to be able to change the flg entry, you need an
input element; in this case I'd probably use a checkbox. The name would
be something like "flg[]", with the value being the id.
When they submit the form, $_POST['flg'] will be an array with all of
the values of the checked boxes. Just build your SQL statement (an
UPDATE statement) to change the data you want.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Updateing a SQL select populated form
am 06.04.2008 07:15:57 von bangsundara
>>On 4月6日, 午前3:52, Jerry Stuckle wrote:
Thank you very much for your kind reply.
as per your advice, i made simple php like below pg,
now i have 2 doubt.
1.when i read a data to check box from database, how can i set
cheked when data is 1 not checked when data is 0.
Then
2. After displaying the data, whe the user clicked, then
date field can be entered, if not previous ino is retained
then the update whereever the user changed the checkbox and
date field onlt those info should be updated.
here is the sample code wher i have done till now
--------------------------
// connect to the database :mysql
$host="localhost"; // Host name.
$dbuser="test"; // MySQL username.
$dbpassword="******"; // MySQL password.
$database="test"; // Database name.
mysql_connect($host,$dbuser,$dbpassword) or die('Unable to connect to
thye database');
mysql_select_db($database) or die("Unable to select database");
$result = mysql_query("SELECT * FROM tbltest ORDER BY slno,empid");
$i = 0;
print "