kemper Posted May 4, 2007 Share Posted May 4, 2007 I have never written an edit.php to edit a line within mysql table. What variables do I need to start with beside the database access and table fields? How do I code to access and edit a specific line (record) withing a table? Quote Link to comment https://forums.phpfreaks.com/topic/49933-starting-something-new-have-questions/ Share on other sites More sharing options...
john010117 Posted May 4, 2007 Share Posted May 4, 2007 Talk about timing! I'm coding the same thing right now. I don't think you'll need any more variables than that. Quote Link to comment https://forums.phpfreaks.com/topic/49933-starting-something-new-have-questions/#findComment-245054 Share on other sites More sharing options...
kemper Posted May 4, 2007 Author Share Posted May 4, 2007 Where do I eve start? Quote Link to comment https://forums.phpfreaks.com/topic/49933-starting-something-new-have-questions/#findComment-245059 Share on other sites More sharing options...
trq Posted May 4, 2007 Share Posted May 4, 2007 A simple example. Pass an id through the url. <?php // connect to db. if (isset($_GET['id'])) { $id = mysql_real_escape_string($_GET['id']); $sql = "DELETE FROM tbl WHERE fld = '$id'"; if ($result = mysql_query($sql)) { if (mysql_affected_rows($result)) { echo "Record id# $id deleted"; } else { echo "No record id# $id exists"; } } else { echo "Query failed<br />" . mysql_error(); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/49933-starting-something-new-have-questions/#findComment-245060 Share on other sites More sharing options...
john010117 Posted May 4, 2007 Share Posted May 4, 2007 ...but then, that's a major security hole. Anyone can edit it. Try changing that code with $_POST and sessions (if you want to make it more secure). Quote Link to comment https://forums.phpfreaks.com/topic/49933-starting-something-new-have-questions/#findComment-245061 Share on other sites More sharing options...
trq Posted May 4, 2007 Share Posted May 4, 2007 $_POST is no more secure then $_GET. Besides, I was simply displaying an example. One would assume any user would need permissions (be logged in) before they could delete any records. Once a login is in place its easy to prevent people deleting records that don't belong to them. Then it does not matter if the id is passed through the url at all. Quote Link to comment https://forums.phpfreaks.com/topic/49933-starting-something-new-have-questions/#findComment-245063 Share on other sites More sharing options...
john010117 Posted May 4, 2007 Share Posted May 4, 2007 Oh, I've always thought POST was more secure than GET... then I'm wrong. Sorry about that. Quote Link to comment https://forums.phpfreaks.com/topic/49933-starting-something-new-have-questions/#findComment-245064 Share on other sites More sharing options...
kemper Posted May 4, 2007 Author Share Posted May 4, 2007 But, how do I select the fields that are editable? I have done forms in html, but not php. This seems very different. Quote Link to comment https://forums.phpfreaks.com/topic/49933-starting-something-new-have-questions/#findComment-245068 Share on other sites More sharing options...
trq Posted May 4, 2007 Share Posted May 4, 2007 Sorry, I misread your post a little. But, how do I select the fields that are editable? What exactly do you mean? To make an edit page you'll firstly need to run a SELECT statement based on the id of the record you wish to edit (Usually passed through the url). Then, you'll neeed to display this data in a form so that it can be edited. Once edited the form posts to a page much like the script I just posted but instead of a DELETE statement you'd run an UPDATE. I have done forms in html, but not php PHP can not make forms. Forms ARE html. Quote Link to comment https://forums.phpfreaks.com/topic/49933-starting-something-new-have-questions/#findComment-245072 Share on other sites More sharing options...
kemper Posted May 4, 2007 Author Share Posted May 4, 2007 Here is what I am doing... I run a youth sports league. I will have my basic schedule in a table with the following fields: Date, Time, Home Team, Visiting Team, Field I will be creating the table with content to complete all fields but "Time". I have another administrator that will be enterring that field into each line of the table. Time will be the only editable field. Does not need to be specified? I am assuming that you mean by PHP can not make forms. Forms ARE html. that the edit.php will allow editting of the empty fields. Or, am I still very confused about the process? Quote Link to comment https://forums.phpfreaks.com/topic/49933-starting-something-new-have-questions/#findComment-245078 Share on other sites More sharing options...
trq Posted May 4, 2007 Share Posted May 4, 2007 The process is still exactly as I have said above. You only list in the editable form the values you wish to be able to edit. Obviously though, you'll need to at least show some other information or your administrator wont be able to identify what record he is editing. Quote Link to comment https://forums.phpfreaks.com/topic/49933-starting-something-new-have-questions/#findComment-245081 Share on other sites More sharing options...
kemper Posted May 4, 2007 Author Share Posted May 4, 2007 OK... My current schedule is displayed as: <?php require_once "maincore.php"; require_once "subheader.php"; if (isset($readmore) && !isNum($readmore)) fallback(FUSION_SELF); opentable("Spring 2007 Scores & Schedules for $division"); // mySQL Table $db_con = mysql_connect(***, ***, ***) or die("Connetion to database failed!"); mysql_select_db(***); $division = $_GET['division']; $sql = "SELECT * FROM `s2007schedules` WHERE division='$division' ORDER BY game_no ASC"; $result = mysql_query($sql) or die(mysql_error()); $i = 0; echo "</p> <table width='100%' border='1' cellspacing='0' cellpadding='0' bordercolor='#3c64a0'>"; while ($row = mysql_fetch_array($result)) { echo "<tr> <td valign='top' width='100%'> <table border='1' width='100%' id='table1' cellspacing='0' cellpadding='0' bordercolor='#2B538E'> <tr> <td style='border-left-style: solid; border-left-width: 1px; border-right-style: solid; border-right-width: 1px; border-top-style: solid; border-top-width: 1px; border-bottom-style: none; border-bottom-width: medium'> <table border='0' width='100%' id='table2' cellspacing='0' cellpadding='2'> <tr> <td width='50%'> <font color='#FF0000' face='Arial' size='1'><b>Date: </b> </font> <font face='Arial' size='1'>" . $row['date'] . "</font></td> <td width='20%'><b><font face='Arial' size='1' color='#ff0000'>Game ID: </font> </b><font face='Arial' size='1'>" . $row['gameid'] . "</font></td> <td width='30%'><b><font face='Arial' size='1' color='#ff0000'>Status: </font> </b><font face='Arial' size='1'>" . $row['status'] . "</font></td> </tr> </table> </td> </tr> <tr> <td style='border-left-style: solid; border-left-width: 1px; border-right-style: solid; border-right-width: 1px; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px'> <table border='0' width='100%' id='table3' cellspacing='0' cellpadding='2'> <tr> <td width='15%'><font face='Arial' size='1' color='#ff0000'><b>Time: </font></b> <font face='Arial' size='1'>" . $row['time'] . "</font></td> <td width='30%'><b><font face='Arial' size='1' color='#ff0000'>Visitors: </font></b> <font face='Arial' size='1'>" . $row['visitor'] . "</font></td> <td width='30%'><b><font face='Arial' size='1' color='#000000'><b>@ </b></font><font face='Arial' size='1' color='#ff0000'>Home: </font></b> <font face='Arial' size='1'>" . $row['home'] . "</font></td> <td width='25%'><b><font face='Arial' size='1' color='#ff0000'>Field: </font></b><a target='_blank' href=" . $row['field_link'] . "><font face='Arial' size='1' color='#3c64a0'><b><u>" . $row['field'] . " " . $row['field_no'] . "</u></b></font></a></td> </tr> </table> </td> </tr> </table> </td> </tr>"; } echo "</table>\n"; // mySQL ends closetable(); ?> Could I link the edit.php to this display? How does the edit.php correspond to the individual id? obviously, there is additional information displaying here that my original variables, but I have id field and gameid field for other scheduling purposes. Thank you for all of your assistance. Quote Link to comment https://forums.phpfreaks.com/topic/49933-starting-something-new-have-questions/#findComment-245088 Share on other sites More sharing options...
trq Posted May 4, 2007 Share Posted May 4, 2007 Look, I'm not going to write the code (if only you knew how much typing Ive done today). Ive explained the complete process. You already have an example of how to display your data from the database, and I have given you an example of how to run a delete and or edit query. One thing about programming. You need to learn how to think a problem through in small steps. Each of which I have already pointed out to you. Quote Link to comment https://forums.phpfreaks.com/topic/49933-starting-something-new-have-questions/#findComment-245096 Share on other sites More sharing options...
clown[NOR] Posted May 4, 2007 Share Posted May 4, 2007 you dont even have to link the file if you want.. you can add everything in one file using the IF statement to tell it what to do... Quote Link to comment https://forums.phpfreaks.com/topic/49933-starting-something-new-have-questions/#findComment-245098 Share on other sites More sharing options...
kemper Posted May 4, 2007 Author Share Posted May 4, 2007 Thanks for all of your input. I will not fustrate anyone anymore. I will try and read this more and understand. Thank you all again. Quote Link to comment https://forums.phpfreaks.com/topic/49933-starting-something-new-have-questions/#findComment-245102 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.