I am working with my last unit assignment, I have already found the way to include the checkboxes into each row of my table. I found the way to display the records selected in the table to be modified. However it works only if they are selected from the beginning including the first record in order without leaving any records in between.
For example if I chose from the second one and above I received this error:
Notice: Undefined offset: 0 in C:\wamp\www\ShowSelected.php on line 48
Does anyone know why? What would be the best way to do this?
I don't want to give up myself with this one so here is what I have until now:
This is the php that presents the data with the checkboxes:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="php_styles.css" type="text/css" />
<title>Modifications</title>
</head>
<body>
<?php
include("admin.php");
?>
<h2 align="center">Making Selection</h2>
<?php
//Varible declared to establish a connection
$connection = mysql_connect("localhost", "user1", "ryciorycio");
//Veryfing if connection is established
if (!$connection)
{
die('Could not connect: ' . mysql_error());
exit;
}
else
//Connecting to database and table
mysql_select_db("garcia", $connection);
//Declaring a variable to hold the requested values
$result = mysql_query("SELECT *
FROM `contacts`
ORDER BY LastName ASC
LIMIT 0 , 30");
$i = 0;
echo "<form action='ShowSelected.php' method='post' enctype='application/x-www-form-urlencoded'>";
//Presenting the values in a table
echo "<table align='center' border='1' width='40%'>";
echo "<tr><th>Modify</th><th>Name</th><th>Phone Number</th></tr>";
while($row = mysql_fetch_array($result))
{
$FixNumber = implode('-',str_split(substr($row['PhoneNumber'] , 0,-4),3)).'-'.substr($row['PhoneNumber'],-4);
echo "<tr><td><input type='checkbox' name='selected[$i]' value='{$row['PhoneNumber']}'/><br /></td><td>{$row['LastName']}, {$row['FirstName']}</td><td>({$row['AreaCode']}) $FixNumber</td></tr>";
++$i;
}
echo "</table><br />";
//Closing connection
echo "<p><input type='submit' value='Modify' tabindex='3'/>
</form></p>";
mysql_close($connection);
?>
<hr/>
<p>To modify any contact select it from the list and click <strong>"Modify"</strong> button.</p><hr width="35%"/>
</body>
</html>
and this is the php to show the selected values:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="php_styles.css" type="text/css" />
<title>Untitled Document</title>
</head>
<body>
<?php
include("admin.php");
?>
<h2 align="center">Making Changes</h2>
<?php
//Varible declared to establish a connection
$connection = mysql_connect("localhost", "user1", "ryciorycio");
//Veryfing if connection is established
if (!$connection)
{
die('Could not connect: ' . mysql_error());
exit;
}
else
//Connecting to database and table
mysql_select_db("garcia", $connection);
//Declaring a variable to hold the requested values
if (isset($_POST['selected']))
{
$size = count($_POST['selected']);
$i = 0;
echo "<table align='center' border='1' width='40%'>";
// Defining columns
echo "<tr><th>First Name</th><th>Last Name</th><th>Street</th><th>City</th><th>State</th><th>Zip Code</th><th>Area Code</th><th>Phone Number</th></tr>";
while ($i < $size)
{
// Variable to hold the Phone Number value of each selected record.
$Modify = $_POST['selected'][$i];
++$i;
// Declaring a variable to hold the requested values
$result = mysql_query("SELECT *
FROM `contacts`
WHERE PhoneNumber = '$Modify'
ORDER BY LastName ASC
LIMIT 0 , 30");
// While database keeps returning values
while($row = mysql_fetch_array($result))
{
// Each row will present all the fields in the table.
echo "<tr><td><input type='text' name='first_name[]' size='12' value='{$row['FirstName']}'/></td><td><input type='text' name='last_name[]' size='12' value='{$row['LastName']}'/></td><td><input type='text' name='street[]' size='34' value='{$row['Street']}'/></td><td><input type='text' name='city[]' size='15' value='{$row['City']}'/></td><td><input type='text' name='state[]' size='15' value='{$row['State']}'/></td><td><input type='text' name='zip_code[]' size='8' value='{$row['ZipCode']}'/></td><td><input type='text' name='area_code[]' size='4' value='{$row['AreaCode']}'/></td><td><input type='text' name='phone_number[]' size='15' value='{$row['PhoneNumber']}'/></td></tr>";
}
}
}
else
{
echo"<hr /><div>There were no contact chosen, please choose at least one and try again!</div>";
}
echo "</table><br />";
mysql_close($connection);
?>
</body>
</html>
I am getting bald with this because this is almost the eigth time I start this php using multiple ways. So any recommendation will be appreciated, thanks.
This post has been edited by RGarcia: 10 July 2010 - 11:48 AM

New Topic/Question
Reply




MultiQuote




|