georegjlee Posted March 6, 2007 Share Posted March 6, 2007 Hi, Im new to PHP and just want a bit of advice. I am displaying a table of information from a database and I have a check box at the end of each row. When you hit the submit button I want to be able place the checked rows into a new table in my data base and delete the rows that aren't checked. Heres the code that produces the first table. <html> <head> <title>First PHP Script</title> </head> <body> <?php //connection to the database $dbhandle = mysql_connect("localhost", "root", "") or die("Couldn't connect to SQL Server on $myServer"); //select a database to work with $selected = mysql_select_db("waterways", $dbhandle) or die("Couldn't open database myDB"); //declare the SQL statement that will query the database $query = "SELECT * FROM pending_problems"; //$query = $query . "WHERE problems.canal_Id = waterways.canal_Id"; //execute the SQL query and return records $result = mysql_query($query, $dbhandle); if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; } ?> <h3 style = "color: blue"> Problems Table</h3> <form id="form1" name="form1" method="post" action=""> <table border = "1" cellpadding = "3" cellspacing = "2"> <?php for ( $counter = 0; $row = mysql_fetch_row($result); $counter++) { print( "<tr>"); foreach ( $row as $key => $value ) print ( "<td>$value</td>" ); print ( "<td>Check box to verify</td>"); print ( "<td><p><input type=\"checkbox\" name=\"option1\" value=\"Milk\"></p></td>" ); print ( "</tr>" ); } //close the connection mysql_close($dbhandle); ?> </table> <input type="submit" value = "Update Problems" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/41480-datbase-and-php/ Share on other sites More sharing options...
.josh Posted March 6, 2007 Share Posted March 6, 2007 looks like you have a solid battle plan there. so...are you just letting us know your goals, or do you actually have a question about something? Quote Link to comment https://forums.phpfreaks.com/topic/41480-datbase-and-php/#findComment-200960 Share on other sites More sharing options...
nloding Posted March 6, 2007 Share Posted March 6, 2007 Are you asking how to do it? I would recommend looking into using the checkboxes as arrays when using POST ... basically, put "[]" after the name. I would also make sure that each problem has a unique ID with it in your table, that way you know what row you're deleting. Then the value of each checkbox becomes that ID. Then you'd use a WHERE SQL statement to choose only the rows affected by that value/ID ... Quote Link to comment https://forums.phpfreaks.com/topic/41480-datbase-and-php/#findComment-200964 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.