Jump to content

[SOLVED] Edit/Update Record via Form


aeafisme23

Recommended Posts

So i am not seeing edit.php show up, I got some help on this and dont understand some of the logic to make this page in particular work.

 

viewrecord.php (shows records with delete and edit)

 

<? 
// Check if session is not registered , redirect back to main page. 
// Put this code in first line of web page. 
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
?>
<?php
//Get variables from config.php to connect to mysql server
require 'config.php';

// connect to the mysql database server.
$connect = mysql_connect($dbhost, $dbusername, $dbuserpass) or die("Unable to connect to SQL server..<br />".mysql_error());
$selectDB = mysql_select_db($dbname) or die("Unable to select database.<br />".mysql_error());

//trim whitespace from variable
$searchcode = preg_replace('/\s+/', ' ', trim($_GET['search']));

//seperate multiple keywords into array space delimited
$keywords = array_diff(explode(" ", $searchcode), array(""));

if( !empty($searchcode) ) {
foreach($keywords as $k => $v) 
$keywords[$k] = (int)$v;	
$codes = implode(",", $keywords);

$searchcode_query = "SELECT * FROM dealer WHERE areacode = '".$codes."'";

//Store the results in a variable or die if query fails
$result = mysql_query($searchcode_query) or die("Error executing MySQL query<br />".mysql_error());

$count = mysql_num_rows($result);
}

/** html code **/
echo "<center><h1>Admin View / Delete Dealer</h1><br><center><b>Other Admin Options Include: <a href=\"add_record.php\">add a record</a> | <a href=\"view_records.php\">view a record</a> | <a href=\"logout.php\">Log Out</a></b><br>
<br>Please put in an area code to filter your search and the proceed to delete or to come back to other admin options.</center><br></center>";

//If users doesn't enter anything into search box tell them to.
if( empty($searchcode) ){
echo "<html><head>";
echo "<title>Admin View / Delete Records</title>";
echo "</head>";
echo "<body onLoad=\"self.focus();document.searchform.search.focus()\">";
echo "<center>";
echo "<br /><form name=\"searchform\" method=\"GET\" action=\"view_records.php\">";
echo "<input type=\"text\" name=\"search\" size=\"20\" TABINDEX=\"1\" />";
echo " <input type=\"submit\" value=\"Search\" />";
echo "</form>";
} else {
if( $count == 0 ){
	echo "<center>Your query returned no results from the database, redirect.</center>";
} else {
	echo "<center><b>Admin - View Records for area code: ".$codes."</b></center><br>";
	$row_count = 0;

	// Define the colours for the alternating rows 
	$colour_odd = "#FDFDEA"; 
	$colour_even = "#E0E0C7"; 

	// If Remainder of $row_count divided by 2 == 0. 
	$row_color = (($row_count % 2) == 0) ? $colour_even : $colour_odd; 

	while( $row = mysql_fetch_array($result) ) {
		//table background color = row_color variable
		echo "<table width=\"550\" cellpadding=\"0\" cellspacing=\"2\">";
		echo "<tr>";
		echo "<td width=\"550\" valign=\"top\"><b>".$row['dealer']."</b><br>
		".$row['address']." ".$row['address2']."<br>
		".$row['city']." , ".$row['state'].", ".$row['zip']."<br>
		(".$row['areacode'].")-".$row['number']." or ".$row['tollnumber']."<br>
		Website: <a href=\"http://".$row['ulweb']."\">".$row['ulweb']."</a><br>
		Email: <a href=\"mailto:".$row['email']."\">".$row['email']."</a><br><br>
		<b>Dealer Information</b><br>".$row['dealerinfo']."<br>
		<br><a href=\"delete_record.php?id=".$row['id']."\">Delete</a> or <a href=\"edit.php?up=1&id=".$row['id']."\">Edit</a></td>";
		echo "</tr></table><hr>";
		$row_count++;
	}

}
}

if( isset($result) ) {
mysql_free_result($result);
mysql_close($connect);
}
?>

 

edit.php (will not display in browser, no php error just blank page

 

<?php   
//Get variables from config.php to connect to mysql server
require 'config.php';
$connect = mysql_connect($dbhost, $dbusername, $dbuserpass) or die("Unable to connect to SQL server..<br />".mysql_error());
$selectDB = mysql_select_db($dbname) or die("Unable to select database.<br />".mysql_error());
$codes = $_GET['id'];
if(isset($_REQUEST["id"]))
$nId=$_REQUEST["id"]; // will be requested.. from search page 
// you have selected the DATABASE now you can select the table and assign this on variable 
$sTable="my_table"; 
$sAction="Update";
// this is for update part 

if($_REQUEST['sAction']=="Update")
{
$query =    "UPDATE   
                            `dealer`   
                        SET  
                            `dealer` = " . mysql_real_escape_string ( $_POST [ 'dealer' ] ) . "  
                            `address` = " . mysql_real_escape_string ( $_POST [ 'address' ] ) . "  
                            `address2` = " . mysql_real_escape_string ( $_POST [ 'address2' ] ) . "  
						`city` = " . mysql_real_escape_string ( $_POST [ 'city' ] ) . "  
                            `state` = " . mysql_real_escape_string ( $_POST [ 'state' ] ) . "  
                            `zip` = " . mysql_real_escape_string ( $_POST [ 'zip' ] ) . " 
                            `areacode` = " . mysql_real_escape_string ( $_POST [ 'areacode' ] ) . "  
                            `number` = " . mysql_real_escape_string ( $_POST [ 'number' ] ) . "  
                            `tollnumber` = " . mysql_real_escape_string ( $_POST [ 'tollnumber' ] ) . "  
                            `ulweb` = " . mysql_real_escape_string ( $_POST [ 'ulweb' ] ) . "  
                            `email` = " . mysql_real_escape_string ( $_POST [ 'email' ] ) . "  
                            `dealerinfo` = " . mysql_real_escape_string ( $_POST [ 'dealerinfo' ] ) . "  

                        WHERE  
                            `ID` = " . mysql_real_escape_string ( $_REQUEST["id"] ); 

mysql_query($query)
echo "Entry updated successfully!";
}
// this value will be passed from the previous page and the text field will be filled with the corresponding ID 
if(isset($_REQUEST['up']) && isset($nId))
{
$sql="select * from ".$sTable." where id=".$_REQUEST['id'].""; // here id is the id column in the table
$result=mysql_query($sql);
if(mysql_num_rows($result)>0)
{
	$row=mysql_fetch_array($result);
	$dealer=$row['dealer'];
	$address=$row['address'];
	$address2=$row['address2'];
	$city=$row['city'];
	$state=$row['state'];
	$zip=$row['zip'];
	$areacode=$row['areacode'];
	$number=$row['number'];
	$tollnumber=$row['tollnumber'];
	$ulweb=$row['ulweb'];
	$email=$row['email'];
	$dealerinfo=$row['dealerinfo'];

	$sAction="Update";

}
}
// end 
  
?>   

<form id="update" name="update" method="post" action="<?=$_SERVER['PHP_SELF']?>"> 
<input type='hidden' name='id' value="<?=$nId?>">
<input type='hidden' name='sAction' value="<?=$sAction?>" >  

<table width="700" cellpadding="0" cellpsacing="0" border="1" bordercolor="#000000">
<tr>
	<td>
		<table width="700" cellpadding="0" cellpsacing="0" border="0" bordercolor="#000000">
			<tr>
				<td align="left" width="180">Dealer/ Distributor Name*</td>
				<td width="320" align="left"><input type="text" name="dealer" value="<?=$dealer?>" size="40"></td>
				<td align="left" width="200"></td>
			</tr>
			<tr>
				<td align="left" width="180">Street Address</td>
				<td width="320" align="left"><input type="text" name="address" value="<?=$address?>" size="40"></td>
				<td align="left" width="200"></td>
			</tr>
			<tr>
				<td align="left" width="180">Address 2</td>
				<td width="320" align="left"><input type="text" name="address2" value="<?=$address2?>" size="40"></td>
				<td align="left" width="200"></td>
			</tr>
			<tr>
				<td align="left" width="180">City*</td>
				<td width="320" align="left"><input type="text" name="city" value="<?=$city?>" size="30"></td>
				<td align="left" width="200"></td>
			</tr>
			<tr>
				<td align="left" width="180">State*</td>
				<td width="320" align="left"><input type="text" name="state" value="<?=$state?>" size="20"></td>
				<td align="left" width="200"></td>
			</tr>
			<tr>
				<td align="left" width="180">Zip*</td>
				<td width="320" align="left"><input type="text" name="zip" value="<?=$zip?>" size="10"></td>
				<td align="left" width="200">ex) 20100</td>
			</tr>
			<tr>
				<td align="left" width="180">Area Code*</td>
				<td width="320" align="left"><input type="text" name="areacode" value="<?=$areacode?>" size="10"></td>
				<td align="left" width="200">ex) 489</td>
			</tr>
			<tr>
				<td align="left" width="180">Local Number*</td>
				<td width="320" align="left"><input type="text" name="number" value="<?=$number?>" size="20"></td>
				<td align="left" width="200">ex) 123-4567</td>
			</tr>
			<tr>
				<td align="left" width="180">Toll Free Number</td>
				<td width="320" align="left"><input type="text" name="tollnumber" value="<?=$tollnumber?>" size="20"></td>
				<td align="left" width="200">ex) 1 800-123-4567</td>
			</tr>
			<tr>
				<td align="left" width="180">Website Address</td>
				<td width="320" align="left"><input type="text" name="ulweb" value="<?=$ulweb?>" size="40"></td>
				<td align="left" width="200">ex) www.google.com</td>
			</tr>
			<tr>
				<td align="left" width="180">Email Address</td>
				<td width="320" align="left"><input type="text" name="email" value="<?=$email?>" size="40"></td>
				<td align="left" width="200">(i.e. “Sales” or persons name)</td>
			</tr>
			<tr>
				<td align="left" width="180" valign="top">Dealer Information</td>
				<td width="320" align="left"><textarea name="dealerinfo" value="<?=$dealerinfo?>" cols="40" rows="6"></textarea></td>
				<td align="left" width="200"></td>
			</tr>
			<tr>
				<td colspan="3">
				<p align="center"><input type="submit" value="Update record"></p>
				</td>
			</tr>
		</table>

		</td></tr></table>
</form><br />* denotes a Required Field</center>

Link to comment
Share on other sites

thanks dennis for fixing one problem.

 

Now i see the html form but it is not passing in the unique data into the input fields where i put

<textarea name="dealerinfo" value="<?=$dealerinfo?>"  etc....

 

Maybe i am focusing on the wrong thing right now, but all i know is it is not passing in the data from the unique id being passed.

 

*Sidenote, the id structure is working because it's how my delete page works and it works just fine.

 

Thanks so far!

Link to comment
Share on other sites

Try changing this:

 

$row=mysql_fetch_array($result);
	$dealer=$row['dealer'];
	$address=$row['address'];
	$address2=$row['address2'];
	$city=$row['city'];
	$state=$row['state'];
	$zip=$row['zip'];
	$areacode=$row['areacode'];
	$number=$row['number'];
	$tollnumber=$row['tollnumber'];
	$ulweb=$row['ulweb'];
	$email=$row['email'];
	$dealerinfo=$row['dealerinfo'];

	$sAction="Update";

 

to this:

 

while($row=mysql_fetch_array($result))
{
	$dealer=$row['dealer'];
	$address=$row['address'];
	$address2=$row['address2'];
	$city=$row['city'];
	$state=$row['state'];
	$zip=$row['zip'];
	$areacode=$row['areacode'];
	$number=$row['number'];
	$tollnumber=$row['tollnumber'];
	$ulweb=$row['ulweb'];
	$email=$row['email'];
	$dealerinfo=$row['dealerinfo'];

	$sAction="Update";
}

 

try that and let me know how it goes

Link to comment
Share on other sites

Updated code, unfortunately it is still not passing the data into the fields  :-[ . any ideas, many thanks still! Also, could it be the while {  part, should i make the form inside php or does that not matter?

 

 

<?php   
//Get variables from config.php to connect to mysql server
require 'config.php';
$connect = mysql_connect($dbhost, $dbusername, $dbuserpass) or die("Unable to connect to SQL server..<br />".mysql_error());
$selectDB = mysql_select_db($dbname) or die("Unable to select database.<br />".mysql_error());
$codes = $_GET['id'];
if(isset($_REQUEST["id"]))
$nId=$_REQUEST["id"]; // will be requested.. from search page 
// you have selected the DATABASE now you can select the table and assign this on variable 
$sTable="my_table"; 
$sAction="Update";
// this is for update part 

if($_REQUEST['sAction']=="Update")
{
$query =    "UPDATE   
                            `dealer`   
                        SET  
                            `dealer` = " . mysql_real_escape_string ( $_POST [ 'dealer' ] ) . "  
                            `address` = " . mysql_real_escape_string ( $_POST [ 'address' ] ) . "  
                            `address2` = " . mysql_real_escape_string ( $_POST [ 'address2' ] ) . "  
						`city` = " . mysql_real_escape_string ( $_POST [ 'city' ] ) . "  
                            `state` = " . mysql_real_escape_string ( $_POST [ 'state' ] ) . "  
                            `zip` = " . mysql_real_escape_string ( $_POST [ 'zip' ] ) . " 
                            `areacode` = " . mysql_real_escape_string ( $_POST [ 'areacode' ] ) . "  
                            `number` = " . mysql_real_escape_string ( $_POST [ 'number' ] ) . "  
                            `tollnumber` = " . mysql_real_escape_string ( $_POST [ 'tollnumber' ] ) . "  
                            `ulweb` = " . mysql_real_escape_string ( $_POST [ 'ulweb' ] ) . "  
                            `email` = " . mysql_real_escape_string ( $_POST [ 'email' ] ) . "  
                            `dealerinfo` = " . mysql_real_escape_string ( $_POST [ 'dealerinfo' ] ) . "  

                        WHERE  
                            `ID` = " . mysql_real_escape_string ( $_REQUEST["id"] ); 

mysql_query($query);	

echo "Entry updated successfully!";
}
// this value will be passed from the previous page and the text field will be filled with the corresponding ID 
if(isset($_REQUEST['up']) && isset($nId))
{
$sql="select * from ".$sTable." where id=".$_REQUEST['id'].""; // here id is the id column in the table
$result=mysql_query($sql);
if(mysql_num_rows($result)>0)
{

while($row=mysql_fetch_array($result))
{
	$dealer=$row['dealer'];
	$address=$row['address'];
	$address2=$row['address2'];
	$city=$row['city'];
	$state=$row['state'];
	$zip=$row['zip'];
	$areacode=$row['areacode'];
	$number=$row['number'];
	$tollnumber=$row['tollnumber'];
	$ulweb=$row['ulweb'];
	$email=$row['email'];
	$dealerinfo=$row['dealerinfo'];

	$sAction="Update";
}
}
// end 
  
?>   

<form id="update" name="update" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> 
<input type='hidden' name='id' value="<?php echo $nId ?>">
<input type='hidden' name='sAction' value="<?php echo $sAction ?>" >  

<table width="700" cellpadding="0" cellpsacing="0" border="1" bordercolor="#000000">
<tr>
	<td>
		<table width="700" cellpadding="0" cellpsacing="0" border="0" bordercolor="#000000">
			<tr>
				<td align="left" width="180">Dealer/ Distributor Name*</td>
				<td width="320" align="left"><input type="text" name="dealer" value="<?php echo $dealer ?>" size="40"></td>
				<td align="left" width="200"></td>
			</tr>
			<tr>
				<td align="left" width="180">Street Address</td>
				<td width="320" align="left"><input type="text" name="address" value="<?php echo $address ?>" size="40"></td>
				<td align="left" width="200"></td>
			</tr>
			<tr>
				<td align="left" width="180">Address 2</td>
				<td width="320" align="left"><input type="text" name="address2" value="<?php echo $address2 ?>" size="40"></td>
				<td align="left" width="200"></td>
			</tr>
			<tr>
				<td align="left" width="180">City*</td>
				<td width="320" align="left"><input type="text" name="city" value="<?php echo $city ?>" size="30"></td>
				<td align="left" width="200"></td>
			</tr>
			<tr>
				<td align="left" width="180">State*</td>
				<td width="320" align="left"><input type="text" name="state" value="<?php echo $state ?>" size="20"></td>
				<td align="left" width="200"></td>
			</tr>
			<tr>
				<td align="left" width="180">Zip*</td>
				<td width="320" align="left"><input type="text" name="zip" value="<?php echo $zip ?>" size="10"></td>
				<td align="left" width="200">ex) 20100</td>
			</tr>
			<tr>
				<td align="left" width="180">Area Code*</td>
				<td width="320" align="left"><input type="text" name="areacode" value="<?php echo $areacode ?>" size="10"></td>
				<td align="left" width="200">ex) 489</td>
			</tr>
			<tr>
				<td align="left" width="180">Local Number*</td>
				<td width="320" align="left"><input type="text" name="number" value="<?php echo $number ?>" size="20"></td>
				<td align="left" width="200">ex) 123-4567</td>
			</tr>
			<tr>
				<td align="left" width="180">Toll Free Number</td>
				<td width="320" align="left"><input type="text" name="tollnumber" value="<?php echo $tollnumber ?>" size="20"></td>
				<td align="left" width="200">ex) 1 800-123-4567</td>
			</tr>
			<tr>
				<td align="left" width="180">Website Address</td>
				<td width="320" align="left"><input type="text" name="ulweb" value="<?php echo $ulweb ?>" size="40"></td>
				<td align="left" width="200">ex) www.google.com</td>
			</tr>
			<tr>
				<td align="left" width="180">Email Address</td>
				<td width="320" align="left"><input type="text" name="email" value="<?php echo $email ?>" size="40"></td>
				<td align="left" width="200">(i.e. “Sales” or persons name)</td>
			</tr>
			<tr>
				<td align="left" width="180" valign="top">Dealer Information</td>
				<td width="320" align="left"><textarea name="dealerinfo" value="<?php echo $dealerinfo ?>" cols="40" rows="6"></textarea></td>
				<td align="left" width="200"></td>
			</tr>
			<tr>
				<td colspan="3">
				<p align="center"><input type="submit" value="Update record"></p>
				</td>
			</tr>
		</table>

		</td></tr></table>
</form><br />* denotes a Required Field</center>
<?php } ?>

Link to comment
Share on other sites

took out echos, then added closing brackets and it did not work, then i modified the bracket placement just to get it to show form and that was not working, but right now i converted back to originally what you told me about putting } at the end. Any more ideas? No i did not say opinions that you hate me lol jk, thanks!

Link to comment
Share on other sites

echo's should remain

 

Here you set $sAction but as just a normal variable.  But then you check it with a $_REQUEST.

 

I dont see where your first form is setting sAction for the $_REQUEST to work.  Echo $_REQUEST['sAction'] right before your If statement, it's probably NULL.

 

$sAction="Update";

// this is for update part

 

if($_REQUEST['sAction']=="Update")

 

 

Link to comment
Share on other sites

I do not think i understand, are you telling me i need to change something or are you telling me that the code is looking for a null value...or..?

 

 

Also if anyone new gets this too, take a look and see if you guys can figure out why the data is not displaying.  Would it be easier if i post another topic and put current code in it? Thanks

 

echo's should remain

 

Here you set $sAction but as just a normal variable.  But then you check it with a $_REQUEST.

 

I dont see where your first form is setting sAction for the $_REQUEST to work.  Echo $_REQUEST['sAction'] right before your If statement, it's probably NULL.

 

$sAction="Update";

// this is for update part

 

if($_REQUEST['sAction']=="Update")

 

 

Link to comment
Share on other sites

Honestly that is one of the parts i was helped with by i believe xeon is his name on phpfreaks.

 

Although here is code on how the id passes the information to my delete.php page (has other stuff like db conn).

 

This page works very well and has no problem locating the information in say id=11 where as when i put the link in to show id=11 for edit.php it is not filling the data into the forms. I think my logic is bad...

 

//$codes = ((int)($_GET['id']));
$codes = $_GET['id'];
$searchcode_query = "SELECT * FROM dealer WHERE id = '".$codes."'";
$sql_delete_query = "DELETE FROM dealer WHERE id = '".$codes."'";

$result = mysql_query($searchcode_query) or die("Error executing MySQL SELECT query<br />".mysql_error());

if( mysql_affected_rows() != 1 ) 
{
  	 print "<center>No such dealer exists anymore<br><br>Please go back to <a href=\"add_record.php\">add a record</a> | <a href=\"view_records.php\">view a record</a></center>";
} 
else
{
	mysql_free_result($result);
    	$result = mysql_query($sql_delete_query) or die("Error executing MySQL DELETE query<br />".mysql_error());
   	 	echo "<center>Deleted record id = $codes<br><br>";
	echo "Please go back to <a href=\"add_record.php\">add a record</a> | <a href=\"view_records.php\">view a record</a></center>";
}

 

 

do i need to get rid of some stuff and do it like the delete except something like this (im way off but trying to figure out logic:

$searchcode_query = "SELECT * FROM dealer WHERE id = '".$codes."'";
$sql_delete_query = "UPDATE FROM dealer WHERE id = '".$codes."'";

 

 

Link to comment
Share on other sites

I tried this and took out alot of code, i am at the point where im just trying to manipulate code, however, i think i may have taken out some important elements let alone bad sql.... If anyone thinks that this may be easier to help me on by me sending them a .zip file i would be more than happy to send anyone it!!! Just let me know, i can also be contacted at randybennett23@hotmail.com  | sorry if it is against php freak rules to display a msn screen name, let me know if im not and ill edit post. Thanks!

 

NEW edit.php

<?php   
//Get variables from config.php to connect to mysql server
require 'config.php';
$connect = mysql_connect($dbhost, $dbusername, $dbuserpass) or die("Unable to connect to SQL server..<br />".mysql_error());
$selectDB = mysql_select_db($dbname) or die("Unable to select database.<br />".mysql_error());

//$codes = ((int)($_GET['id']));
$codes = $_GET['id'];
$searchcode_query = "SELECT * FROM dealer WHERE id = '".$codes."'";
$sql_delete_query = "UPDATE   
                            `dealer`   
                        SET  
                            `dealer` = " . mysql_real_escape_string ( $_POST [ 'dealer' ] ) . "  
                            `address` = " . mysql_real_escape_string ( $_POST [ 'address' ] ) . "  
                            `address2` = " . mysql_real_escape_string ( $_POST [ 'address2' ] ) . "  
						`city` = " . mysql_real_escape_string ( $_POST [ 'city' ] ) . "  
                            `state` = " . mysql_real_escape_string ( $_POST [ 'state' ] ) . "  
                            `zip` = " . mysql_real_escape_string ( $_POST [ 'zip' ] ) . " 
                            `areacode` = " . mysql_real_escape_string ( $_POST [ 'areacode' ] ) . "  
                            `number` = " . mysql_real_escape_string ( $_POST [ 'number' ] ) . "  
                            `tollnumber` = " . mysql_real_escape_string ( $_POST [ 'tollnumber' ] ) . "  
                            `ulweb` = " . mysql_real_escape_string ( $_POST [ 'ulweb' ] ) . "  
                            `email` = " . mysql_real_escape_string ( $_POST [ 'email' ] ) . "  
                            `dealerinfo` = " . mysql_real_escape_string ( $_POST [ 'dealerinfo' ] ) . "  

                        WHERE  
                            `id` = " .$codes." );



$result = mysql_query($searchcode_query) or die("Error executing MySQL SELECT query<br />".mysql_error());

if( mysql_affected_rows() != 1 ) 
{
  	 print "<center>No such dealer exists anymore<br><br>Please go back to <a href=\"add_record.php\">add a record</a> | <a href=\"view_records.php\">view a record</a></center>";
} 
else
{
	mysql_free_result($result);
    	$result = mysql_query($sql_delete_query) or die("Error executing MySQL Update query<br />".mysql_error());
   	 	echo "<center>Updated record id = $codes<br><br>";
	echo "Please go back to <a href=\"add_record.php\">add a record</a> | <a href=\"view_records.php\">view a record</a></center>";
}

?>
<form id="update" name="update" method="post" action="<?php $_SERVER['PHP_SELF'] ?>"> 
<input type='hidden' name='id' value="<?php echo $nId ?>">
<input type='hidden' name='sAction' value="<?php echo $sAction ?>" >  

<table width="700" cellpadding="0" cellpsacing="0" border="1" bordercolor="#000000">
<tr>
	<td>
		<table width="700" cellpadding="0" cellpsacing="0" border="0" bordercolor="#000000">
			<tr>
				<td align="left" width="180">Dealer/ Distributor Name*</td>
				<td width="320" align="left"><input type="text" name="dealer" value="<?php echo $dealer ?>" size="40"></td>
				<td align="left" width="200"></td>
			</tr>
			<tr>
				<td align="left" width="180">Street Address</td>
				<td width="320" align="left"><input type="text" name="address" value="<?php echo $address ?>" size="40"></td>
				<td align="left" width="200"></td>
			</tr>
			<tr>
				<td align="left" width="180">Address 2</td>
				<td width="320" align="left"><input type="text" name="address2" value="<?php echo $address2 ?>" size="40"></td>
				<td align="left" width="200"></td>
			</tr>
			<tr>
				<td align="left" width="180">City*</td>
				<td width="320" align="left"><input type="text" name="city" value="<?php echo $city ?>" size="30"></td>
				<td align="left" width="200"></td>
			</tr>
			<tr>
				<td align="left" width="180">State*</td>
				<td width="320" align="left"><input type="text" name="state" value="<?php echo $state ?>" size="20"></td>
				<td align="left" width="200"></td>
			</tr>
			<tr>
				<td align="left" width="180">Zip*</td>
				<td width="320" align="left"><input type="text" name="zip" value="<?php echo $zip ?>" size="10"></td>
				<td align="left" width="200">ex) 20100</td>
			</tr>
			<tr>
				<td align="left" width="180">Area Code*</td>
				<td width="320" align="left"><input type="text" name="areacode" value="<?php echo $areacode ?>" size="10"></td>
				<td align="left" width="200">ex) 489</td>
			</tr>
			<tr>
				<td align="left" width="180">Local Number*</td>
				<td width="320" align="left"><input type="text" name="number" value="<?php echo $number ?>" size="20"></td>
				<td align="left" width="200">ex) 123-4567</td>
			</tr>
			<tr>
				<td align="left" width="180">Toll Free Number</td>
				<td width="320" align="left"><input type="text" name="tollnumber" value="<?php echo $tollnumber ?>" size="20"></td>
				<td align="left" width="200">ex) 1 800-123-4567</td>
			</tr>
			<tr>
				<td align="left" width="180">Website Address</td>
				<td width="320" align="left"><input type="text" name="ulweb" value="<?php echo $ulweb ?>" size="40"></td>
				<td align="left" width="200">ex) www.google.com</td>
			</tr>
			<tr>
				<td align="left" width="180">Email Address</td>
				<td width="320" align="left"><input type="text" name="email" value="<?php echo $email ?>" size="40"></td>
				<td align="left" width="200">(i.e. “Sales” or persons name)</td>
			</tr>
			<tr>
				<td align="left" width="180" valign="top">Dealer Information</td>
				<td width="320" align="left"><textarea name="dealerinfo" value="<?php echo $dealerinfo ?>" cols="40" rows="6"></textarea></td>
				<td align="left" width="200"></td>
			</tr>
			<tr>
				<td colspan="3">
				<p align="center"><input type="submit" value="Update record"></p>
				</td>
			</tr>
		</table>

		</td></tr></table>
</form><br />* denotes a Required Field</center>
<?php } ?>

 

 

old.php

<?php   
//Get variables from config.php to connect to mysql server
require 'config.php';
$connect = mysql_connect($dbhost, $dbusername, $dbuserpass) or die("Unable to connect to SQL server..<br />".mysql_error());
$selectDB = mysql_select_db($dbname) or die("Unable to select database.<br />".mysql_error());

$codes = $_GET['id'];
if(isset($_REQUEST["id"]))

$nId=$_REQUEST["id"]; // will be requested.. from search page 
// you have selected the DATABASE now you can select the table and assign this on variable 
$sTable="my_table"; 
$sAction="Update";
// this is for update part 

if($_REQUEST['sAction']=="Update")
{
$query =    "UPDATE   
                            `dealer`   
                        SET  
                            `dealer` = " . mysql_real_escape_string ( $_POST [ 'dealer' ] ) . "  
                            `address` = " . mysql_real_escape_string ( $_POST [ 'address' ] ) . "  
                            `address2` = " . mysql_real_escape_string ( $_POST [ 'address2' ] ) . "  
						`city` = " . mysql_real_escape_string ( $_POST [ 'city' ] ) . "  
                            `state` = " . mysql_real_escape_string ( $_POST [ 'state' ] ) . "  
                            `zip` = " . mysql_real_escape_string ( $_POST [ 'zip' ] ) . " 
                            `areacode` = " . mysql_real_escape_string ( $_POST [ 'areacode' ] ) . "  
                            `number` = " . mysql_real_escape_string ( $_POST [ 'number' ] ) . "  
                            `tollnumber` = " . mysql_real_escape_string ( $_POST [ 'tollnumber' ] ) . "  
                            `ulweb` = " . mysql_real_escape_string ( $_POST [ 'ulweb' ] ) . "  
                            `email` = " . mysql_real_escape_string ( $_POST [ 'email' ] ) . "  
                            `dealerinfo` = " . mysql_real_escape_string ( $_POST [ 'dealerinfo' ] ) . "  

                        WHERE  
                            `ID` = " . mysql_real_escape_string ( $_REQUEST["id"] ); 

mysql_query($query);	

echo "Entry updated successfully!";
}
// this value will be passed from the previous page and the text field will be filled with the corresponding ID 
if(isset($_REQUEST['up']) && isset($nId))
{
$sql="select * from ".$sTable." where id=".$_REQUEST['id'].""; // here id is the id column in the table
$result=mysql_query($sql);
if(mysql_num_rows($result)>0)
{

while($row=mysql_fetch_array($result))
{
	$dealer=$row['dealer'];
	$address=$row['address'];
	$address2=$row['address2'];
	$city=$row['city'];
	$state=$row['state'];
	$zip=$row['zip'];
	$areacode=$row['areacode'];
	$number=$row['number'];
	$tollnumber=$row['tollnumber'];
	$ulweb=$row['ulweb'];
	$email=$row['email'];
	$dealerinfo=$row['dealerinfo'];

	$sAction="Update";
}
}
// end 
  
?>   

<form id="update" name="update" method="post" action="<?php $_SERVER['PHP_SELF'] ?>"> 
<input type='hidden' name='id' value="<?php echo $nId ?>">
<input type='hidden' name='sAction' value="<?php echo $sAction ?>" >  

<table width="700" cellpadding="0" cellpsacing="0" border="1" bordercolor="#000000">
<tr>
	<td>
		<table width="700" cellpadding="0" cellpsacing="0" border="0" bordercolor="#000000">
			<tr>
				<td align="left" width="180">Dealer/ Distributor Name*</td>
				<td width="320" align="left"><input type="text" name="dealer" value="<?php echo $dealer ?>" size="40"></td>
				<td align="left" width="200"></td>
			</tr>
			<tr>
				<td align="left" width="180">Street Address</td>
				<td width="320" align="left"><input type="text" name="address" value="<?php echo $address ?>" size="40"></td>
				<td align="left" width="200"></td>
			</tr>
			<tr>
				<td align="left" width="180">Address 2</td>
				<td width="320" align="left"><input type="text" name="address2" value="<?php echo $address2 ?>" size="40"></td>
				<td align="left" width="200"></td>
			</tr>
			<tr>
				<td align="left" width="180">City*</td>
				<td width="320" align="left"><input type="text" name="city" value="<?php echo $city ?>" size="30"></td>
				<td align="left" width="200"></td>
			</tr>
			<tr>
				<td align="left" width="180">State*</td>
				<td width="320" align="left"><input type="text" name="state" value="<?php echo $state ?>" size="20"></td>
				<td align="left" width="200"></td>
			</tr>
			<tr>
				<td align="left" width="180">Zip*</td>
				<td width="320" align="left"><input type="text" name="zip" value="<?php echo $zip ?>" size="10"></td>
				<td align="left" width="200">ex) 20100</td>
			</tr>
			<tr>
				<td align="left" width="180">Area Code*</td>
				<td width="320" align="left"><input type="text" name="areacode" value="<?php echo $areacode ?>" size="10"></td>
				<td align="left" width="200">ex) 489</td>
			</tr>
			<tr>
				<td align="left" width="180">Local Number*</td>
				<td width="320" align="left"><input type="text" name="number" value="<?php echo $number ?>" size="20"></td>
				<td align="left" width="200">ex) 123-4567</td>
			</tr>
			<tr>
				<td align="left" width="180">Toll Free Number</td>
				<td width="320" align="left"><input type="text" name="tollnumber" value="<?php echo $tollnumber ?>" size="20"></td>
				<td align="left" width="200">ex) 1 800-123-4567</td>
			</tr>
			<tr>
				<td align="left" width="180">Website Address</td>
				<td width="320" align="left"><input type="text" name="ulweb" value="<?php echo $ulweb ?>" size="40"></td>
				<td align="left" width="200">ex) www.google.com</td>
			</tr>
			<tr>
				<td align="left" width="180">Email Address</td>
				<td width="320" align="left"><input type="text" name="email" value="<?php echo $email ?>" size="40"></td>
				<td align="left" width="200">(i.e. “Sales” or persons name)</td>
			</tr>
			<tr>
				<td align="left" width="180" valign="top">Dealer Information</td>
				<td width="320" align="left"><textarea name="dealerinfo" value="<?php echo $dealerinfo ?>" cols="40" rows="6"></textarea></td>
				<td align="left" width="200"></td>
			</tr>
			<tr>
				<td colspan="3">
				<p align="center"><input type="submit" value="Update record"></p>
				</td>
			</tr>
		</table>

		</td></tr></table>
</form><br />* denotes a Required Field</center>
<?php } ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.