here is my table

CREATE TABLE `invoice` (
`invoice_id` tinyint(4) NOT NULL auto_increment,
`company_name` varchar(255) NOT NULL,
`issue_date` int(11) NOT NULL,
`invoice_title` varchar(255) NOT NULL,
`country` varchar(255) NOT NULL,
`invoice_number` int(20) unsigned NOT NULL,
`payment_method` varchar(255) NOT NULL,
`payment_due_date` int(11) NOT NULL,
`payment_plan` varchar(255) NOT NULL,
`paid` int(5) unsigned NOT NULL,
`paid_date` int(11) NOT NULL,
`added_date` int(11) NOT NULL,
`modified_date` int(11) NOT NULL,
PRIMARY KEY (`invoice_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;


please tell the query so that when i click edit for corresponding invoice_id should get updated by retreiving the corresponding invoice_id im able to get the corresponding values for editing but not able to update please pass me the query for the above table
thanks in advance

Hi vijukumar,
just because you press a button, nothing is going to be executed unless you program a script that does it (connect to a database, build the UPDATE query from FORM values and executes the query against the database). Maybe you're using some framework that does it for you but then you probably don't need to know the query as the framework should do all the work for you. You probably 'only' need to know more about the framework to know what is its built-in function for updating entities that you display in an edit form. Can't help you with this.

The final query will look something like this:
UPDATE `invoice` SET company_name = 'blah blah', issue_date = 123, .... .... WHERE invoice_id = 456;

Like I said, this is useless for you unless you have a script that fills in the attribute_name = attribute_value pairs.

admin_logged.php--------->below view hyper link will get the respected Id nd take yo to next page ie: edit.php as shown

<?               
$swipGalleryListQry = $db->get_rsltset("SELECT * FROM invoice");

                for ($img=0;$img<count($swipGalleryListQry);$img++)
                {

                    $invoice_id = $swipGalleryListQry[$img]['invoice_id']; 
                    $issue_date = $swipGalleryListQry[$img]['issue_date'];
                    $company_name = $swipGalleryListQry[$img]['company_name'];
                    $invoice_title = $swipGalleryListQry[$img]['invoice_title'];

                    echo "<tr class='text'> ";
                    echo "<td> $invoice_id  </td>";
                    echo "<td> $issue_date  </td>";
                    echo "<td> $company_name </td>";
                    echo "<td> $invoice_title </td>";                 
                    echo "<td>  200.00  </td>";
                    echo "<td> <a href='view_invoice.php?id=" . $swipGalleryListQry[$img]['invoice_id'] . "'>View</a> </td>";
                    echo "<td> <a href='delete.php?id=" . $swipGalleryListQry[$img]['invoice_id'] . "'>Delete</a></td>";
                    echo "<td> <a href='edit.php?id=" . $swipGalleryListQry[$img]['invoice_id'] . "'>Edit</a></td>";
                    //echo "<td> <a href='create_invoice.php'>Edit</a> </td>";              
                    echo "</tr>";                    

                }

?>

edit.php

//database connection here
<?php include_once "header.php"; ?>

......
.
.
<!--.to show form action when you submit-->
.   <tr> 
                    <td align="center">
                    <form action="edit_invoice_database_new.php?id= . $swipGalleryListQry[$img]['invoice_id'] . method="post">

                    <table width="100%" border="1" cellspacing="0" cellpadding="5">
                        <tr> 
                            <td colspan="2" class="textmore">Creating Invoice</td>
                        </tr>
.
.
.
.
.
<?//which shows the page to edit here value attribute will reflect all the particular data from data base back here.... is that name attribute is alrite? what changes i have to do so that when i edit it will update the same? 

$line=$_GET['id'];
$swipGalleryListQry = $db->get_rsltset("SELECT * FROM invoice where invoice_id='$line'");

                for ($img=0;$img<count($swipGalleryListQry);$img++)

                {


                    $company_name = $swipGalleryListQry[$img]['company_name'];                  
                    $issue_date = $swipGalleryListQry[$img]['issue_date'];                  
                    $invoice_number = $swipGalleryListQry[$img]['invoice_number'];
                    $payment_method = $swipGalleryListQry[$img]['payment_method']; 
                    $payment_due_date = $swipGalleryListQry[$img]['payment_due_date']; 
                    $payment_plan = $swipGalleryListQry[$img]['payment_plan']; 
                    $country = $swipGalleryListQry[$img]['country']; 
                    $invoice_title = $swipGalleryListQry[$img]['invoice_title']; 
                    $paid_date = $swipGalleryListQry[$img]['paid_date']; 
                    //$payment_due_date = $swipGalleryListQry[$img]['payment_due_date']; 







                        echo "<tr class='logo'>"; 
                            echo "<td width='22%' height='35' valign='middle'>To</td>";
                            echo "<td width='78%' align='left'>";
                            echo "<input name='$company_name' type='text' value='$company_name' class='typeforms'>";
                            echo "</td>";
                        echo "</tr>";
                        echo "<tr class='logo'>"; 
                            echo "<td>Issue Date</td>";
                            echo "<td><input name='$issue_dat' type='text' value='$issue_date' class='typeforms'></td>";
                        echo "</tr>";



                        echo "<tr class='logo'>"; 
                            echo "<td>Country</td>";
                            echo "<td><input name='$country' type='text' value='$country' class='typeforms'></td>";
                        echo "</tr>";
                        echo "<tr class='logo'>";
                            echo "<td><p>Invoice Title</td>";
                            echo "<td>";
                                 echo " <input name='$invoice_title' value='$invoice_title' type='text' class='typeforms'>";
                             echo " (for your reference- this will not be displayed in the invoice)";     

                        echo "</tr>";

                        echo "<tr class='logo'>"; 
                            echo "<td>Invoice Number </td>";
                            echo "<td><input name='$invoice_number' value='$invoice_number' type='text' class='typeforms'></td>";
                        echo "</tr>";



                        echo "<tr>"; 
                        echo "<td colspan='2' align='right'>";
                                                echo "<table width='100%' border='1' cellpadding='8' cellspacing='0' bordercolor='#CCCCCC'>";
                                                echo "<tr >"; 
                                                echo "<td>&nbsp;</td>";
                                                echo "<td>&nbsp; </td>";
                                                echo "<td colspan='2' align='right'>";
                                                echo "<table width='47%' border='0' cellspacing='0' cellpadding='4'>";
                                                echo "<tr bgcolor='#FFFFCC'>"; 
                                                echo "<td width='70%' align='center' class='text'>No of rows</td>";
                                                echo "<td width='30%' align='center'>"; 
                                                echo "<input name='textfield' type='text' class='typeforms' value='2' size='2' maxlength='2'>";
                                                echo "</td>";
                                                echo "</tr>";
                                                echo "</table>"; 
                                                echo "</td>";
                                                echo "</tr>";
                                                echo "<tr class='text'>"; 
                                                echo "<td width='10%'>Sl.No</td>";
                                                echo "<td width='46%'>Description</td>";
                                                echo "<td width='19%'>Quantity</td>";
                                                echo "<td width='25%'>Amount</td>";
                                                echo "</tr>";
                                                echo "<tr class='text'>"; 
                                                echo "<td>1</td>";
                                                echo "<td><textarea name='$description' cols='45' rows='7' class='typeforms'></textarea></td>";
                                                echo "<td><input name='quantity' type='text' class='typeforms' size='4'></td>";
                                                echo "<td><input name='amount' type='text' class='typeforms' value='0' size='10'>";
                                                echo ".";
                                                echo "<input name='' type='text' class='typeforms' value='00' size='2'></td>";
                                                echo "</tr>";
                                                echo "<tr class='text'>"; 
                                                echo "<td height='131'>2</td>";
                                                echo "<td><textarea name='textfield' cols='45' rows='7' class='typeforms'></textarea></td>";
                                                echo "<td><input name='textfield' type='text' class='typeforms' size='4'></td>";
                                                echo "<td><input name='textfield' type='text' class='typeforms' value='0' size='10'>";
                                                echo "."; 
                                                echo "<input name='textfield' type='text' class='typeforms' value='00' size='2'></td>";
                                                echo "</tr>";
                                                echo "<tr class='text'>"; 
                                                echo "<td>&nbsp;</td>";
                                                echo "<td>&nbsp;</td>";
                                                echo "<td align='right'>Sub Total </td>";
                                                echo "<td><input name='textfield' type='text' class='typeforms' value='0' size='10'>";
                                                echo "."; 
                                                echo "<input name='textfield' type='text' class='typeforms' value='00' size='2'></td>";
                                                echo "</tr>";
                                                echo "<tr class='text'>";
                                                 echo " <td>&nbsp;</td>";
                                                  echo "<td>&nbsp;</td>";
                                                  echo "<td align='right'>GST/ TAX/ VAT</td>";
                                                  echo "<td><input name='textfield' type='text' class='typeforms' value='0' size='10'>";
                                                    echo ".";
                                                     echo " <input name='textfield' type='text' class='typeforms' value='00' size='2'></td>";
                                                echo "</tr>";
                                                echo "<td>&nbsp;</td>";
                                                echo "<td>&nbsp;</td>";
                                                echo "<td align=right'><span class='text'>Total</span></td>";
                                                echo "<td><input name='textfield' type='text' class='typeforms' value='0' size='10'>";
                                                echo "."; 
                                                echo "<input name='textfield' type='text' class='typeforms' value='00' size='2'> </td>";


                                                echo "</table>";
                        echo "</td>";
                        echo "</tr>";


                            echo "<tr>"; 
                            echo "<td colspan='2' align='right'>";
                                                    echo "<table width='100%' border='1' cellpadding='6' cellspacing='0' bordercolor='#CCCCCC'>";
                                                    echo "<tr >"; 
                                                    echo "<td width='34%'><span class='text'> Payment Method</span>";
                                                                        echo "<input name='$payment_due_date' type='text' value='$payment_method' class='typeforms'>";   

                                                 echo "</td>";


                                                echo "<td width='34%' align='left'>";
                                                echo "<span class='text'>";
                                                echo "Payment is due</span>";
                                                echo "<input name='$payment_due_date' type='text' value='$payment_due_date'class='typeforms'>";
                                                echo "</td>";
                                                echo "<td width='32%'>"; 
                                                echo "<span class='text'>Payment plan</span>";
                                                echo "<input name='$payment_plan' type='text' value='$payment_plan' class='typeforms'>";   
                                                echo "</pre>";
                                                echo "</td>";

                                                echo "</tr>";

                                                echo "<tr >"; 
                                                echo "<td width='34%'><span class='text'>";
                                                echo"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                                                echo "&nbsp;paid </span>"; 
                                                                echo "<input type='checkbox' name='paid' value='checkbox' class='typeforms'>";


                                                 echo "</td>";


                                                echo "<td width='34%' align='left'>";
                                                echo "<span class='text'>";
                                                echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Paid Date </span>";
                                                echo "<input name='$paid_date' type='text'  value='$paid_date' class='typeforms'>";
                                                echo "</td>";
                                                echo "<td width='32%'>&nbsp;"; 
                                                echo "</td>";
                                                echo "</tr>";
                                                echo "</table>";
                        echo "</td>";
                        echo "</tr>";



                                }

?>

edit_invoice_database_new.php

<?// here i tried all possible things i need help for first one proper query and the best get_a_line functions for my database.class please send me the code with altering these + your database.class file which i keep inside the common folder. database is shown in the previous thread thank you.

 include_once "header.php"; 

$swipGalleryListQry = $db->get_a_line("update invoice  set company_name='$company_name' 
where invoice_id='$line'");


//$swipGalleryListQry = $db->delete_single_row("update invoice  //set company_name='$_POST[company_name]',issue_date='$_POST[issue_date]',invoice_title='$_POST[invoice_title]',country='$_POST[country]',invoice_number='$_POST[invoice_number]',payment_method='$_POST[payment_method]',payment_due_date='$_POST[payment_due_date]',payment_plan='$_POST[payment_plan]',paid='$_POST[paid]',paid_date='$_POST[paid_date]',added_date='$_POST[added_date]',modified_date='$_POST[modified_date]') 
//where invoice_id="$line"");

//$swipGalleryListQry = $db->delete_single_row("update invoice  //set(company_name,issue_date,invoice_title,country,invoice_number,payment_method,payment_due_date,payment_plan,paid,paid_date,added_date,modified_date) 
//values('$_POST[company_name]','$_POST[issue_date]','$_POST[invoice_title]','$_POST[country]','$_POST[invoice_number]','$_POST[payment_method]','$_POST[//payment_due_date]','$_POST[payment_plan]','$_POST[paid]','$_POST[paid_date]','$_POST[added_date]','$_POST[modified_date]') where invoice_id='$line");

 print "<script>";
print " self.location='admin_logged';"; // Comment this line if you don't want to redirect
print "</script>";

?>

Edited 3 Years Ago by mike_2000_17: Fixed formatting

hi
i did not go through ur code but i do understand tat u want a code for edit & update...if so use the below code

1 st page where allthe retrived data is will be in the fields
here i have used id in session ,to pass the get the id from 1 st page to 3rd page

<form method="post" action="update2.php">
<?php
$hostname = "";
$username = "";
$password = "";
$dbid = "";
$link=mysql_connect($hostname, $username, $password);
mysql_select_db($dbid) or die("unable to connect"); 
$query="SELECT * FROM personal where id='$_SESSION[id]'";
$result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
for ($i = 0; $i < 1; ++$i)
{
$line = mysql_fetch_row($result);

print '<tr><td>Name</td><td><input type="hidden" name="name1" value="'.$line[1].'"></td>
<td><input type="text" name="nname1" size="53" value="'.$line[1].'"></td></tr>';

print '<tr><td>Date of Birth</td><td><input type="hidden" name="dob" size="53" value="'.$line[13].'"></td>
<td><input type="text" name="ndob" size="53" value="'.$line[13].'"></td></tr>';
print '<tr><td><input type="hidden" name="spid" size="53" value="'.$line[0].'"></td></tr>';
print '<tr><td><input type="submit" name="submit" value="Update"></td></tr>';
print '</table>';
}
mysql_close($link);
?>

</form>

2nd page contains the update command

<form>
<?php
$hostname = "";
$username = "";
$password = "";
$dbid = "";
$link=mysql_connect($hostname, $username, $password);
mysql_select_db($dbid) or die("unable to connect"); 
$nname1=$_REQUEST['nname1'];
$ndob=$_REQUEST['ndob'];
if (isset($_REQUEST['submit'])) 
{ 
mysql_query("UPDATE personal SET name='$nname1',doj='$ndoj') or die("ERROR:".mysql_error());
echo "Thank for Updating";
}
mysql_close($link);
?>
</form>

if u want to use where then

mysql_query("UPDATE personal SET name='$fieldname1',doj='$fieldname2' where name='$hiddenfield')

hiddenfield name is the name of the field tat is hidden,it will contain the old value

Hi vijukumar,
your source code would be much easier to read if you used code tags when pasting it into this forum. Please edit your post and add them.

I noticed that you incorrectly name the input fields:

echo "<input name='$company_name' type='text' value='$company_name' class='typeforms'>";

You should remove the first dollar symbol:

echo "<input name='company_name' type='text' value='$company_name' class='typeforms'>";

I don't know what database wrapper you're using so I can't tell you which method you should call for a simple query execution. Attach the source code if you want me to have a look. The simplest method would be

mysql_query("update invoice set company_name='$company_name'
where invoice_id='$line'");

This would update only the company name, of course. You have to add other attribute=value pairs for other attributes. Also, it's better to use $_POST or more general $_REQUEST arrays because $company_name will contain your form values only if register_globals is on.

Also it looks like you're not passing $line variable in the form. Add a hidden attribute with $line value.

I guess this answers all your questions, doesn't it? Let me know if I missed something.

This article has been dead for over six months. Start a new discussion instead.