ragrim Posted May 23, 2008 Share Posted May 23, 2008 Hi, apologies for the newbie question hehe, but im stuck and i just cant find the answer to what will be the easier question ever i have website that has pictures on it and when you click one it loads a php frame which displays info about the page, now what i want is an edit button which then sends the info of the mysql record i was just looking at into a form which i can then edit and update, now i know how to delete record, add records etc etc, but i just dont know how to load a record into a form! by form i mean an editible text field. so heres what i got <? include 'config.php'; include 'open_db.php'; $query = "SELECT user, os, asset_name, mac, ip FROM inventory"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<b>User</b> :{$row['user']} <br>" . "<b>O/S</b> : {$row['os']} <br>" . "<b>MAC</b> : {$row['mac']} <br>" . "<b>IP</b> : {$row['ip']} <br>" . "<b>Asset Name</b> : {$row['asset_name']} <br><br>"; } ?> So all i want to be able to do is click an edit link on that page which then takes the info i have loaded and puts it into a form. should be pretty easy hehe. Thanks in advance Quote Link to comment Share on other sites More sharing options...
LooieENG Posted May 23, 2008 Share Posted May 23, 2008 Something like this? I list the blog posts, with a hyperlink for admin.php?do=edit&id=id (use GET) then I get the blog content from the table with that id, and set a variable. Then, in the html bit, if the variable is set, it echos a textarea with the blog content in it, and when the content is edited, the data is submitted with POST and changed Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted May 23, 2008 Share Posted May 23, 2008 The edit link needs to look something like this: www.your-site.com/script_name.php?editID=UNIQUE_ID Then, at the top of your script, your code should look something like this <?php //check if they want to edit something if (isset($_GET['editID'])){ $editID = $_GET['editID']; //select the information from the database that they want to edit $query = mysql_query("SELECT user, os, asset_name, mac, ip FROM inventory WHERE unique_field='$editID'"); $row = mysql_fetch_assoc($query); //put the information in text boxes echo "User: <input type='text' name='user' value='{$row['user']}'>"; } ?> Wherever it says UNIQUE_ID is where you want to use the field from the database table thats unique, that way you know which information to select. Quote Link to comment Share on other sites More sharing options...
ragrim Posted May 23, 2008 Author Share Posted May 23, 2008 Thank you, this is the part i needed, i just couldnt get the right syntax for this piece of code, now that works i should be able to get the rest of it, ill see how i go. //put the information in text boxes echo "User: <input type='text' name='user' value='{$row['user']}'>"; PS: why does the insert code and quote not work for me? :S Quote Link to comment Share on other sites More sharing options...
ragrim Posted May 23, 2008 Author Share Posted May 23, 2008 ok i hit a wall allready lol. i know how to pass a variable from one page to another, but how do i send the variable of the current record thats open? say i use the "user" as my unique identifier, how can i add a link to send that "user" variable?\ if im making any sense lol Quote Link to comment Share on other sites More sharing options...
ragrim Posted May 23, 2008 Author Share Posted May 23, 2008 this may help, { echo "<b>User</b> :{$row['user']} <br>" . "<b>O/S</b> : {$row['os']} <br>" . "<b>MAC</b> : {$row['mac']} <br>" . "<b>IP</b> : {$row['ip']} <br>" . "<b>Asset Name</b> : {$row['asset_name']} <br><br>"; echo "<a href="edit_info.php?{$row['user']}"> EDIT!"; } ?> as you can see im trying to send the value of user to the next page. but i cant seem to get it right. Quote Link to comment Share on other sites More sharing options...
LooieENG Posted May 23, 2008 Share Posted May 23, 2008 echo "<a href=\"edit_info.php?user={$row['user']}\">EDIT!</a>"; And then on the next page $user = $_GET['user']; Quote Link to comment Share on other sites More sharing options...
ragrim Posted May 23, 2008 Author Share Posted May 23, 2008 thank you very much, i got it working! now i just gotta learn how to format it all haha! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.