Forum Moderators: coopster

Message Too Old, No Replies

PHP form to edit MySQL

Editing MySql database entries via form

         

feralo

6:44 pm on Oct 2, 2005 (gmt 0)

10+ Year Member



i have a script to update (edit) entries in a MySQL databvase that i got from a mentor: it loops through every field in a specified row number and prints it into a pre-populated form.
The problem is this: i don't want to display every row the same way (i would rather display a photo than it's name, and for a larger text field i would like to display the text in a larger text box).

His solution seems pretty smooth :
"foreach ($dd as $field=>$value)"
my thought was to do a case switch, but i don't know how to set that up, any ideas?

mcibor

7:41 pm on Oct 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you thought about using phpMyAdmin tool which is free and can do really everything with mysql!

There's a way to get the type of the fields. Then for the text and blob fields you would put <textarea> Or just use the strlen and then case, or ifs.

However if you already know what structure the database has, then use a preformatted text and only add values dynamically.

That's my suggestion
Best regards
Michal Cibor

feralo

8:57 pm on Oct 3, 2005 (gmt 0)

10+ Year Member



mcibor, thanks- but maybe i forgot to mention that this form that i am after is for a friend of mine (who is brand new to computers) to make changes to his inventory database. i don't want to allow him to have access to everything!
i was seeking a way to populate text areas and make an SQL query based on the form values subbmitted.
I guess it is like a content management system...
i am getting pretty frustrated with this and i can't wait to find a solution!

coopster

12:58 am on Oct 4, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, feralo.

How about creating a data dictionary of sorts that keeps each column and it's related HTML <input> type in an associated row? Then when you read the column name in you link it to this *associate HTML <input> type* table and set the input type accordingly? A bit more complex than the loop you are currently using, but I'm not sure how else you might accomplish a similar task.

feralo

6:14 pm on Oct 17, 2005 (gmt 0)

10+ Year Member



Thank you very much for all the feedback, i have implemented the solutions and am very excited with the results!

SopaRangtrol

4:08 am on Oct 18, 2005 (gmt 0)



Rather than start a new thread I thought I'd ask a question here because it's somewhat related and it seems those posting on this thread would have the answer.

I'm trying to create a page that will let a user edit a mysql database. The fields I want to edit have mutliple lines and carriage returns.

I found some code that lets me fetch the fields ok, but I can't figure out how to have mulitple lines in the input box.

grandpa

4:23 am on Oct 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hello SopaRangtrol. Welcome to WebmasterWorld

The typical method to allow multiple input lines is to use the textarea elements.

<textarea>
Multiple lines
of text.
</textarea>

SopaRangtrol

11:37 pm on Oct 18, 2005 (gmt 0)



Thanks for the response Grandpa.
I've tried using <textarea>, but when I do all the code shows up in the box along with the data.
Could you tell me where I would put the <textarea> tag in the following? Thanks again.

<form action="saveitem.php" method="get">
<input type="hidden" name="NewsID" value="<?php echo($NewsID)?>">

<table border="1" cellpadding="3" cellspacing="3">
<tr>
<td align="left">
<input name="NewsStory" type="text" value="<?php echo htmlspecialchars ($NewsStory)?>" />
</td>
</tr>
<tr>
<td align="left">
<input name="NewsDo" type="text" value="<?php echo htmlspecialchars ($NewsDo)?>" />
</td>
</tr>
</table>

<br>
<input type="submit" value="Save Entry">
<br>
<a href="delete.php?NewsID=<?php echo($NewsID)?>">Delete Entry</a>

</form>

grandpa

3:45 am on Oct 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Possibly here?

<input name="NewsStory" type="textarea" value="<?php echo htmlspecialchars ($NewsStory)?>" />

With apologies for my previous example, it wasn't very complete. Also, keep in mind that the textarea does not expand till there is data in it. So if you define a textarea with 5 columns and 3 rows, it won't fill out that space until there is data in the space.

mcibor

8:14 am on Oct 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Grandpa, there's no type textarea in input.
You use the textarea tag. It doesn't have the value, and requires ending tag.

<textarea name="NewsStory"><?php echo htmlspecialchars ($NewsStory)?></textarea>

However using js you may clear it by value property: this.value=''
Best regards
Michal Cibor

grandpa

12:24 pm on Oct 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yep, I should have looked up an example beforehand. The top of my head can be a dangerous place.