Page 1 of 1

calculated form ID to new .php

Posted: Thu Mar 04, 2004 2:02 pm
by redtux
What I am tryng to is this

I have a form which pulls a set of data from pg in a table format

eg:

Code: Select all

echo('<input type="text" name="id'. $row .'" value="' .$myrow&#1111;0] .'">');
where the value is concatenated with the row number value

now what I want to do is this, use this calculated value to do an update query as follows

Code: Select all

<?php
$db = pg_connect("dbname=data_cc");
$id_chg="id'. $row .'";
$firstchg="$firstname'. $row .'";
$query = "UPDATE tb_contacts SET first_name='$firstchg' WHERE contact_id='$id_chg'";
$result = pg_exec($db, $query);
if (!$result) &#123;
printf ("ERROR");
$errormessage = pg_errormessage($db);
echo $errormessage;
exit;
&#125;
printf ("These values were updated in the database - ");
pg_close();
?>
Is what I am trying possible?

Posted: Sun Mar 07, 2004 1:10 pm
by JAM
Not ideal, but not impossible. (Not sure I really understand the point of concatenating it like this...)

Code: Select all

// simple example...
$row = 4;
$id_chg = 'id' . $row; 
echo $id_chg; // id4
echo '<hr>';
echo substr($id_chg,2); // 4
As you allready are getting information from the database, I asume that you should be able to get the unique id field (here: contact_id). Why not add that as a <hidden>-tag, that you later use to know what rowset to update?

If I misunderstood you completely, sorry... ;)