calculated form ID to new .php

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
redtux
Forum Newbie
Posts: 7
Joined: Thu Mar 04, 2004 8:40 am

calculated form ID to new .php

Post 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?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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... ;)
Post Reply