I could not figure out how to pass data to next page. Here is my code. I hope someone who can help me with it. I am trying tp pass id=$_get. Can someone look at the code and tell me what I do wrong. I am kind of new on this.

member.php
<HTML>
<HEAD>
<TITLE> Member List </TITLE>

</HEAD>
<BODY>
<FORM>

<?php
include ('dbc.php');
if ($db) {
//$SQL = "SELECT * FROM member";

$result = mysql_query("SELECT * FROM member");

echo "<table border='1'>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Maiden Name</th>
<th>Last Name</th>
<th>Month (start)</th>
<th>Year (start)</th>
<th>Month (end)</th>
<th>Year (end)</th>
<th>Edit/Update</th>
</tr>

";

while($row = mysql_fetch_array($result))
{

echo "<tr>";
echo "<td>" . $row . "&nbsp;</td>";
echo "<td>" . $row . "&nbsp;</td>";
echo "<td>" . $row . "&nbsp;</td>";
echo "<td>" . $row . "&nbsp;</td>";
echo "<td>" . $row . "&nbsp;</td>";
echo "<td>" . $row . "&nbsp;</td>";
echo "<td>" . $row . "&nbsp;</td>";
echo "<td>" . $row . "&nbsp;</td>";

echo "<td>" . "<a href=\"edit_update.php?id=\" " . $row . ">Edit/Update</a>" . "</td>";

}

echo "</tr>";

echo "</table>";
}
else {
echo "Database NOT Found ";
}

mysql_close($link) ;
?>
</FORM>
</BODY>
</HTML>

edit_update.php

<?php
include ('dbc.php');

$id=$_GET;

// Retrieve data from database
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);
?>

<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<form name="form1" method="post" action="update_ac.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>&nbsp;</td>
<td colspan="3"><strong>Update data in mysql</strong> </td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center"><strong>First Name</strong></td>
<td align="center"><strong>Maiden Name</strong></td>
<td align="center"><strong>Last Name</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="center"><input name="first_name" type="text" id="first_name" value="<? echo $rows; ?>"></td>
<td align="center"><input name="Maiden_name" type="text" id="Maiden_name" value="<? echo $rows; ?>" size="15"></td>
<td><input name="last_name" type="text" id="last_name" value="<? echo $rows; ?>" size="15"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="id" type="hidden" id="id" value="<? echo $rows; ?>"></td>
<td align="center"><input type="submit" name="Submit" value="Submit"></td>
<td>&nbsp;</td>
</tr>
</table>
</td>
</form>
</tr>
</table>

<?

// close connection
mysql_close();

?>

$_POST or session_start(); and $_SESSION.

Can you explain little more on $_post? Do we need to use $session? How do we use it. I am new on that.

Reid

You use $_POST to put the data in an global array whilst using a form method = post... And $_GET when you want to get the data from an URL.

$_SESSION is not needed when you use $_POST

With the $_GET you the the id from the query string. The first script is passing an ID from the query string.
In the first script you have an error building the url. Substitute:
echo "<td>" . "<a href=\"edit_update.php?id=\" " . $row . ">Edit/Update</a>" . "</td>";
With:
echo "<td>" . "<a href=\"edit_update.php?id=" . $row . ">Edit/Update</a>" . "</td>";
You

Member Avatar for soldierflup

A usefull hint : try to mix the " and ' signs to create a string.

Example :

<?php
$string = "< a href='test.php'">;
?>

instead of

<?php
$string = "<a href=\"test.php\"">;
?>

Sometimes this helps to find errors in building string and is less confusing.

Grtz,

Soldierflup

the url which is getting created is wrong. THere is an extra quote in url.

echo "<td>" . "<a href=\"edit_update.php?id=\" " . $row . ">Edit/Update</a>" . "</td>";

Make it

echo "<td>" . "<a href=\"edit_update.php?id= " . $row . ">Edit/Update</a>" . "</td>";

It will work.

--Amol
<FAKE SIGNATURE>

I could not figure out how to pass data to next page. Here is my code. I hope someone who can help me with it. I am trying tp pass id=$_get. Can someone look at the code and tell me what I do wrong. I am kind of new on this.

member.php
<HTML>
<HEAD>
<TITLE> Member List </TITLE>

</HEAD>
<BODY>
<FORM>

<?php
include ('dbc.php');
if ($db) {
//$SQL = "SELECT * FROM member";

$result = mysql_query("SELECT * FROM member");

echo "<table border='1'>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Maiden Name</th>
<th>Last Name</th>
<th>Month (start)</th>
<th>Year (start)</th>
<th>Month (end)</th>
<th>Year (end)</th>
<th>Edit/Update</th>
</tr>

";

while($row = mysql_fetch_array($result))
{

echo "<tr>";
echo "<td>" . $row . "&nbsp;</td>";
echo "<td>" . $row . "&nbsp;</td>";
echo "<td>" . $row . "&nbsp;</td>";
echo "<td>" . $row . "&nbsp;</td>";
echo "<td>" . $row . "&nbsp;</td>";
echo "<td>" . $row . "&nbsp;</td>";
echo "<td>" . $row . "&nbsp;</td>";
echo "<td>" . $row . "&nbsp;</td>";

echo "<td>" . "<a href=\"edit_update.php?id=\" " . $row . ">Edit/Update</a>" . "</td>";

}

echo "</tr>";

echo "</table>";
}
else {
echo "Database NOT Found ";
}

mysql_close($link) ;
?>
</FORM>
</BODY>
</HTML>

edit_update.php

<?php
include ('dbc.php');

$id=$_GET;

// Retrieve data from database
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);
?>

<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<form name="form1" method="post" action="update_ac.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>&nbsp;</td>
<td colspan="3"><strong>Update data in mysql</strong> </td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center"><strong>First Name</strong></td>
<td align="center"><strong>Maiden Name</strong></td>
<td align="center"><strong>Last Name</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="center"><input name="first_name" type="text" id="first_name" value="<? echo $rows; ?>"></td>
<td align="center"><input name="Maiden_name" type="text" id="Maiden_name" value="<? echo $rows; ?>" size="15"></td>
<td><input name="last_name" type="text" id="last_name" value="<? echo $rows; ?>" size="15"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="id" type="hidden" id="id" value="<? echo $rows; ?>"></td>
<td align="center"><input type="submit" name="Submit" value="Submit"></td>
<td>&nbsp;</td>
</tr>
</table>
</td>
</form>
</tr>
</table>

<?

// close connection
mysql_close();

?>

I need to move form field text to the next page and essential from the Javascript forum gave me this. It works in the test.

On the form page.

<form id="testform" action="nextpage.php" method="post">
<div>Test Field: <input type="text" id="FieldData0" name="FieldData0" value="" size="30" /> <input type="submit" value="submit" />
</div>
</form>

on the nextpage.php the code would look something like:

<html>
<head>
<body>
<h1><?php 
$testfield = $_POST['FieldData0'];
   if ( isset( $testfield )) { 
   echo $tesfield;
   } 
else { echo "Failed to capture entries"; } ?></h1>
</body>
</html>

Hope it can help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.