Jump to content

Recommended Posts

Im trying to assign the checkbox the row id number but dont know how to go about it. Each row contains problem_id, problem_severity, user_name, password, waterway_id. I am passing the checkbox as an array but how do I assign the problem_id to the checked checkbox. The idea is to place the selected rows in a new table and delete the rest. Any ideas?

<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=\"?????\"></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/43658-checkboxs-as-arrays/
Share on other sites

<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=\"".$id."\"></p></td>" );
print ( "</tr>" );

}
//close the connection
mysql_close($dbhandle);
?>
</table>
<input type="submit" name="submit" value = "Update Problems" />
</form>
</body>
</html>

 

added $id to the value. Once that is done here is the second part.

 

<?php
// should be added after
////select a database to work with
//$selected = mysql_select_db("waterways", $dbhandle)
// or die("Couldn't open database myDB");

if (isset($_POST['submit'])) {
      foreach ($_POST['option'] as $id) {
                print $id . " should be deleted here.<br />";
      }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/43658-checkboxs-as-arrays/#findComment-211998
Share on other sites

When you put a period in the string it "breaks it up" and allows for processing. IE:

 

<?php
$test2 = "myTest";
$test = "This is a test $test2 "; // prints this is a test myTest

$test = "This is a test ".$test2."!"; // prints this is a test myTest!

// It really just makes sure that the variable will display right.

$test = 'This is a test '.$test2.'!'; // prints this is a test myTest!

// But with single quotes it is necessary because single quotes take the variables literally.

?>

 

I just use them to make sure my variables are displayed correctly.

Link to comment
https://forums.phpfreaks.com/topic/43658-checkboxs-as-arrays/#findComment-212014
Share on other sites

I think i follow it but the what dose the code below do exatly.

if (isset($_POST['submit'])) { // Dose this check if the submit button was pressed?
      foreach ($_POST['option'] as $id) { // Should this be the checkbox array?
                print $id . " should be deleted here.<br />"; // this is where I write my SQL delete?
      }
}

Link to comment
https://forums.phpfreaks.com/topic/43658-checkboxs-as-arrays/#findComment-212038
Share on other sites

<?php
if (isset($_POST['submit'])) { // Make sure the form was submitted
      if (is_array($_POST['option1'])) { // Make sure the checkbox is an array.
          foreach ($_POST['option1'] as $id) { // This loops through the checkbox array
                print $id . " should be deleted here.<br />"; // Write processing code here.
          }
      }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/43658-checkboxs-as-arrays/#findComment-212049
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.