after i click on this a href, it ll pop out a form and i trying to pass a variable to the pop up form. This is in a while loop.
while($row = mysql_fetch_array($result))
{
$id=$row['file_id'];
echo '<span class=right>[edit]
}
This is the pop up form code
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("isiti");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if (isset($_GET["id"]))
{
$id =$_GET["id"];
}
$result = mysql_query("SELECT * FROM publication where file_id='$id'");
$row1 = mysql_fetch_array($result);
$title=$row1['title'];
$author=$row1['author'];
$year=$row1['year'];
$abstract=$row1['abstract'];
if(!empty($_SESSION['username']))
{
echo'<div class="popup">';
echo'<form method="POST" action="public_edit.php" enctype="multipart/form-data">';
echo'<div>';
echo'<label for="citation">Title</label>';
echo'<input style="width:100%;" type="text" name="title" id="title" value="'.$title.'">';
echo'</div>';
echo'<div>';
echo'<label for="citation">Author</label>';
echo'<input style="width:100%;" type="text" name="author" id="author" value="'.$author.'">';
echo'</div>';
echo'<div>';
echo'<label for="citation">Year</label>';
echo'<input style="width:100%;" type="year" name="year" id="year" value="'.$year.'">';
echo'</div>';
echo'<div>';
echo'<label for="abstract">Abstract</label>';
echo'<textarea name="abstract" id="abstract" size="5000">'.$abstract.'</textarea>';
echo'</div>';
echo'<p>Rechoose your file here</p>';
echo'<input type="hidden" name="MAX_FILE_SIZE" value="2000000">';
echo'<input name="userfile" type="file" id="userfile"> ';
echo'<br/> ';
echo'<input name="submit" type="submit" value="Upload" style="width: 150px">';
echo'<a class="close" href="#close"></a>';
echo'</form>';
echo'</div>';
}
The problem i faced is that it do not pass the right id. no matter what link i click it show the data from the first id.
Thanks for helping me .
You need to pass the id as get parameter when calling that pop up. Replace with this the echo statement in first code
echo '<span class=right>[edit]';
$_GET works well for data sent by a query string. In this case, you are sending the data as the id of href tag.
so try attaching id to your query string.
echo '<span class=right>[edit]
Related
So basically what I am trying to do is using a loop to display multiple image and create a corresponding button to each image. If I pressed on the corresponding button, it will store the image into another database.
The first part display quite well. However, the second part I can hardly figure out how to determine the corresponding button for each image.
<?php while($row=mysqli_fetch_array($result)) { ?>
<div id="item">
<?php echo '<img height="200" width="200" src="data:image;base64,'.$row[2]. '">';?>
</br>
<?php echo $row[ "name"];?>
</br>
<?php echo $row[ "price"];?>
</br>
<?php echo $row[ "description"];?>
</br>
<form>Quantity:
<input type="text" value="" name="quantity" />
</br>
<input type="submit" value="add to cart" name="cart" />
</form>
<?php
if (isset($_POST[ "cart"])){
$addtoname=$_SESSION[ 'username'];
$addtoprice=$row[ 'price'];
$addtodiscount=$row[ 'discount'];
$addtoid=$row[ 'id'];
$addtoimage=$row[ 'image'];
$addtoquantity=$_POST[ 'quantity'];
$hostname="localhost" ;
$username="root";
$password="" ;
$database="myproject" ; $con=mysqli_connect($hostname,$username,$password,$database) or die(mysqli_error());
$select=mysqli_select_db($con, "myproject")or die( "cannnot select db"); mysqli_query($con,"INSERT INTO cart(username,quantity,price,image,id,discount) VALUES('$addtoname','$addtoquantity','$addtoprice','$addtoimage','$addtoid','$addtodiscount')");
echo "success";
}
else{
echo "fail";
}?>
</div>
<?php }//end of while ?>
It seems like it always go to fail AND never run into isset($_POST[ "cart"]))
Any tips will be much appreciated.
Thank you
Create 2 files:
One with the actual form populated by the DB:
<?php while($row=mysqli_fetch_array($result)) { ?>
<div id="item">
<form method="post" action="cartReceiver.php">Quantity:
<?php echo '<img height="200" width="200" src="data:image;base64,'.$row[2]. '">';?>
</br>
<?php echo $row[ "name"];?>
</br>
<?php echo $row[ "price"];?>
</br>
<?php echo $row[ "description"];?>
</br>
<input type="text" value="" name="quantity" />
</br>
<input type="submit" value="add to cart" name="cart" />
</form>
</div>
<?php }//end of while ?>
And then the receiver of the action declared in form(cartReceiver.php):
<?php
if (isset($_POST[ "cart"])){
$addtoname=$_SESSION[ 'username'];
$addtoprice=$row[ 'price'];
$addtodiscount=$row[ 'discount'];
$addtoid=$row[ 'id'];
$addtoimage=$row[ 'image'];
$addtoquantity=$_POST[ 'quantity'];
$hostname="localhost" ;
$username="root";
$password="" ;
$database="myproject" ; $con=mysqli_connect($hostname,$username,$password,$database) or die(mysqli_error());
$select=mysqli_select_db($con, "myproject")or die( "cannnot select db"); mysqli_query($con,"INSERT INTO cart(username,quantity,price,image,id,discount) VALUES('$addtoname','$addtoquantity','$addtoprice','$addtoimage','$addtoid','$addtodiscount')");
echo "success";
}
else{
echo "fail";
}
Note that I changed the tag order of the form. If you wish to receive the fetched parameters from POST without querying the DB after transition, then you can change the first file like this:
<?php while($row=mysqli_fetch_array($result)) { ?>
<div id="item">
<form method="post" action="cartReceiver.php">Quantity:
<?php echo '<img height="200" name="image" width="200" src="data:image;base64,'.$row[2]. '">';?>
</br>
<input type="text" name="username" value="<?php echo $row[ "name"];?>" readonly />
</br>
<input type="text" name="price" value="<?php echo $row[ "price"];?>" readonly />
<input type="hidden" name="discount" value="<?php echo $row[ "discount"];?>" />
</br>
<input type="text" name="description" value="<?php echo $row[ "description"];?>" readonly />
</br>
<input type="text" value="" name="quantity" />
</br>
<input type="submit" value="add to cart" name="cart" />
</form>
</div>
<?php }//end of while ?>
So the cartReceiver.php file will look like this in this case:
<?php
if (isset($_POST[ "cart"])){
$addtoname=$_POST['username'];
$addtoprice=$_POST['price'];
$addtodiscount=$_POST['discount'];
$addtoid=$_POST['id'];
$addtoimage=$_POST['image'];
$addtoquantity=$_POST[ 'quantity'];
$hostname="localhost" ;
$username="root";
$password="" ;
$database="myproject" ; $con=mysqli_connect($hostname,$username,$password,$database) or die(mysqli_error());
$select=mysqli_select_db($con, "myproject")or die( "cannnot select db"); mysqli_query($con,"INSERT INTO cart(username,quantity,price,image,id,discount) VALUES('$addtoname','$addtoquantity','$addtoprice','$addtoimage','$addtoid','$addtodiscount')");
echo "success";
}
else{
echo "fail";
}
Notice the readonly attirbute in the inputs. It will prevent the users from altering their contents.
Now you can access all the inputs after you submit the form (click the add to cart button) by using $_POST['name'],$_POST['description'] etc
EDIT: Code updated for your needs. Since it seems you dont want to display the discount, you pass it to the form through a hidden field which can be then accessed as the others through $_POST.
First if all you need to make sure your submit button is inside a form that has the action field set to the current script. Second, I would place inside it a hidden field with the id of the image as value, so you know which image was submitted
Neither of the divs and buttons defined after the while loop are visible until the timer goes down. I don't know what's the problem. I tried it outside the php also but still it shows nothing. Everything was working well before adding this php code to display a number of distinct questions selected from a database randomly. Someone please help me. I'm a newbie in php. Thanks a lot in advance.
<?php
$record=array(); //creating array to keep record of Q_ID of questions
for($count=1;$count <= $NoOfQuestion;$count++)// to display $NoOfQuestion number of questions
{
while(1)
{
$sql=mysql_query("select * from questions order by RAND()");
$result = mysql_fetch_array($sql);
$temp=0;
if(count($record)>=1)
{
for($i=1;$i<=$count;$i++)
{
if($record[$i]==$result['Q_ID'])
$temp++;
}
}
if($temp==0)
{
$text ='Question '.$count. '. '.$result['Question'];
echo $text;
return 0;
}
else
return 1;
}
echo'</div>';
echo'<div id="option"></div>';
echo'<div id="buton">';
echo'<input type="submit" name="Previous" value="previous" id="previous"/>';
echo'<input type="submit" name="Next" value="next" id="next"/>';
echo'<input type="submit" name="Review" value="review" id="review"/>';
echo'<input type="submit" name="Submit" value="submit" id="submit"/>';
echo'</div>';
echo'<div id="div3">3</div>';
echo'</div>';
echo'</form>';
}
?>
Modify your code....
echo'<div id="option"></div>';
echo'<div id="buton">';
echo'<input type="submit" name="Previous" value="previous" id="previous"/>';
echo'<input type="submit" name="Next" value="next" id="next"/>';
echo'<input type="submit" name="Review" value="review" id="review"/>';
echo'<input type="submit" name="Submit" value="submit" id="submit"/>';
echo'</div>';
echo'<div id="div3">3</div>';
Try
<?php
$record=array(); //creating array to keep record of Q_ID of questions
for($count=1;$count <= $NoOfQuestion;$count++)// to display $NoOfQuestion number of questions
{
while(1)
{
$sql=mysql_query("select * from questions order by RAND()");
$result = mysql_fetch_array($sql);
$temp=0;
if(count($record)>=1)
{
for($i=1;$i<=$count;$i++)
{
if($record[$i]==$result['Q_ID'])
$temp++;
}
}
if($temp==0)
{
$text ='Question '.$count. '. '.$result['Question'];
echo $text;
return 0;
}
else
return 1;
}
}
echo '</div>';
echo '<div id="option"></div>';
echo '<div id="buton">';
echo '<input type="submit" name="Previous" value="previous" id="previous"/>';
echo '<input type="submit" name="Next" value="next" id="next"/>';
echo '<input type="submit" name="Review" value="review" id="review"/>';
echo '<input type="submit" name="Submit" value="submit" id="submit"/>';
echo '</div>';
echo '<div id="div3">3</div>';
echo '</div>';
echo '</form>';
?>
PHP it's throwing at me
Notice: Undefined index: username in D:\xampp\htdocs\0100348514\pages\account.php on line 16
Warning: mysql_query() expects parameter 1 to be string, resource given in D:\xampp\htdocs\pages\account.php on line 19
But in my database I have it exactly the same 'username' but it's still throwing it at me any ideas?
Code on that page
<?php
$page = "My Account";
session_start();
include '../includes/config.php';
?>
<div id="searchbar">
<form action="search.php" method="get">
<input type="text" name="search" />
<input type="submit" name="submit" class="btn btn-primary" value="Search" />
</form>
</div>
</div>
<?php
$username = $_SESSION['username'];
$sql = "SELECT * FROM login WHERE username = '$username'";
$result = mysql_query($con, $sql) or die(mysql_error($con)); //run the query
$row = mysql_fetch_array($result);
?>
<div id="wrapper">
<section id="content" class="shadow">
<div id="titlebar">
<?php
echo $page = '<h1> My ACCOUNT </h1>';
?>
</div>
<br />
<?php
//user messages
if(isset($_SESSION['error'])) //if session error is set
{
echo '<div class="error">';
echo '<p class="center">' . $_SESSION['error'] . '</p>'; //display error message
echo '</div><br />';
unset($_SESSION['error']); //unset session error
}
elseif(isset($_SESSION['success'])) //if session success is set
{
echo '<div class="success">';
echo '<p class="center">' . $_SESSION['success'] . '</p>'; //display success message
echo '</div><br />';
unset($_SESSION['success']); //unset session success
}
?>
<div id='left'>
<form id="registration" form action="accountprocessing.php" method="post">
<br />
<fieldset><h1>Update Your Details</h1><br />
<ol>
<li>
<label>Username*</label> <input type="text" name="username" required value="<?php echo $row['username'] ?>" readonly />
</li>
<?php
//generate drop-down list for state using enum data type and values from database
$tableName='member';
$colState='state';
function getEnumState($tableName, $colState)
{
global $con; //enable database connection in the function
$sql = "SHOW COLUMNS FROM $tableName WHERE field='$colState'";
//retrieve enum column
$result = mysql_query($con, $sql) or die(mysql_error($con));
//run the query
$row = mysql_fetch_array($result); //store the results in a variable named $row
$type = preg_replace('/(^enum\()/i', '', $row['Type']); //regular expression to replace the enum syntax with blank space
$enumValues = substr($type, 0, -1); //return the enum string
$enumExplode = explode(',', $enumValues); //split the enum string into individual values
return $enumExplode; //return all the enum individual values
}
$enumValues = getEnumState('member', 'state');
echo '<select name="state">';
if((is_null($row['state'])) || (empty($row['state']))) //if the state field is NULL or empty
{
echo "<option value=''>Please select</option>"; //display the 'Please select' message
}
else
{
echo "<option value=" . $row['state'] . ">" . $row['state'] .
"</option>"; //display the selected enum value
}
foreach($enumValues as $value)
{
echo '<option value="' . $removeQuotes = str_replace("'", "",
$value) . '">' . $removeQuotes = str_replace("'", "", $value) . '</option>'; //remove the quotes from the enum values
}
echo '</select><br />';
?>
</li>
<p> </p>
<li>
<label>Postcode*</label> <input type="text" name="postcode" required value="<?php echo $row['postcode'] ?>"/>
</li><br />
<li>
<label>Country*</label> <input type="text" name="country" required value="<?php echo $row['country'] ?>"/>
</li><br />
<li>
<label>Phone</label> <input type="text" name="phone" value="<?php echo $row['phone'] ?>"/>
</li><br />
<li>
<label>Mobile</label> <input type="text" name="mobile" value="<?php echo $row['mobile'] ?>" />
</li><br />
<li>
<label>Email*</label> <input type="email" name="email" required value="<?php echo $row['email'] ?>" />
</li><br />
<li><label>Gender*</label>
<?php
//generate drop-down list for gender using enum data type and values from database
$tableName='member';
$colGender='gender';
function getEnumGender($tableName, $colGender)
{
global $con; //enable database connection in the function
$sql = "SHOW COLUMNS FROM $tableName WHERE field='$colGender'";
//retrieve enum column
$result = mysql_query($con, $sql) or die(mysql_error($con));
//run the query
$row = mysql_fetch_array($result); //store the results in a variable named $row
$type = preg_replace('/(^enum\()/i', '', $row['Type']); //regular expression to replace the enum syntax with blank space
$enumValues = substr($type, 0, -1); //return the enum string
$enumExplode = explode(',', $enumValues); //split the enum string into individual values
return $enumExplode; //return all the enum individual values
}
$enumValues = getEnumGender('member', 'gender');
echo '<select name="gender">';
echo "<option value=" . $row['gender'] . ">" . $row['gender'] .
"</option>"; //display the selected enum value
foreach($enumValues as $value)
{
echo '<option value="' . $removeQuotes = str_replace("'", "",
$value) . '">' . $removeQuotes = str_replace("'", "", $value) . '</option>';
}
echo '</select>';
?>
</li>
</ol>
</fieldset>
<br />
<fieldset>
<p>Subscribe to weekly email newsletter?</p><br />
<label>Yes</label><input type="radio" name="newsletter" value="Y" <?php if($row['newsletter'] == "Y"){echo "checked";} ?>><br />
<label>No</label><input type="radio" name="newsletter" value="N" <?php if($row['newsletter'] == "N"){echo "checked";} ?>>
<input type="hidden" name="memberID" value="<?php echo $memberID; ?>">
</fieldset><br />
<p class="center"><input type="submit" name="accountupdate" value="Update Account" /></p><br />
</form>
</div>
<br />
<div id='right'>
<form id="registration" form action="accountimageprocessing.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="memberID" value="<?php echo $memberID; ?>">
<br />
<fieldset><h1>Update Image</h1><br />
<?php
if((is_null($row['image'])) || (empty($row['image']))) //if the photo field is NULL or empty
{
echo "<p class='center'><img src='../images/members/member.png' width=150 height=150 alt='default photo' /></p>"; //display the default photo
}
else
{
echo "<p class='center'><img src='../images/members/" . ($row['image']) . "'" . 'width=150 height=150 alt="contact photo"' . "/></p><br />"; //display the contact photo
}
?>
<label>New Image</label> <input type="file" name="image" />
<br />
<p>Accepted files are JPG, GIF or PNG. Maximum size is 500kb.</p>
<br />
<p class='center'><input type="submit" name="imageupdate" value="Update Image" /></p>
</form>
<br />
<br />
<form action="accountpasswordprocessing.php" method="post">
<h1>Update Password</h1>
<br />
<p>Passwords must have a minimum of 8 characters.</p> <br />
<label>New Password*</label> <input type="password" name="password" pattern=".{8,}" title= "Password must be 8 characters or more" required />
<br />
<input type="hidden" name="memberID" value="<?php echo $memberID; ?>">
<br />
<p class='center'><input type="submit" name="passwordupdate" value="Update Password" /></p>
<br />
</form>
<h1>Delete My Account</h1>
<br />
<p>We're sorry to hear you'd like to delete your account. By clicking the button below you will permanently delete your account.</p>
<br />
<form action="accountdelete.php" method="post">
<p class='center'><input type="submit" value="Delete My Account" onclick="return confirm('Are you sure you wish to permanently delete your account?');" ></p>
<input type="hidden" name="memberID" value="<?php echo $memberID; ?>"><br />
</fieldset>
</form>
</div>
</section> <!-- end #content -->
<div id="footernav" class id="shadow">
<?php
require "../inc/footer.php";
?>
</div>
</div>
Your mysql_query parameteres are reversed. It should be:
mysql_query($sql, $con);
Also as you can see in the linked PHP Manual page, this extension is deprecated and alternatives should be used:
This extension is deprecated as of PHP 5.5.0, and will be removed in
the future. Instead, the MySQLi or PDO_MySQL extension should be used.
See also MySQL: choosing an API guide and related FAQ for more
information. Alternatives to this function include:
mysqli_query()
PDO::query()
I have recently used a PHP pagination tutorial, Pagination - what it is and how to do it, to display record information from a MySQL database. The problem is that the page only sends out the information sent in the latest form, and I am not quite sure how to fix the problem.
The code for the form output is shown below.
$musicitems = getmusicitems($pagenumber,$prevpage,$lastpage,$nextpage);
$count = ($musicitems==NULL) ? 0 : mysql_num_rows($musicitems);
for ($i=0;$i<$count;$i++)
{
$records = mysql_fetch_assoc($musicitems);
print'
<label for="deleteMusicItem'.$records['m_id'].'" id="deleteMusicItemLabel'.$records['m_id'].'">Delete Music Record:</label>
<input type="checkbox" name="deleteMusicItem" id ="deleteMusicItem'.$records['m_id'].'" value="delete" />
<br/>
<label for="artistname'.$records['m_id'].'" id="artistLabel'.$records['m_id'].'">Artist Name:</label>
<input type="text" size="30" name="artistname" class="artistname1" id ="artistname'.$records['m_id'].'" value="'.$records['artistname'].'" />
<br/>
<label for="recordname'.$records['m_id'].'" id="recordnameLabel'.$records['m_id'].'">Record Name:</label>
<input type="text" size="30" name="recordname" class="recordname1" id ="recordname'.$records['m_id'].'" value="'.$records['recordname'].'"/>
<br/>
<label for="recordtype'.$records['m_id'].'" id="recordtypeLabel'.$records['m_id'].'">Record type:</label>
<input type="text" size="20" name="recordtype" class="recordtype1" id ="recordtype'.$records['m_id'].'" value="'.$records['recordtype'].'"/>
<br/>
<label for="format'.$records['m_id'].'" id="formatLabel'.$records['m_id'].'">Format:</label>
<input type="text" size="20" name="format" class="format1" id ="format'.$records['m_id'].'" value="'.$records['format'].'"/>
<br/>
<label for="price'.$records['m_id'].'" id="priceLabel'.$records['m_id'].'">Price:</label>
<input type="text" size="10" name="price" class="price1" id ="price'.$records['m_id'].'" value="'.$records['price'].'"/>
<br/><br/>
';
$musicfiles=getmusicfiles($records['m_id']);
for($j=0; $j<2; $j++)
{
$mus=mysql_fetch_assoc($musicfiles);
if(file_exists($mus['musicpath']))
{
echo ''.$mus['musicname'].'<br/>';
}
else
{
echo '<label for="musicFile'.$records['m_id'].'" id="musicFileLabel'.$records['m_id'].'">Music:</label> <input type="file" size="40" name="musicFile1" id="musicFile'.$records['m_id'].'"/><br/>';
}
}
$pictures=getpictures($records['m_id']);
for($j=0;$j<2;$j++)
{
$pics=mysql_fetch_assoc($pictures);
if(file_exists($pics['picturepath']))
{
echo '<img src="'.$pics['picturepath'].'" width="150" height="150"><br/>';
}
else
{
echo '<label for="pictureFile'.$records['m_id'].'" id="pictureFileLabel'.$records['m_id'].'">Picture:</label><input type="file" size="40" name="pictureFile1" id="pictureFile'.$records['m_id'].'"/><br/>';
}
}
}
echo'<input type="submit" value="Submit" name="modfiymusicitem" id="modfiymusicitem" /> ';
if ($pagenumber == 1) {
echo " FIRST PREV ";
}
else {
echo " <a href='{$_SERVER['PHP_SELF']}?pagenumber=1'>FIRST</a> ";
$prevpage = $pagenumber-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenumber=$prevpage'>PREV</a> ";
}
echo "(Page $pagenumber of $lastpage)";
if ($pagenumber == $lastpage) {
echo " NEXT LAST ";
}
else {
$nextpage = $pagenumber+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenumber=$nextpage'>NEXT</a> ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenumber=$lastpage'>LAST</a> ";
}
You have to pass the form data to the next page manually. This, most important part, is always forgotten by tutorial writers.
You have to pass to other pages, not only the page number, but the whole form data.
I hope your form uses the GET method, as it should be, so, you have your data either in the $_SERVER['QUERY_STRING'] as a string or the $_GET array. So, you can either do regexp pagenumber in the QUERY_STRING, or assemble another QUERY_STRING from the $_GET array, like this:
$_GET['pagenumber']=$nextpage;
$query_string=http_build_query($_GET);
echo " <a href='{$_SERVER['PHP_SELF']}?$query_string'>NEXT</a> ";
Update mysql with $_POST data from while loop
I'm trying to get this round my head, but i am failing quite hard :[
I have 3 rows in a database which i am echoing out in a while() loop.
A user can change search_terms and then save the fields in mysql, however i don't quite know how to do this, as there are 3 rows, so i can't just do;
<?php
if($_POST['update']) {
mysql_query("....");
}
?>
Here is my code;
<?php
$box_query = mysql_query("SELECT * FROM `ta_boxs`");
while($box = mysql_fetch_array($box_query)) {
echo '<div class="box_content">';
echo '<div class="box">'."\n";
echo '<span class="box_top"></span>';
echo '<div class="box_header"><input type="text" id="title" name="title" class="title-input" value="'.$box['title'].'" /></div>';
echo '<span class="sept"></span>';
echo '<div class="admin-back">';
echo '<form id="form-'.$box['id'].'" name="form-'.$box['id'].'" method="post" action="">';
echo '<p class="sub"><span>Includes:</span> Search for these terms in Twitter Feeds.</p>';
echo '<p class="sub-small">Please enter one word per field or click "add word".</p>';
echo '<p><input type="text" id="search_term_1" name="search_term_1" value="'.$box['search_term_1'].'" class="term-input" />';
echo '<p><input type="text" id="search_term_2" name="search_term_2" value="'.$box['search_term_2'].'" class="term-input" />';
echo '<p><input type="text" id="search_term_3" name="search_term_3" value="'.$box['search_term_3'].'" class="term-input" />';
echo '<span class="hr"></span>';
echo '<p class="sub"><span>Excludes:</span> Ignore these terms in Twitter Feeds.</p>';
echo '<p class="sub-small">Please enter one word per field or click "add word".</p>';
echo '<p><input type="text" id="search_term_1" name="search_term_1" value="'.$box['exc_search_term_1'].'" class="term-input" />';
echo '<p><input type="text" id="search_term_2" name="search_term_2" value="'.$box['exc_search_term_2'].'" class="term-input" />';
echo '<p><input type="text" id="search_term_3" name="search_term_3" value="'.$box['exc_search_term_3'].'" class="term-input" />';
echo '<input type="hidden" id="update" name="update" value="yes" />'
echo '<p><input type="submit" id="update_'.$box['id'].'" name="update_'.$box['id'].'" value="Update" /></p>';
echo '</form>';
echo '</div>';
echo '</div>'."\n";
echo '<span class="box_bottom"></span>';
echo '</div>';
}
?>
There could be 1 output, or 100, but i need a way to save them all, onsubmit. Any ideas?
Since you're outputting each box in a different <form> you'll only every get one back.
If you change:
<input type="hidden" id="update" name="update" value="yes" />
to
<input type="hidden" id="update" name="update" value="' . $box['id'] . '" />
Then you'll be able to look which one was posted back.
I don't think your approach will work because you are generating multiple forms, so PHP will only get the one form that is submitted, and you won't be able to save all the changes on your page.
You might want to consider using one form and naming your inputs like an array (see http://php.net/manual/en/faq.html.php#faq.html.arrays) .
e.g. (simplified)
<form method="post">
<?php while($box = mysql_fetch_array($box_query)): ?>
<!-- div box thing -->
<input name="box[<?php echo $box['id'];?>][search_term_1]" value="<?php echo $box['search_term_1']; ?>">
<input name="box[<?php echo $box['id'];?>][search_term_2]" value="<?php echo $box['search_term_2']; ?>">
<input name="box[<?php echo $box['id'];?>][search_term_3]" value="<?php echo $box['search_term_3']; ?>">
<input name="box[<?php echo $box['id'];?>][exc_search_term_1]" value="<?php echo $box['exc_search_term_1']; ?>">
<input name="box[<?php echo $box['id'];?>][exc_search_term_2]" value="<?php echo $box['exc_search_term_2']; ?>">
<input name="box[<?php echo $box['id'];?>][exc_search_term_3]" value="<?php echo $box['exc_search_term_3']; ?>">
<!-- end div box thing -->
<?php endwhile; ?>
</form>
If you print_r($_POST) after submitting that form you should see that it will be fairly easy to loop over/process.
make one form ,
and in this form set all fields,
one button to submit ,
give to the input elements unique id to every row like you do to the form with the box id