synchro_irl Posted February 24, 2008 Share Posted February 24, 2008 hey guys i have an admin section in my website, where i want the admin to view all the table entries of table 1 fr example, and edit the entries and click 'save' . i currently have code that will display the table entries, but u cant edit them: heres a pic of what it looks like right now: wat must i do to my code to allow the admin to update the table entries? heres my code for this: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- Design by Free CSS Templates http://www.freecsstemplates.org Released for free under a Creative Commons Attribution 2.5 License Name : Pluralism Description: A two-column, fixed-width template fit for 1024x768 screen resolutions. Version : 1.0 Released : 20071218 --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Search4Trade</title> <meta name="keywords" content="" /> <meta name="description" content="" /> <link href="style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper" style="width: 961px; height: 564px"> <div id="wrapper2"> <div id="header"> <div id="logo"> <h1>search4trade.net</h1> </div> <div id="menu"> <ul> <li><a href="Search1.html">Search </a></li> <li><a href="Login1.php">Login</a></li> <li><a href="#">Forum</a></li> <li><a href="registration.html">Register</a></li> <li><a href="#">About Us</a></li> <li><a href="#">Contact</a></li> </ul> </div> </div> <div id="page"> <div id="content" style="width: 766px; height: 205px"> <div class="post"> <h2 class="title"><a href="#">Welcome to Search4Trade</a></h2> <div class="entry"> <?php $con = mysql_connect("localhost","xxx","xxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydatabase", $con); $search1=$_POST["search1"]; $search2=$_POST["search2"]; $search2=$_POST["search3"]; $result = mysql_query("SELECT * FROM mytable WHERE location LIKE '%$search1%' AND type LIKE '%$search2%' AND name LIKE '%$search3%' "); echo "<table border='1'> <tr> <th>Type</th> <th>Location</th> <th>Availability</th> <th>StarRating</th> <th>name</th> <th>email</th> <th>username</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['type'] . "</td>"; echo "<td>" . $row['location'] . "</td>"; echo "<td>" . $row['availability'] . "</td>"; echo "<td>" . $row['StarRating'] . "</td>"; echo "<td>" . $row['name'] . "</td>"; echo "<td>" . $row['email'] . "</td>"; echo "<td>" . $row['username'] . "</td>"; echo "</tr>"; } mysql_close($con); ?></div> </div> </div> </div> </div> </div> </body> </html> EDITED BY WILDTEEN88: Removed database credentials Quote Link to comment Share on other sites More sharing options...
deansatch Posted February 24, 2008 Share Posted February 24, 2008 You can add a column to your table and add a link like <a href="edit.php?id=$id>Edit</a> Obviously, you need to fetch the id of each entry from your db. On the edit.php page, create a form, much like the one you use to add the entries in the first place but in each input field echo the value="" as your variables. You should be able to use the same php code you used in your display of results page, only without the while statment. Then have your form go to your update mysql script. Quote Link to comment Share on other sites More sharing options...
deansatch Posted February 24, 2008 Share Posted February 24, 2008 Oh! And please don't post your database login details. I suggest you edit your post. Quote Link to comment Share on other sites More sharing options...
rameshfaj Posted February 24, 2008 Share Posted February 24, 2008 You need to write query for updating into the database. When the user selects on some of the displayed entry,u can link to a form and display the corresponding entry,then allow the editing via some HTML forms. Quote Link to comment Share on other sites More sharing options...
synchro_irl Posted February 24, 2008 Author Share Posted February 24, 2008 hey guys, sorry for being stupid, but im still noot sure what to do! Quote Link to comment Share on other sites More sharing options...
synchro_irl Posted February 24, 2008 Author Share Posted February 24, 2008 You can add a column to your table and add a link like <a href="edit.php?id=$id>Edit</a> Obviously, you need to fetch the id of each entry from your db. On the edit.php page, create a form, much like the one you use to add the entries in the first place but in each input field echo the value="" as your variables. You should be able to use the same php code you used in your display of results page, only without the while statment. Then have your form go to your update mysql script. i understand what u mean, it will ponly disply the items in a read only table, i need it to be editable. thanks steve 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.