Lee-Bartlett Posted October 5, 2008 Share Posted October 5, 2008 Ok i recently done a drop down box which grabs the user, you click go then presto you can update it. Now, i have a page where you see all my db, a delete button + a update button. The update button tho then linked to my old drop down box one, which is very efficent, cause the data is already in the row. So im kind of stuck on what to do, i looked at my old script and its basically all in form2. Here is my current scripts. I need advice or help how to link the last 2 scripts, with out the first. MY OLD DROP DOWN BOX FORM <?php require_once("includes/db_connection.php"); $sql = "SELECT * from tblbasicform"; $res = mysql_query($sql) or die(mysql_error()); echo "<form action=\"form2.php\" method=\"post\">"; echo "<select name=\"name\">"; while($row = mysql_fetch_array($res)){ echo "<option>". $row['name']; echo "</option>"; $name = $row['name']; $email = $row['email']; $location = $row['location']; $buissnes_name = $row['buissnes_name']; $type = $row['type']; $id = $row['id']; } echo "</select><br>"; echo "<input type=submit value=\"Update Record\">"; echo "</form>"; ?> THE PAGE WHERE THE DATABASE IS ECHOED, WITH THE DELETE/UPDATE BIT <?php require_once("includes/db_connection.php"); ?> <?php if(isset($_POST['id'])) { $id = $_POST['id']; $delete = mysql_query("DELETE FROM tblbasicform WHERE id='$id'"); } $sql = "SELECT * from tblbasicform"; $res = mysql_query($sql) or die(mysql_error()); echo "<table border=1 align=centre>"; echo "<tr><td>id</td> <td>Name</td><td>Email</td><td>Buissnes Name</td><td>Location</td><td>Free or Paid</td><td>Delete</td><td>Update</td></tr>"; while($row = MYSQL_FETCH_ARRAY($res)) { echo "<tr><td>".$row['id']."</td>"; echo "<td>".$row['name']."</td>"; echo "<td>".$row['email']."</td>"; echo "<td>".$row['buissnes_name']."</td>"; echo "<td>".$row['location']."</td>"; echo "<td>".$row['type']."</td>"; echo '<td><form action="'.basename($_SERVER['PHP_SELF']).'" method="POST"> <input type="hidden" name="id" value="'.$row['id'].'"><input type="submit" name="button=" id="button" value="Delete Record"></form></td>'; echo "<td>( <a href=form2.php>Update</a> ) </td></tr>"; } echo "</table><br>"; ?> <a href="userform.php">Add a new user.</a> AND FORM 2, THE BIT WHERE THE UPDATE HAPPENDS <?php require_once("includes/db_connection.php"); $name = $_POST['name']; echo "<form action=\"form3.php\" method=\"post\">"; $sql = "SELECT * from tblbasicform WHERE name = '$name'"; $res = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_array($res)){ $id = $row['id']; $name = $row['name']; $email = $row['email']; $buissnes_name = $row['buissnes_name']; $location = $row['location']; $type = $row['type']; ?> Input Name: <input type="text" name="name" value="<? echo $name ?>" /><br /> Input Email: <input type="text" name="email" value="<? echo $email?>" /><br /> Input Buissnes Name: <input type="text" name="buissnes_name" value="<? echo $buissnes_name?>" /><br /> Input Location: <input type="text" name="location" value="<? echo $location?>" /><br /> Input Free or Paid: <input type="text" name="type" value="<? echo $type?>" /><br /> <input type="hidden" name="id" value="<? echo $id?>"> <input type="submit" name="submit" value="Update Data" /> </form> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/127165-getting-information-from-db/ Share on other sites More sharing options...
Bendude14 Posted October 6, 2008 Share Posted October 6, 2008 What exactly are you trying to do? can you explain further... Link to comment https://forums.phpfreaks.com/topic/127165-getting-information-from-db/#findComment-657890 Share on other sites More sharing options...
Lee-Bartlett Posted October 6, 2008 Author Share Posted October 6, 2008 ok my page has an update button, i want to use that button to update my page, instead of using my drop down box. Instead of using the top piece of code, i wanna get rid of that bit and combine the bottom 2 to work, atm it just loads a blank page. Is that bit more cleaerer? imagine an admin looking at his database, end 2 collums are delete and update, the update takes him to the page where he can update his data then takes him back to the database page. Link to comment https://forums.phpfreaks.com/topic/127165-getting-information-from-db/#findComment-658077 Share on other sites More sharing options...
Bendude14 Posted October 7, 2008 Share Posted October 7, 2008 well all you need is a link to the update page and append the row Id to the end of the url. Then on the update page you can echo the info retrieved from the DB into a text box. You will have a submit button on this page also which you can check if(isset( and then update the database with the new info from the text box. Have a go yourself and come back with what you get Link to comment https://forums.phpfreaks.com/topic/127165-getting-information-from-db/#findComment-658633 Share on other sites More sharing options...
Lee-Bartlett Posted October 7, 2008 Author Share Posted October 7, 2008 I tried putting it in a new form, becuase i wasnt sure if i should just keep it in same one or not. This is what i tried, im fairly new to php. <?php require_once("includes/db_connection.php"); ?> <?php $name = $_POST['name']; $email = $_POST['email']; $location = $_POST['location']; $type = $_POST['type']; $buissnes_name = $_POST['buissnes_name']; $id = $_POST['id']; ?> <?php if(isset($_POST['id'])) { $id = $_POST['id']; $delete = mysql_query("DELETE FROM tblbasicform WHERE id='$id'"); } $sql = "SELECT * from tblbasicform"; $res = mysql_query($sql) or die(mysql_error()); echo "<table border=1 align=centre>"; echo "<tr><td>id</td> <td>Name</td><td>Email</td><td>Buissnes Name</td><td>Location</td><td>Free or Paid</td><td>Delete</td><td>Update</td></tr>"; while($row = MYSQL_FETCH_ARRAY($res)) { echo "<tr><td>".$row['id']."</td>"; echo "<td>".$row['name']."</td>"; echo "<td>".$row['email']."</td>"; echo "<td>".$row['buissnes_name']."</td>"; echo "<td>".$row['location']."</td>"; echo "<td>".$row['type']."</td>"; echo '<td><form action="'.basename($_SERVER['PHP_SELF']).'" method="POST"> <input type="hidden" name="id" value="'.$row['id'].'"><input type="submit" name="button=" id="button" value="Delete Record"></form></td>'; $sql = "SELECT * from tblbasicform"; $res = mysql_query($sql) or die(mysql_error()); echo "<form action=\"form2.php\" method=\"post\"> <input type=\"hidden\" name=\"name=name\" value=\"'.$row['name'].'\">"; echo "<br>"; echo "<input type=submit value=\"Update Record\">"; echo "</form>"; echo "</tr>"; } echo "</table><br>"; ?> <a href="userform.php">Add a new user.</a> Link to comment https://forums.phpfreaks.com/topic/127165-getting-information-from-db/#findComment-658899 Share on other sites More sharing options...
Bendude14 Posted October 7, 2008 Share Posted October 7, 2008 i can't really see where your going with that you wrote... From what i interpreted from what you said you wanted this code should get you going... <?php error_reporting(E_ALL); require_once("includes/db_connection.php"); if(isset($_POST['update'])) { $name = $_POST['name']; $email = $_POST['email']; $location = $_POST['location']; $business_name = $_POST['business_name']; $type = $_POST['type']; $id = $_POST['id']; $sql = "Update Query Here"; mysql_query($sql) or trigger_error("query failed" . mysql_error()); echo "DB Updated"; } $sql = "SELECT * from tblbasicform"; $res = mysql_query($sql) or die(mysql_error()); echo "<form action=\"form2.php\" method=\"post\">"; echo "<select name=\"name\">"; while($row = mysql_fetch_array($res)){ echo '<input type="text" name="name" value="'.$row['name'].'" /><br />'; '<input type="text" name="email" value="'.$row['email'].'" /><br />'; '<input type="text" name="location" value="'.$row['location'].'" /><br />'; '<input type="text" name="business_name" value="'.$row['business_name'].'" /><br />'; '<input type="text" name="type" value="'.$row['type'].'" /><br />'; '<input type="text" name="id" value="'.$row['id'].'" /><br />'; } echo "<input type=submit value=\"Update Record\" name=\"update\">"; echo "</form>"; ?> I adapted it from the first section of code that you posted but instead of the drop town your now using text boxes. You will still need to add validation and escape date etc before updating your DB If this is not what your after please post again.. Link to comment https://forums.phpfreaks.com/topic/127165-getting-information-from-db/#findComment-658925 Share on other sites More sharing options...
Lee-Bartlett Posted October 7, 2008 Author Share Posted October 7, 2008 Thats not quite what i need, i need the update button in updatedelete.php to give the information to my update page. my current update page is this. <?php require_once("includes/db_connection.php"); $name = $_POST['name']; echo "<form action=\"form3.php\" method=\"post\">"; $sql = "SELECT * from tblbasicform WHERE name = '$name'"; $res = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_array($res)){ $id = $row['id']; $name = $row['name']; $email = $row['email']; $buissnes_name = $row['buissnes_name']; $location = $row['location']; $type = $row['type']; ?> Input Name: <input type="text" name="name" value="<? echo $name ?>" /><br /> Input Email: <input type="text" name="email" value="<? echo $email?>" /><br /> Input Buissnes Name: <input type="text" name="buissnes_name" value="<? echo $buissnes_name?>" /><br /> Input Location: <input type="text" name="location" value="<? echo $location?>" /><br /> Input Free or Paid: <input type="text" name="type" value="<? echo $type?>" /><br /> <input type="hidden" name="id" value="<? echo $id?>"> <input type="submit" name="submit" value="Update Data" /> </form> <?php } ?> But i need to send the db data from this page, using the update button <?php require_once("includes/db_connection.php"); ?> <?php $name = $_POST['name']; $email = $_POST['email']; $location = $_POST['location']; $type = $_POST['type']; $buissnes_name = $_POST['buissnes_name']; $id = $_POST['id']; ?> <?php if(isset($_POST['id'])) { $id = $_POST['id']; $delete = mysql_query("DELETE FROM tblbasicform WHERE id='$id'"); } $sql = "SELECT * from tblbasicform"; $res = mysql_query($sql) or die(mysql_error()); echo "<table border=1 align=centre>"; echo "<tr><td>id</td> <td>Name</td><td>Email</td><td>Buissnes Name</td><td>Location</td><td>Free or Paid</td><td>Delete</td><td>Update</td></tr>"; while($row = MYSQL_FETCH_ARRAY($res)) { echo "<tr><td>".$row['id']."</td>"; echo "<td>".$row['name']."</td>"; echo "<td>".$row['email']."</td>"; echo "<td>".$row['buissnes_name']."</td>"; echo "<td>".$row['location']."</td>"; echo "<td>".$row['type']."</td>"; echo '<td><form action="'.basename($_SERVER['PHP_SELF']).'" method="POST"> <input type="hidden" name="id" value="'.$row['id'].'"><input type="submit" name="button=" id="button" value="Delete Record"></form></td>'; $sql = "SELECT * from tblbasicform"; $res = mysql_query($sql) or die(mysql_error()); echo "<form action=\"form2.php\" method=\"post\"> <input type=\"hidden\" name=\"name=name\" value=\"'.$row['name'].'\">"; echo "<br>"; echo "<input type=submit value=\"Update Record\">"; echo "</form>"; echo "</tr>"; } echo "</table><br>"; ?> <a href="userform.php">Add a new user.</a> Link to comment https://forums.phpfreaks.com/topic/127165-getting-information-from-db/#findComment-659046 Share on other sites More sharing options...
Lee-Bartlett Posted October 7, 2008 Author Share Posted October 7, 2008 Im at a loss i tried this to see if i could get my update button to work <?php require_once("includes/db_connection.php"); ?> <?php $name = $_POST['name']; $email = $_POST['email']; $location = $_POST['location']; $type = $_POST['type']; $buissnes_name = $_POST['buissnes_name']; $id = $_POST['id']; ?> <?php if(isset($_POST['id'])) { $id = $_POST['id']; $delete = mysql_query("DELETE FROM tblbasicform WHERE id='$id'"); } $sql = "SELECT * from tblbasicform"; $res = mysql_query($sql) or die(mysql_error()); echo "<table border=1 align=centre>"; echo "<tr><td>id</td> <td>Name</td><td>Email</td><td>Buissnes Name</td><td>Location</td><td>Free or Paid</td><td>Delete</td><td>Update</td></tr>"; while($row = MYSQL_FETCH_ARRAY($res)) { echo "<tr><td>".$row['id']."</td>"; echo "<td>".$row['name']."</td>"; echo "<td>".$row['email']."</td>"; echo "<td>".$row['buissnes_name']."</td>"; echo "<td>".$row['location']."</td>"; echo "<td>".$row['type']."</td>"; echo '<td><form action="'.basename($_SERVER['PHP_SELF']).'" method="POST"> <input type="hidden" name="id" value="'.$row['id'].'"><input type="submit" name="button=" id="button" value="Delete Record"></form></td>'; $sql = "SELECT * from tblbasicform"; $res = mysql_query($sql) or die(mysql_error()); echo "<td><form action="form2.php" method="POST">"; while($row = mysql_fetch_array($res)){ echo "<input type="hidden" name="name" value="$row['name']">" echo "<input type="submit" name="button=" id="button" value="oelete Record"></form></td>"; } echo "</tr>"; } echo "</table><br>"; ?> <a href="userform.php">Add a new user.</a> Link to comment https://forums.phpfreaks.com/topic/127165-getting-information-from-db/#findComment-659231 Share on other sites More sharing options...
Lee-Bartlett Posted October 7, 2008 Author Share Posted October 7, 2008 Any one with a tut? or can see where im going wrong, please Link to comment https://forums.phpfreaks.com/topic/127165-getting-information-from-db/#findComment-659486 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.