473,327 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Dynamically generate update and delete form in PHP.

26
Hi there! Thanks for all the help so far. When my boss said I should be up to date as soon as possible, he meant last week. So I got a good rollicking when I came to work. Nice way to start my day....

Back to my problem:

I have a Text in Mysql: The code for fetching it in php is:
[PHP]
$id = intval( mysql_real_escape_string( $_GET['id'] ));
$query = "SELECT * FROM jos_issues WHERE jos_issues.contentid= '$id' ORDER BY text desc";
$result = mysql_query($query);

while($row= mysql_fetch_array($result)) {
echo"$row[text]<BR>";
}
[/PHP]

What I am looking for is a way to
a) press a link for update
b) dynamically print out a form for doing that.

All I am after is a way to edit and delete all the texts that are in my database. They are all linked to a content $id. So my table looks like this: id | text | contentid

I tried this code, but all I get is a very blank page with nothing on:

[PHP]<? include("c:/db.inc"); error_reporting(E_ALL);
ini_set('display_errors', '1');
//$id = intval( mysql_real_escape_string( $_GET['id'] ));
$id = 12; echo "id = $id";

$query = "SELECT * FROM jos_issues WHERE jos_issues.contentid= '$id'";
$result = mysql_query($query);
$num = mysql_numrows($result);
//mysql_close();

$i = 0;
while($i<$num) {
$text = mysql_result($result,$i,"text");
<form action="updated.php" method="post">
<input type="hidden" name="ud_id" value="<? echo $id; ?>">
Text: <input type="text" name="ud_text" value="<? echo $text; ?>"><br>
<input type="Submit" value="Update">
</form>

++$i;
}
?>[/PHP]

Let me know if you can help me with this one. There's no lunch for me today. I have to have finished at one o' clock, or I am screwed...


Thanks in advance.


Phopman
Aug 30 '07 #1
10 2935
ak1dnar
1,584 Expert 1GB
Are you trying to open a separate page for each "text links"?
for a example
Link1
Link2
Link3

Once I select Link2 the corresponding id will pass with the URL String to another Page and from that the dynamic form will print for do the updation for the Text Link.

If this is the thing Why this " ++$i" ?
And use the relative path for the include function, Why you using this OS related File path here? This is a web Application. So if you are want to deploy it to remote server, can expect the same paths ? No way. Always use the Web Server Related Paths. Here you can use the relative path to the db.php file.
Aug 30 '07 #2
prosad
27
hi,

you are using 'POST' for your form method instead of 'GET'. 'GET' will send through url for update on processing to your dynamically generated form.
Advise: Always use
Expand|Select|Wrap|Line Numbers
  1. <?php
for your php opening tags.
Aug 30 '07 #3
ak1dnar
1,584 Expert 1GB
hi,

you are using 'POST' for your form method instead of 'GET'. 'GET' will send through url for update on processing to your dynamically generated form.
Advise: Always use
Expand|Select|Wrap|Line Numbers
  1. <?php
for your php opening tags.
<?Php
?>
Its a good point. Nice work.
But, How come this GET and POST came here ?
As I can see first code snippet in the original post is working.
Then once click the links Form will print.(Hope we can fix It)
Then only we need to use the POST or GET to submit the values to updated.php. So what is the wrong with using POST here?
Aug 30 '07 #4
phopman
26
I solved the problem, albeit not in a very smooth and good way to be honest.

How do you use include so its not a OS adddress?

The way I did it was:

made three files:

1. List up all the content, add an update button
2. Called update. Loaded a white, ugly page with a text area, and a submit button. Captured the content from page 1.
3. update_ac Updates the database with the data from update.php.

I found the code on the Internet, and it's working, even though it's seriously ugly and so far from elegant it hurts.

But at least the boss isn't that pissed on me anymore. I hope.

Phopman
Aug 30 '07 #5
ak1dnar
1,584 Expert 1GB
Glad you got it working.

This
Expand|Select|Wrap|Line Numbers
  1. include("c:/db.inc");
With this.
Expand|Select|Wrap|Line Numbers
  1. include 'db.inc';
Change this according to document relative path.
but php can read the Files in out side the web root.

Good luck with your projects!
Aug 30 '07 #6
pbmods
5,821 Expert 4TB
I usually think that office romances are a bad idea; they usually end badly, and then they cause disruptions in morale and productivity.

Oh, you said UP to date. Gotcha :)

[EDIT: (see OP)]
Aug 30 '07 #7
phopman
26
Glad you got it working.

This
Expand|Select|Wrap|Line Numbers
  1. include("c:/db.inc");
With this.
Expand|Select|Wrap|Line Numbers
  1. include 'db.inc';
Thanks for the tip. Will do that from now on.

Phopman
Aug 31 '07 #8
prosad
27
Thanks for the tip. Will do that from now on.

Phopman
pbmods

I offered the suggestion on "GET' cos wat i thought from 1st post he wanted to update by passing a url visibly which i assume cant be done using 'POST'.
What I am looking for is a way to
a) press a link for update
i guess link is not meant as HREF link
correction? thnks.
Sep 3 '07 #9
pbmods
5,821 Expert 4TB
Heya, Prosad.

You can pass _GET variables even though your form is posting:
Expand|Select|Wrap|Line Numbers
  1. <form ... method="post" action="script.php?var1=value1&var2=value2">
  2.     <input ... />
  3.     .
  4.     .
  5.     .
  6. </form>
  7.  
Note that you can't pass _POST variables in the address bar, since that defeats half of the purpose of being able to post in the first place.
Sep 3 '07 #10
phopman
26
Thanks for all the help so far. The Project is nearing completion. I have decided to put update.php in a popup window, and it's working nicely!
Sep 13 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Dave Nouwens | last post by:
Hi All, Please accept my appologies in advance for what I expect will be a reasonably simple question. I have an html form (which is generated in php) which contains a number of rows (one row...
27
by: Nicholas Couch | last post by:
I have a little form with a couple of dynamically generated list boxes. When the user makes a selection from the first box, the second box is refreshed. When they make a selection from the second...
2
by: Chad | last post by:
I have a problem that I am desperate to understand. It involves dynamically adding controls to a Table control that is built as a result of performing a database query. I am not looking to...
1
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
2
by: jmarendo | last post by:
Hello, After reading through the "Table Basics - DOM - Refer to table cells" example at mredkj.com , I modified the code for my own purposes. In the modified version, I create a hyperlink and...
5
by: Amoril | last post by:
I've read quite a few different message on various boards and for some reason I'm still having trouble wrapping my head around this viewstate maintenance and trying to get these dynamically created...
0
by: lianaent | last post by:
Hi All, I'm brand new to asp.net 2.0, and have a simple task of just creating a quick and dirty data entry form with SQL Server 2005 on the back end. I added a gridview to my form, and I can...
2
by: ssmith147 | last post by:
Hi, I'm somewhat familiar with access and vb programming (I can read someone else's code, for the most part), but I'm still very green when it comes to creating solutions for my own needs. I'm...
0
by: Slickuser | last post by:
From my PHP page: Grab all data from the database. Go through a loop to generate the HTML. Client side: From the Color drop menu list, if a user change the value. It will grab that value &...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.