Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/41480-datbase-and-php/
Share on other sites

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 ...

Link to comment
https://forums.phpfreaks.com/topic/41480-datbase-and-php/#findComment-200964
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.