Forum Moderators: coopster

Message Too Old, No Replies

PHP & MySQL - Updating & Deleting Records

         

bgcsm_bk

6:39 pm on Mar 15, 2005 (gmt 0)

10+ Year Member



I am very new to MySQL and have built myself a small database for website update requests. The thing is Instead of having a "enter the record id # and press edit" I want to have a small edit icon at the end of each record I am displaying in a table. I've got the table data box setup at the end of the record and this is what I put in it:

<form method="POST" action="change_form.php">
<input type="hidden" name="id" value="<? echo $id;?>">
<input type="submit" value="EDIT">
</pre>
</form>

Why doesn't this work? Why can't you use the id as a variable?

This is what works at the bottom of the table (but proves to be a hassle):

<form method="POST" action="change_form.php">
<pre>
Enter Line Number to Edit: <input type="text" name="id" size="5">
<input type="submit" value="Submit">
</pre>
</form>

RonPK

6:47 pm on Mar 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello bgcsm_bk, welcome to WebmasterWorld. You may find it useful to read the TOS (link at bottom of page), especially the policy on posting URLs.

As for your question: you can ofcourse use $id in the way you did. It will need to be created first and filled with data. Maybe you could provide some more information about how you're doing that.

[edit: forget about the URL-thing; it's allready gone ;)]

bgcsm_bk

6:56 pm on Mar 15, 2005 (gmt 0)

10+ Year Member



The id field is the key for the table set as INT with Auto Increment. Does that affect it at all?

I am just pulling out data to display it as a table. Is there any other way to use edit/delete buttons at the end og each record without using the <? echo $id?>

RonPK

7:18 pm on Mar 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So your code is
<input type="hidden" name="id" value="<? echo $id;?>">

and you're expecting output like
<input type="hidden" name="id" value="4578">

but you're getting
<input type="hidden" name="id" value="">

Is that a correct summary?

Tapolyai

7:31 pm on Mar 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The following will connect to a database yourDB, with user yourDBUSER and password yourDBpassword on www.yourdomain.com. Then get the data into a array called $row[], with each column name as the selector, i.e. in your case 'id' is one column, therefore you would access it as $row[id].

The code loops through all the returned rows from the table yourTABLE. I suggest you limit your SELECT statement.

<?php
mysql_connect( 'www.yourdomain.com', 'yourDBUSER', 'yourDBpassword' ) or die ( mysql_error() );
mysql_select_db( 'yourDB' ) or die ( mysql_error() );
$sql = "SELECT * FROM yourTABLE";
$result = mysql_query( $sql ) or die ( mysql_error() );
while ($row = mysql_fetch_array ($result))
{
?>
<form method="POST" action="change_form.php">
<input type="hidden" name="id" value="<?php echo $row[id];?>">
<input type="submit" value="EDIT">
</pre>
</form>
<?php }?>

Does this answer your question?

Before anyone jumps down my throat... this is simply a sceleton to start from)

bgcsm_bk

7:42 pm on Mar 15, 2005 (gmt 0)

10+ Year Member



Ron: Yes that is correct...

bgcsm_bk

7:47 pm on Mar 15, 2005 (gmt 0)

10+ Year Member



Thanks, but im still getting value=""

Tapolyai

2:34 am on Mar 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Dump the schema and post it here.

Did you check to make sure you have the right column name?

bgcsm_bk

2:53 am on Mar 17, 2005 (gmt 0)

10+ Year Member



Im very new to MySQL - what does dump the scema mean? You want the PHP Code?

ergophobe

1:11 am on Mar 21, 2005 (gmt 0)

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



The schema is your table structure. He's asking you how your database is structured (i.e. SQL code, not PHP code).

Tapolyai

4:37 am on Mar 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What do you use to manage your mySQL database?