Thread: Parsing Data, Table to Form
Hi. I have done a search on one of my PHP pages, and displayed the results in a table on another page. Then when a button is clicked, i want to be able to display the table information in editable form fields, so that the data may be altered and the database updated. Does anyone have any ideas how i may be able to carry this out? :-) It's the parsing the data that i am unable to do. Thanx Again Yaz _________________________________________________________________ Use MSN Messenger to send music and pics to your friends http://www.msn.co.uk/messenger
Look at these functions in the php documentation: pg_Query, pg_NumRows, pg_Fetch_Object, and pg_FreeResult http://www.php.net/manual/en/ref.pgsql.php Small example $conn = pg_Connect("host=localhost dbname=test user=postgres"); $result = pg_Query($conn, "SELECT * FROM mytable ORDER BY id LIMIT 1 OFFSET 0;"); $rows = pg_NumRows($result); if ( $rows == 0 ) echo "Sorry no data found.\n"; else { $data = pg_Fetch_Object($result, 0); pg_FreeResult($result); echo "<form method=post action=myaction.php>\n"; echo "Field 1: <input type=text name=\"field1\" value=\"$data->field1\"><br />\n"; echo "Field 2: <input type=text name=\"field2\" value=\"$data->field2\"><br />\n"; echo "Field 3: <input type=text name=\"field2\" value=\"$data->field3\"><br />\n"; echo "<input type=submit value=update></form>\n"; } Yasmine Kedoo wrote: > Hi. > > I have done a search on one of my PHP pages, and displayed the results > in a table on another page. > > Then when a button is clicked, i want to be able to display the table > information in editable form fields, so that the data may be altered > and the database updated. > > Does anyone have any ideas how i may be able to carry this out? :-) > It's the parsing the data that i am unable to do. > > Thanx Again > > Yaz > > _________________________________________________________________ > Use MSN Messenger to send music and pics to your friends > http://www.msn.co.uk/messenger > > > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly
Yaz...... > i want to be able to display the table information in editable form > fields, so that the data may be altered and the database updated. If by table information, you mean the information contained in the table, then what I do is get one row's data and load it into variables. I use the variables as the default text in the form (check the html standard). After the user makes any edits he updates the entire row. This only works with text boxes, with radio buttons and on/off buttons you have to generate different html depending on the existing button state. It's not complicated, just tedious to code if it has lots of buttons. If it's only text it's easier. I think I started with an example someone posted on php.net, maybe you can search for that and use it for reference, too. I think it has a subroutine to generate the buttons preselected by the existing state of the database. My script is long, involving switches to display the possible rows to be edited for a user on the first pass, then displaying the info for the row selected in an editable form, then updating (or inserting the row if it doesn't exist) and going back to displaying all the possible rows for that user. I have to study it for a while myself, remembering how it works before I make any changes to it! Hopefully somebody else has a more basic example. If by table information you mean the definition of a table in the database, then that would be diferent, although still involving somewhat the same type of script, just working on different database information. All my table definitions are static in my database, so I've never done it from a script, though. brew ========================================================================== Strange Brew (brew@theMode.com) Check out my Musician's Online Database Exchange (The MODE Pages) http://www.TheMode.com ==========================================================================
Hi again. I have carried out a search, then displayed the results in a table on a php page called admininfo.php: $row = pg_fetch_object($result, 0); $test = ""; for ($rw = 0; $rw < $maxrows; $rw++) { echo " <tr> "; for ($fld = 0; $fld < $maxfields ; $fld++) { echo "<td width=\"418\" class=\"tabletext\" height=\"38\">"; echo pg_Result($result,$rw,$fld); $test .= pg_Result($result,$rw,$fld); echo "</td>"; echo "<form method=post action=updaad.php>\n"; } echo "<td width=\"194\" class=\"tabletext\" height=\"38\"> </td> </tr>"; } Now, i would like to parse the information displayed in the table to textfields on the page updaad.php, i've used a link to do this: <a href="updaad.php">Update</a> On the page updaad.php, i have displyed the textfields using the following code: echo "Admin ID Number: <input type=text name=\"formadid\" value=\"$fld\"><br />\n"; echo "Name: <input type=text name=\"formname\" value=\"$fld\"><br />\n"; echo "Surname: <input type=text name=\"formsurname\" value=\"$fld\"><br />\n"; echo "Phone: <input type=text name=\"formphone\" value=\"$fld\"><br />\n"; echo "Email: <input type=text name=\"formemail\" value=\"$fld\"><br />\n"; echo "Username: <input type=text name=\"formusername\" value=\"$fld\"><br />\n"; echo "Password: <input type=text name=\"formpassword\" value=\"$fld\"><br />\n"; echo "Building: <input type=text name=\"formbuilding\" value=\"$fld\"><br />\n"; echo "Postcode: <input type=text name=\"formpsotcode\" value=\"$fld\"><br />\n<br>"; echo "<input type=submit value=Update></form>\n"; but i am unable to write the information displayed in the table in admininfo.php, to the textfields in updaad.php. Has anybody got any suggestions? :-) Thanx Yaz >From: brew@theMode.com >To: Yasmine Kedoo <yazkedoo@hotmail.com> >Subject: Re: [PHP] Parsing Data, Table to Form >Date: Sun, 9 May 2004 11:36:14 -0400 (EDT) > > >Yaz...... > > > i want to be able to display the table information in editable form > > fields, so that the data may be altered and the database updated. > >If by table information, you mean the information contained in the table, >then what I do is get one row's data and load it into variables. I use >the variables as the default text in the form (check the html standard). >After the user makes any edits he updates the entire row. > >This only works with text boxes, with radio buttons and on/off buttons you >have to generate different html depending on the existing button state. > >It's not complicated, just tedious to code if it has lots of buttons. If >it's only text it's easier. I think I started with an example someone >posted on php.net, maybe you can search for that and use it for reference, >too. I think it has a subroutine to generate the buttons preselected by >the existing state of the database. > >My script is long, involving switches to display the possible rows to be >edited for a user on the first pass, then displaying the info for the row >selected in an editable form, then updating (or inserting the row if it >doesn't exist) and going back to displaying all the possible rows for that >user. I have to study it for a while myself, remembering how it works >before I make any changes to it! Hopefully somebody else has a more basic >example. > >If by table information you mean the definition of a table in the >database, then that would be diferent, although still involving somewhat >the same type of script, just working on different database information. >All my table definitions are static in my database, so I've never done it >from a script, though. > >brew > > >========================================================================== > Strange Brew (brew@theMode.com) > Check out my Musician's Online Database Exchange (The MODE Pages) > http://www.TheMode.com > >========================================================================== > _________________________________________________________________ It's fast, it's easy and it's free. Get MSN Messenger today! http://www.msn.co.uk/messenger
Hi Yasmine, If you click the link only, it will not submit the form and pass the information on. You need to have a 'submit' button in your form and hit that. Chris. -----Original Message----- From: pgsql-php-owner@postgresql.org [mailto:pgsql-php-owner@postgresql.org] On Behalf Of Yasmine Kedoo Sent: Monday, May 10, 2004 9:18 AM To: pgsql-php@postgresql.org Subject: Re: [PHP] Parsing Data, Table to Form Hi again. I have carried out a search, then displayed the results in a table on a php page called admininfo.php: $row = pg_fetch_object($result, 0); $test = ""; for ($rw = 0; $rw < $maxrows; $rw++) { echo " <tr> "; for ($fld = 0; $fld < $maxfields ; $fld++) { echo "<td width=\"418\" class=\"tabletext\" height=\"38\">"; echo pg_Result($result,$rw,$fld); $test .= pg_Result($result,$rw,$fld); echo "</td>"; echo "<form method=post action=updaad.php>\n"; } echo "<td width=\"194\" class=\"tabletext\" height=\"38\"> </td> </tr>"; } Now, i would like to parse the information displayed in the table to textfields on the page updaad.php, i've used a link to do this: <a href="updaad.php">Update</a> On the page updaad.php, i have displyed the textfields using the following code: echo "Admin ID Number: <input type=text name=\"formadid\" value=\"$fld\"><br />\n"; echo "Name: <input type=text name=\"formname\" value=\"$fld\"><br />\n"; echo "Surname: <input type=text name=\"formsurname\" value=\"$fld\"><br />\n"; echo "Phone: <input type=text name=\"formphone\" value=\"$fld\"><br />\n"; echo "Email: <input type=text name=\"formemail\" value=\"$fld\"><br />\n"; echo "Username: <input type=text name=\"formusername\" value=\"$fld\"><br />\n"; echo "Password: <input type=text name=\"formpassword\" value=\"$fld\"><br />\n"; echo "Building: <input type=text name=\"formbuilding\" value=\"$fld\"><br />\n"; echo "Postcode: <input type=text name=\"formpsotcode\" value=\"$fld\"><br />\n<br>"; echo "<input type=submit value=Update></form>\n"; but i am unable to write the information displayed in the table in admininfo.php, to the textfields in updaad.php. Has anybody got any suggestions? :-) Thanx Yaz >From: brew@theMode.com >To: Yasmine Kedoo <yazkedoo@hotmail.com> >Subject: Re: [PHP] Parsing Data, Table to Form >Date: Sun, 9 May 2004 11:36:14 -0400 (EDT) > > >Yaz...... > > > i want to be able to display the table information in editable form > > fields, so that the data may be altered and the database updated. > >If by table information, you mean the information contained in the >table, then what I do is get one row's data and load it into variables. >I use the variables as the default text in the form (check the html >standard). After the user makes any edits he updates the entire row. > >This only works with text boxes, with radio buttons and on/off buttons >you have to generate different html depending on the existing button >state. > >It's not complicated, just tedious to code if it has lots of buttons. >If it's only text it's easier. I think I started with an example >someone posted on php.net, maybe you can search for that and use it for >reference, too. I think it has a subroutine to generate the buttons >preselected by the existing state of the database. > >My script is long, involving switches to display the possible rows to >be edited for a user on the first pass, then displaying the info for >the row selected in an editable form, then updating (or inserting the >row if it doesn't exist) and going back to displaying all the possible >rows for that user. I have to study it for a while myself, remembering >how it works before I make any changes to it! Hopefully somebody else >has a more basic example. > >If by table information you mean the definition of a table in the >database, then that would be diferent, although still involving >somewhat the same type of script, just working on different database >information. All my table definitions are static in my database, so >I've never done it from a script, though. > >brew > > >======================================================================= === > Strange Brew (brew@theMode.com) > Check out my Musician's Online Database Exchange (The MODE Pages) > http://www.TheMode.com > >======================================================================= >=== > _________________________________________________________________ It's fast, it's easy and it's free. Get MSN Messenger today! http://www.msn.co.uk/messenger ---------------------------(end of broadcast)--------------------------- TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
The task you are trying to do is easy enough once you understand the steps involved. From your example the following major steps (programs) are needed. 1. Display the data from the database in a table in HTML (admininfo.php) 2. Select one row from the table for update (I'm guessing this step is intended). 3. Display selected row in a form in HTML for operator update. (updaat.php) 4. Write changes made in 3 back to postgresql database table. (not_named_yet.php) My way of doing this (and there are many other ways to do this) is to have in step 2 the key or keys that will identify the row from the database in the html as hidden fields. echo "<input type=\"hidden\" name=\"yourkeyid\" value=\"$keyoftabledata\" >"; In the updaat.php program the hidden fields are assigned to php variables using the $_POST ["yourkeyid"] like: $keyforrow = $_POST["yourkeyid"]; You use the key to get the data again from the database and then display it in the new form for update. The final step involves the final php program picking up all the entered data from the form and updating the database, again the key to the database table may need to be hidden and assigned to variables. If this is where you are trying to go I can expand or send you some sample working php programs. Hope this helps, Paul Yasmine Kedoo wrote: > Hi again. > > I have carried out a search, then displayed the results in a table on > a php page called admininfo.php: > > $row = pg_fetch_object($result, 0); > > $test = ""; > > for ($rw = 0; $rw < $maxrows; $rw++) > { > echo " <tr> "; > > for ($fld = 0; $fld < $maxfields ; $fld++) > { > > echo "<td width=\"418\" class=\"tabletext\" > height=\"38\">"; > echo pg_Result($result,$rw,$fld); > $test .= pg_Result($result,$rw,$fld); > echo "</td>"; > > echo "<form method=post action=updaad.php>\n"; > > } > echo "<td width=\"194\" class=\"tabletext\" height=\"38\"> > </td> </tr>"; > > } > > Now, i would like to parse the information displayed in the table to > textfields on the page updaad.php, i've used a link to do this: > > <a href="updaad.php">Update</a> > > On the page updaad.php, i have displyed the textfields using the > following code: > > echo "Admin ID Number: <input type=text name=\"formadid\" > value=\"$fld\"><br />\n"; > echo "Name: <input type=text name=\"formname\" value=\"$fld\"><br />\n"; > echo "Surname: <input type=text name=\"formsurname\" > value=\"$fld\"><br />\n"; > echo "Phone: <input type=text name=\"formphone\" value=\"$fld\"><br > />\n"; > echo "Email: <input type=text name=\"formemail\" value=\"$fld\"><br > />\n"; > echo "Username: <input type=text name=\"formusername\" > value=\"$fld\"><br />\n"; > echo "Password: <input type=text name=\"formpassword\" > value=\"$fld\"><br />\n"; > echo "Building: <input type=text name=\"formbuilding\" > value=\"$fld\"><br />\n"; > echo "Postcode: <input type=text name=\"formpsotcode\" > value=\"$fld\"><br />\n<br>"; > echo "<input type=submit value=Update></form>\n"; > > but i am unable to write the information displayed in the table in > admininfo.php, to the textfields in updaad.php. > > Has anybody got any suggestions? :-) > > Thanx > > Yaz > > > > >> From: brew@theMode.com >> To: Yasmine Kedoo <yazkedoo@hotmail.com> >> Subject: Re: [PHP] Parsing Data, Table to Form >> Date: Sun, 9 May 2004 11:36:14 -0400 (EDT) >> >> >> Yaz...... >> >> > i want to be able to display the table information in editable form >> > fields, so that the data may be altered and the database updated. >> >> If by table information, you mean the information contained in the >> table, >> then what I do is get one row's data and load it into variables. I use >> the variables as the default text in the form (check the html standard). >> After the user makes any edits he updates the entire row. >> >> This only works with text boxes, with radio buttons and on/off >> buttons you >> have to generate different html depending on the existing button state. >> >> It's not complicated, just tedious to code if it has lots of >> buttons. If >> it's only text it's easier. I think I started with an example someone >> posted on php.net, maybe you can search for that and use it for >> reference, >> too. I think it has a subroutine to generate the buttons preselected by >> the existing state of the database. >> >> My script is long, involving switches to display the possible rows to be >> edited for a user on the first pass, then displaying the info for the >> row >> selected in an editable form, then updating (or inserting the row if it >> doesn't exist) and going back to displaying all the possible rows for >> that >> user. I have to study it for a while myself, remembering how it works >> before I make any changes to it! Hopefully somebody else has a more >> basic >> example. >> >> If by table information you mean the definition of a table in the >> database, then that would be diferent, although still involving somewhat >> the same type of script, just working on different database information. >> All my table definitions are static in my database, so I've never >> done it >> from a script, though. >> >> brew >>
Hi Yasmine, Using your example as much as I can and assuming a single row is being selected for updating. Your patid will be used in place of my keyoftabledata (key of table data) variable. In admininfo.php: <?php for ($rw = 0; $rw < $maxrows; $rw++) { for ($fld = 0; $fld < $maxfields ; $fld++) { echo pg_Result($result,$rw,$fld); } // I will assume that the key field is the first field in your table result pg_result($result,0,$patid); // add this line - you could combine in one line echo "<form method=post action=updaad.php>\n"; echo "<input type=\"hidden\" name=\"patid\"value=\"$patid\" >" // add this line echo "<input type=\"submit\" value=\"Update\" >" // add this line as well echo "</form>"; } // this will give an update button for each row of data from your result table // I have left out the html table so as to simplify and avoid html issues between tables and forms // The only information being passed to updaat.php is the name patid and its value ?> So updaat.php will have the following: <?php $patid = $_POST["patid']; // now use $patid to query the db for the row to update $rowtoupdate = pg_exec($dbcon, "select patid, name, surname, phone, email from your_table_name where patid=$patid" ); // patid is int ? // where your_table_name is the name in postgresql // and patid, name, surname, phone, email are the column names in the table // // add error checking etc here // next lines assumes single row is available in $rowtoupdate list($formatid,$formname,$formsurname,$formphone,$formemail) = pg_fetch_row($rowtoupdate, 0 ); // need to start new form echo "<form method=post action=writeat.php>\n"; // name the next php program here echo "Admin ID Number: <input type=text name=\"formadid\" value=\"$formatid\"><br />\n"; echo "Name: <input type=text name=\"formname\" value=\"$formname\"><br />\n"; echo "Surname: <input type=text name=\"formsurname\" value=\"$formsurname\"><br />\n"; echo "Phone: <input type=text name=\"formphone\" value=\"$fornphone\"><br />\n"; echo "Email: <input type=text name=\"formemail\" value=\"$formemail\"><br />\n"; // and so on for all your data // need an update or accept button before writing back data changes echo "<input type=\"submit\" value=\"Make Changes\" >" echo "</form>"; ?> So finally we have the program that puts the data back to the database. I have used writeat.php in this example, but use whatever name fits into your naming convention. The essence of writeat.php: <?php $patid = $_POST["formatid"]; $name = $_POST["formname"]; $surname = $_POST["formsurname"] $phone = $_POST["formphone"]; $email = $+POST["formemail"]; $dbcon = pg_connect("dbname=your_db_name user=your_user"); pg_exec( $dbcon, "update your_table_name set patid=$patid, // allowing the key to be changed !!!! name='$name', surname='$surname', phone='$phone', email='$email' where patid=$patid" ); ?> This is only one way of doing the required steps and it leaves all error checking out . One thing I don't like is allowing key fields to be changed so easily by operator input, but you may have valid reasons for this. Generally I hide the key fields from update screens unless required or useful to see. My real programs have a lot of additional stuff but I will try and find the simplest one to send to you off line. Paul Yasmine Kedoo wrote: > Hi Paul. > > I think u do understand what i'm trying to do :-) , but i'm not too > sure i understand what u've told me ;-) > > Do i need to repeat the following line for each bit of data in the table: > > echo "<input type=\"hidden\" name=\"patid\"value=\"$keyoftabledata\" >"; > > where 'patid' is the ID field in the database. But I am unsure what to > do with $keyoftabledata. What does this relate to? > > What does $keyforrow relate to here: > > $keyforrow = $_POST["yourkeyid"]; > > Do i need to do this line a number of times for all data in the html > table? > > If u dont mind, it would be nice if u could send me some sample > programs relating to this topic. > > Thanx Again, > > Yasmine >
Hi Yasmine, Could you post line 66 or point out which line is 66 in updaad.php. From the error message I would expect it to contain something like: pg_fetch_row($rowtoupdate, 0) From your code, if this failed it would be before the display of data in the form, and not after you click the update button. Which has me a little perplexed. In fact I would expect clicking on the update button to start loading program adupdate.php as per instructions in this line: echo "<form method=post action=adupdate.php>\n"; So unless this error was hidden somehow by the form and then displayed after the click of update button, but that doesn't fit with my knowledge of browser behaviour. I am hoping the content on line 66 and a bit above and below it can help relate the error message to the code. Paul Yasmine Kedoo wrote: > but when i click the submit button on updaad.php, i'm getting the > following error : > > Warning: Unable to jump to row 0 on PostgreSQL result index 2 in > /home/webpages/yamkedoo/Project/updaad.php on line 66 > > and nothing is being parsed to the textfields on adupdate.php > (writeat.php). > > Do u know wat the problem may be? :-) > > Thanx again, your help is much appreciated > > Yasmine
Hi Yasmine, A lack of error checking has caught us out here. Plus some syntax in the select and where clause. The adid in admininfo table is an integer, and I gave you code for using a character type key. So change ... WHERE adid='$adid' to WHERE adid=$adid (drop the ' ) While there you could add some error condition checking like below: $rowtoupdate = pg_exec($database, "SELECT adid, name, sur, phone, email, username, password, building, postcode FROM admininfo WHERE adid=$adid"); if ( ! pg_numrows($rowstoupdate) == 1 ) // expecting a single row only { echo "<h2>Error in getting information from table</h2>"; // add whatever you want here to help you see what went wrong } else{ list($formadid, $formname, $formsurname, $formphone, $formemail, $formusername, $formpassword, $formbuilding,$formpostcode) = pg_fetch_row($rowtoupdate, 0); } Keep going you're getting close. Yasmine Kedoo wrote: > Hey Paul. > > Yes, the error is exactly that :-). I've put in the following code on > admininfo.php: > > else > { > > $row = pg_fetch_object($result, 0); > > $test = ""; > > for ($rw = 0; $rw < $maxrows; $rw++) > { > > echo " <tr> "; > > for ($fld = 0; $fld < $maxfields ; $fld++) > > { > > > /*echo "<td width=\"418\" > class=\"tabletext\" height=\"38\">"; > > > echo "</td>"; > echo $test .= pg_Result($result,$rw,$fld);*/ > > echo pg_Result($result,$rw,$fld); > > } > > /*echo "<td width=\"194\" class=\"tabletext\" > height=\"38\"> </td> </tr>";*/ > > > pg_result($result,0,$adid); > echo "<form method=post action=updaad.php>\n"; > echo "<input type=\"hidden\" > name=\"adid\"value=\"$adid\" >"; > echo "<input type=\"hidden\" > name=\"name\"value=\"$name\" >"; > echo "<input type=\"hidden\" > name=\"surname\"value=\"$surname\" >"; > echo "<input type=\"hidden\" > name=\"phone\"value=\"$phone\" >"; > echo "<input type=\"hidden\" > name=\"email\"value=\"$email\" >"; > echo "<input type=\"hidden\" > name=\"username\"value=\"$username\" >"; > echo "<input type=\"hidden\" > name=\"password\"value=\"$password\" >"; > echo "<input type=\"hidden\" > name=\"building\"value=\"$building\" >"; > echo "<input type=\"hidden\" > name=\"postcode\"value=\"$postcode\" >"; > echo "<input type=\"submit\" value=\"Update\" >"; > echo "</form>"; > } > } > > and on page updaad.php, the error: > > Warning: Unable to jump to row 0 on PostgreSQL result index 2 in > /home/webpages/yamkedoo/Project/updaad.php on line 66 > > is displayed, along with empty textfields. The relevant code for > updaad.php is as follows: > > $adid = $_POST['adid']; > $name = $_POST['name']; > $surname = $_POST['surname']; > $phone = $_POST['phone']; > $email = $_POST['email']; > $username = $_POST['username']; > $password = $_POST['password']; > $building = $_POST['building']; > $postcode = $_POST['postcode']; > > $rowtoupdate = pg_exec($database, "SELECT adid, name, sur, > phone, email, username, password, building, postcode FROM admininfo > WHERE adid='$adid'"); > > list($formadid, $formname, $formsurname, $formphone, $formemail, > $formusername, $formpassword, $formbuilding,$formpostcode) = > pg_fetch_row($rowtoupdate, 0); > > echo "<form method=post action=adupdate.php>\n"; > echo "Admin ID Number: <input type=text name=\"formadid\" > value=\"$formadid\"><br />\n"; > echo "Name: <input type=text name=\"formname\" > value=\"$formname\"><br />\n"; > echo "Surname: <input type=text name=\"formsurname\" > value=\"$formsurname\"><br />\n"; > echo "Phone: <input type=text name=\"formphone\" > value=\"$formphone\"><br />\n"; > echo "Email: <input type=text name=\"formemail\" > value=\"$formemail\"><br />\n"; > echo "Username: <input type=text name=\"formusername\" > value=\"$formusername\"><br />\n"; > echo "Password: <input type=text name=\"formpassword\" > value=\"$formpassword\"><br />\n"; > echo "Building: <input type=text name=\"formbuilding\" > value=\"$formbuilding\"><br />\n"; > echo "Postcode: <input type=text name=\"formpostcode\" > value=\"$formpostcode\"><br />\n"; > echo "<BR>"; > echo "<input type=\"submit\" value=\"Update\" >"; > echo "</form>"; > > I am not too sure how to fix the error on page admininfo.php. Any > ideas? It doesn't seem to be parsing the data to the textfields. > > Thanx again, > > Yasmine > > >> From: Paul Lynch <paul.lynch@exemail.com.au> >> To: Yasmine Kedoo <yazkedoo@hotmail.com>, pgsql-php@postgresql.org >> Subject: Re: [PHP] Parsing Data, Table to Form >> Date: Sun, 16 May 2004 22:14:15 +1000 >> >> Hi Yasmine, >> >> Could you post line 66 or point out which line is 66 in updaad.php. >> From the error message I would expect it to contain something like: >> pg_fetch_row($rowtoupdate, 0) >> >> From your code, if this failed it would be before the display of data >> in the form, and not after you click the update button. Which has me >> a little perplexed. In fact I would expect clicking on the update >> button to start loading program adupdate.php >> as per instructions in this line: >> echo "<form method=post action=adupdate.php>\n"; >> So unless this error was hidden somehow by the form and then >> displayed after the click of update button, but that doesn't fit with >> my knowledge of browser behaviour. >> >> I am hoping the content on line 66 and a bit above and below it can >> help relate the error message to the code. >> >> Paul >> >> Yasmine Kedoo wrote: >> >>> but when i click the submit button on updaad.php, i'm getting the >>> following error : >>> >>> Warning: Unable to jump to row 0 on PostgreSQL result index 2 in >>> /home/webpages/yamkedoo/Project/updaad.php on line 66 >>> >>> and nothing is being parsed to the textfields on adupdate.php >>> (writeat.php). >>> >>> Do u know wat the problem may be? :-) >>> >>> Thanx again, your help is much appreciated >>> >>> Yasmine >> >> >> > > _________________________________________________________________ > Use MSN Messenger to send music and pics to your friends > http://www.msn.co.uk/messenger > > >
Hi Yasmine, Just noticed a mistake in the error checking. I typed : if ( ! pg_numrows($rowstoupdate) == 1 ) // expecting a single row only however $rowstoupdate should be $rowtoupdate - take out the 's' . That will hopefully catch the lack of rows. Now the real problem lies in the pg_exec statement. It is not getting the data from the table. And its problem is possibly in the $database connection value. You should have somewhere before the pg_exec a line like: $database=pg_connect("dbname=your_db user=your_user"); The error that displays is not the cause of the error, it is back up in the code that you need to look. Hopefully you will find the missing or wrong piece up there. It is also a good practice to include lots of error checks in your program to help isolate where things are going wrong. It is also good not to make typing errors when writing error checks :-[ as I did. HTH Paul Yasmine Kedoo wrote: > Hey Paul. > > I've actually used CHAR for the id, as it involves both numbers and > letters. That's y i actually left the single inverted commas around > $adid, '$adid'. > > So i too am confused as to why the code doesn't work. Can't put my > finger on the problem at the mo, but still get the same error. > > Warning: Unable to jump to row 0 on PostgreSQL result index 2 in > /home/webpages/yamkedoo/Project/updaad.php on line 66 > > I've added ur suggestion, but still the same thing. If u could help > any further, that would be great :-) > > Thanx again, > > Yasmine > > > > > > >> From: Paul Lynch <paul.lynch@exemail.com.au> >> To: pgsql-php@postgresql.org >> Subject: Re: [PHP] Parsing Data, Table to Form >> Date: Mon, 17 May 2004 22:21:00 +1000 >> >> Hi Yasmine, >> >> A lack of error checking has caught us out here. Plus some syntax in >> the select and where clause. The adid in admininfo table is an >> integer, and I gave you code for using a character type key. So >> change ... WHERE adid='$adid' to WHERE adid=$adid (drop the ' ) >> While there you could add some error condition checking like below: >> >> $rowtoupdate = pg_exec($database, "SELECT adid, name, sur, phone, >> email, username, password, building, postcode FROM >> admininfo WHERE adid=$adid"); >> if ( ! pg_numrows($rowstoupdate) == 1 ) // expecting a >> single row only >> { >> echo "<h2>Error in getting information from table</h2>"; >> // add whatever you want here to help you see what went wrong >> } else{ >> list($formadid, $formname, $formsurname, $formphone, >> $formemail, $formusername, >> $formpassword, >> $formbuilding,$formpostcode) = pg_fetch_row($rowtoupdate, 0); >> } >> >> Keep going you're getting close. >>