Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP table with loop and passing form data to next page
    primarykey
    data
    text
    <p>I am working on a web based contact list for a friend. I have the html portion all done and working on the PHP scripts and such. I have the main page as a table in a while loop enclosed in form tags. I need two things to happen but not sure how to get this accomplished. </p> <p>First, each row has to have two submit buttons, which one goes to edit and the other to details, and carries over the values in the global $_POST. </p> <p>Second, the list will be about 300 rows, so i am using a while loop to create the table. </p> <p>I have the form working and passing the data but it is always passing the last row of the table. Here is my main page with the table:</p> <pre><code>&lt;?php if (!isset ($_SESSION['username'])) { session_start(); } ?&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Client Contact List&lt;/title&gt; &lt;/head&gt; &lt;?php $user1 = implode(',',$_SESSION); //DB information require_once('/includes/db.php'); //Declaring edit and details $edit = "&lt;INPUT type='image' src='/addressbook/images/edit.png' onclick='\addressbook\edit.php'&gt;"; $details = "&lt;INPUT type='image' src='/addressbook/images/contact.gif' name='details' onclick='f1.action='\addressbook\contact_details.php'&gt;"; //Table declarations and such mysql_connect("$host", "$username", "$password") or die(mysql_error()); mysql_select_db("$db_name")or die("cannot select DB"); $result = mysql_query("SELECT * FROM contacts") or die(mysql_error()); $num=mysql_numrows($result); $user1 = implode(',',$_SESSION); $userresults = "SELECT first FROM i_user where userid IN $user1"; $user = mysql_query($userresults); // print_r ($_SESSION); // print_r ($_POST); ?&gt; &lt;body style="background-image: url('Images/background_login.jpg');"&gt; &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt; &lt;table&gt; &lt;br&gt;&lt;br&gt; &lt;tr&gt;&lt;td width="500"&gt;Welcome Back, &lt;?php echo $user; ?&gt;&lt;/td&gt;&lt;td width="500"&gt;&lt;/td&gt;&lt;td width="300"&gt;&lt;form name="search" method="post" id="searchform" action="&lt;?php echo $_SERVER['PHP_SELF'];?&gt;"&gt;&lt;label for="searchtext"&gt;Search:&amp;nbsp; &lt;/label&gt;&lt;input type="text" name="name" /&gt; &lt;input type="submit" name="submit" value="Search" /&gt;&lt;/form&gt; &lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; &lt;br&gt; &lt;form name="f1" method="post" action="/addressbook/edit.php"&gt; &lt;table border="1"&gt; &lt;tr&gt; &lt;?php echo "&lt;table border='1'&gt;"; echo "&lt;tr&gt; &lt;th&gt;First&lt;/th&gt; &lt;th&gt;Last&lt;/th&gt; &lt;th&gt;Company&lt;/th&gt; &lt;th&gt;Primary Email&lt;/th&gt; &lt;th&gt;Secondary Email&lt;/th&gt; &lt;th&gt;Primary Phone&lt;/th&gt; &lt;th&gt;Second Phone&lt;/th&gt; &lt;th&gt;Action&lt;/th&gt; &lt;/tr&gt;"; $i=0; while ($i&lt;$num) { $id = mysql_result($result,$i,"id"); $first = mysql_result($result, $i, "first"); $last = mysql_result($result,$i, "last"); $company = mysql_result($result, $i, "company"); $email1 = mysql_result($result,$i, "email1"); $email2 = mysql_result($result,$i, "email2"); $phone = mysql_result($result,$i, "phone"); $mobile = mysql_result($result,$i, "mobile"); // Print out the contents of each row into a table echo "&lt;tr&gt;&lt;td width = '100'&gt;&lt;center&gt;&lt;input type='hidden' value='$first' name='first'&gt;"; echo $first; echo "&lt;/center&gt;&lt;/td&gt;&lt;td width = '100'&gt;&lt;center&gt;&lt;input type='hidden' value='$last' name='last'&gt;"; echo $last; echo "&lt;/center&gt;&lt;/td&gt;&lt;td width = '100'&gt;&lt;center&gt;&lt;input type='hidden' value='$company' name='company'&gt;"; echo $company; echo "&lt;/center&gt;&lt;/td&gt;&lt;td width = '100'&gt;&lt;center&gt;&lt;input type='hidden' value='$email1' name='email1'&gt;"; echo $email1; echo "&lt;/center&gt;&lt;/td&gt;&lt;td width = '100'&gt;&lt;center&gt;&lt;input type='hidden' value='$email2' name='email2'&gt;"; echo $email2; echo "&lt;/center&gt;&lt;/td&gt;&lt;td width = '100'&gt;&lt;center&gt;&lt;input type='hidden' value='$phone' name='phone'&gt;"; echo $phone; echo "&lt;/center&gt;&lt;/td&gt;&lt;td width = '100'&gt;&lt;center&gt;&lt;input type='hidden' value='$mobile name='mobile'&gt;"; echo $mobile; echo "&lt;/center&gt;&lt;/td&gt;&lt;td width = '100'&gt;&lt;center&gt;"; echo $edit; echo " &amp;nbsp&amp;nbsp "; echo $details; echo "&lt;/td&gt;&lt;/center&gt;&lt;/tr&gt;"; echo "&lt;input type='hidden' value='$id name='id'&gt;&lt;/td&gt;"; $i++; } ?&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>This get directed to either the details or edit page. Below is the edit page....</p> <pre><code>&lt;?php if (!isset ($_SESSION['username'])) { session_start(); } ?&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Edit Contact Information&lt;/title&gt; &lt;/head&gt; &lt;?php //DB information require_once('/includes/db.php'); mysql_connect("$host", "$username", "$password") or die(mysql_error()); mysql_select_db("$db_name")or die("cannot select DB"); $id = $_POST['id']; $first = $_POST['first']; $last = $_POST['last']; $company = $_POST['company']; $email1 = $_POST['email1']; $email2 = $_POST['email2']; $phone = $_POST['phone']; $mobile = $_POST['mobile']; //pulling the record id from the main login page. $first=$_POST['first']; $query="SELECT * FROM contacts where last=$last"; $result=mysql_query($query); print_r($_POST); ?&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;body style="background-image: url('Images/background_login.jpg');"&gt; &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt; &lt;!-- First Table with the back and search option but disabled for now --&gt; &lt;table&gt; &lt;br&gt; &lt;tr&gt; &lt;td width="500"&gt; &lt;input type='button' value='Back' onClick='history.go(-1)'&gt; &lt;/td&gt; &lt;td width="500"&gt;&lt;/td&gt; &lt;td width="300"&gt; &lt;!-- &lt;form name="search" method="post" id="searchform" action="&lt;?php echo $_SERVER['PHP_SELF'];?&gt;"&gt; &lt;label for="searchtext"&gt;Search:&amp;nbsp; &lt;/label&gt; &lt;input type="text" name="name" /&gt; &lt;input type="submit" name="submit" value="Search" /&gt; &lt;/form&gt; --&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;br&gt;&lt;br&gt; &lt;center&gt; &lt;!-- Second Table with form data pulled out for Identify --&gt; &lt;table&gt; &lt;tr&gt; &lt;th&gt; &lt;table&gt; &lt;tr&gt; &lt;td bgcolor="silver" colspan="4"&gt;&lt;center&gt;Identify&lt;/center&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="100"&gt;&lt;center&gt;&lt;b&gt;Title&lt;/b&gt;&lt;/center&gt;&lt;/td&gt; &lt;td width="100"&gt;&lt;/td&gt; &lt;td width="150"&gt;&lt;center&gt;&lt;b&gt;Company Name&lt;/b&gt;&lt;/center&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="100"&gt;&lt;input value="Title"&gt;&lt;/td&gt; &lt;td width="100"&gt;&lt;/td&gt; &lt;td width="100"&gt;&lt;? echo $company ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;&lt;td colspan="4"&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td width="100"&gt;&lt;center&gt;&lt;b&gt;First Name&lt;/b&gt;&lt;/center&gt;&lt;/td&gt; &lt;td width="100"&gt;&lt;/td&gt; &lt;td width="100"&gt;&lt;center&gt;&lt;b&gt;Last Name&lt;/b&gt;&lt;/center&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="100"&gt;&lt;input value="Test"&gt;&lt;/td&gt; &lt;td width="100"&gt;&lt;/td&gt; &lt;td width="100"&gt;&lt;input value="Test"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/th&gt; &lt;!-- Space between the contact info and Indenty --&gt; &lt;td width="100"&gt; &lt;/td&gt; &lt;th&gt; &lt;td&gt; &lt;!-- Third Table with form data pulled out --&gt; &lt;table&gt; &lt;tr&gt; &lt;td bgcolor="silver" colspan="4"&gt;&lt;center&gt;Contact Information&lt;/center&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="100"&gt;&lt;center&gt;&lt;b&gt;Office Phone&lt;/b&gt;&lt;/center&gt;&lt;/td&gt; &lt;td width="100"&gt;&lt;/td&gt; &lt;td width="150"&gt;&lt;center&gt;&lt;b&gt;Mobile Name&lt;/b&gt;&lt;/center&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="100"&gt;&lt;input value="Test"&gt;&lt;/td&gt; &lt;td width="100"&gt;&lt;/td&gt; &lt;td width="100"&gt;&lt;input value="Test"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="4"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="100"&gt;&lt;b&gt;Primary Email&lt;/b&gt;&lt;/td&gt; &lt;td width="100"&gt;&lt;/td&gt; &lt;td width="150"&gt;&lt;b&gt;Secondary Email&lt;/b&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="100"&gt;&lt;input value="Test"&gt;&lt;/td&gt; &lt;td width="100"&gt;&lt;/td&gt; &lt;td width="100"&gt;&lt;input value="Test"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/th&gt; &lt;tr height="100"&gt; &lt;td colspan="9"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;th class="style2"&gt; &lt;table&gt; &lt;tr width="400"&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td bgcolor="silver" colspan="4"&gt;&lt;center&gt;Applications Used&lt;/center&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="100"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="4"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="100"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="100"&gt;&lt;/td&gt; &lt;td width="100"&gt;&lt;/td&gt; &lt;td width="100"&gt;&lt;/td&gt; &lt;td width="100"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/th&gt; &lt;td width="200"&gt;&lt;/td&gt; &lt;td&gt; &lt;th class="style2"&gt; &lt;table&gt; &lt;tr&gt; &lt;td bgcolor="silver" colspan="4"&gt;&lt;center&gt;Internal Information&lt;/center&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="100"&gt;&lt;center&gt;&lt;b&gt;Account Mgr&lt;/b&gt;&lt;/center&gt;&lt;/td&gt; &lt;td width="100"&gt;&lt;/td&gt; &lt;td width="150"&gt;&lt;center&gt;&lt;b&gt;Client Relations&lt;/b&gt;&lt;/center&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="100"&gt;&lt;input value="Test"&gt;&lt;/td&gt; &lt;td width="100"&gt;&lt;/td&gt; &lt;td width="100"&gt;&lt;input value="Test"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;&lt;td colspan="4"&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td width="200"&gt;&lt;center&gt;&lt;b&gt;Acct Development&lt;/b&gt;&lt;/center&gt;&lt;/td&gt; &lt;td width="100"&gt;&lt;/td&gt; &lt;td width="100"&gt;&lt;center&gt;&lt;b&gt;Project Mgr&lt;/b&gt;&lt;/center&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="100"&gt;&lt;input value="Test"&gt;&lt;/td&gt; &lt;td width="100"&gt;&lt;/td&gt; &lt;td width="100"&gt;&lt;input value="Test"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/th&gt; &lt;/td&gt; &lt;/table&gt; &lt;/center&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Any thoughts on how to get this done?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload