/    Sign up×
Community /Pin to ProfileBookmark

showing values on a update form

i have this code to update the database when the user type in his user name and password
it takes them to the members page and them they click on update links that takes them to the update form, the problem is that the form is not displaying the values so whatever i write will replace the old text in the database

[code=php]

<?php
$host = “localhost”;
$username = “townsfin_localho”;
$password = “abc123”;
$database = “townsfin_contacts”;

$db = mysql_connect($host, $username, $password) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());

$BusinessName = (isset($_POST[‘BusinessName’]) ? $_POST[‘BusinessName’] : ”);
$Slogan = (isset($_POST[‘Slogan’]) ? $_POST[‘Slogan’]:”);
$Business_Address = (isset($_POST[‘Business_Address’]) ? $_POST[‘Business_Address’]:”);
$Tel = (isset($_POST[‘Tel’]) ? $_POST[‘Tel’]:”);
$Website = (isset($_POST[‘Website’]) ? $_POST[‘Website’]:”);
$Email = (isset($_POST[‘Email’]) ? $_POST[‘Email’]:”);
$Member_Status = (isset($_POST[‘Member_Status’]) ? $_POST[‘Member_Status’]:”);
$Fax =(isset($_POST[‘Fax’]) ? $_POST[‘Fax’]:”);
$type = (isset($_POST[‘type’]) ? $_POST[‘type’]:”);
$make = (isset($_POST[‘make’]) ? $_POST[‘make’]:”);
$Categories = (isset($_POST[‘Categories’]) ? $_POST[‘Categories’]:”);
$Keyword = (isset($_POST[‘Keyword’]) ? $_POST[‘Keyword’]:”);
$Picture1 = (isset($_POST[‘Picture1’]) ? $_POST[‘Picture1’]:”);
$Headline = (isset($_POST[‘Headline’]) ? $_POST[‘Headline’]:”);
$Slogan2 = (isset($_POST[‘Slogan2’]) ? $_POST[‘Slogan2’]:”);
$Description1 = (isset($_POST[‘Description1’]) ? $_POST[‘Description1’]:”);
$Description2 = (isset($_POST[‘Description2’]) ? $_POST[‘Description2’]:”);
$Description3= (isset($_POST[‘Description3’]) ? $_POST[‘Description3’]:”);
$Contact2 = (isset($_POST[‘Contact2’]) ? $_POST[‘Contact2’]:”);
$Picture2 = (isset($_POST[‘Picture2’]) ? $_POST[‘Picture2’]:”);
$Picture3 = (isset($_POST[‘Picture3’]) ? $_POST[‘Picture3’]:”);
$Picture4 = (isset($_POST[‘Picture4’]) ? $_POST[‘Picture4’]:”);
$User_Name = (isset($_POST[‘User_Name’]) ? $_POST[‘User_Name’]:”);
$Password = (isset($_POST[‘Password’]) ? $_POST[‘Password’]: ”);

$query = “SELECT * FROM business_info WHERE `BusinessName`= ‘$BusinessName’
AND `User_Name`=’$User_Name'”;

$result = mysql_query($query) or die (mysql_error());
$res2 = mysql_fetch_assoc($result);

echo “$BusinessName”;

if(isset($_GET[‘update’]))
{

$query=”UPDATE business_info SET `BusinessName`= ‘{$BusinessName}’, `Slogan`='{$Slogan}’,
`Business_Address`='{$Business_Address}’, `Tel`='{$Tel}’, `Website`='{$Website}’,
`Email`='{$Email}’, `Fax`='{$Fax}’, `type`='{$type}’,
`make`='{$make}’, `Categories`='{$Categories}’, `Keyword`='{$Keyword}’, `Picture1`='{$Picture1}’,
`Headline`='{$Headline}’, `Slogan2`='{$Slogan2}’, `Description1`='{$Description1}’,
`Description2`='{$Description2}’, `Description3`= ‘{$Description3}’,
`Picture2`='{$Picture2}’, `Picture3`='{$Picture3}’,
`Password`='{$Password}’ WHERE `User_Name`='{$User_Name}'”;

$result = mysql_query($query) or die (mysql_error());
}

?>

<table width=”83%” border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td bordercolor=”#FFFFFF” bgcolor=”#FFFFFF”><div align=”left”><br>
<table width=”96%” border=”0″ cellpadding=”0″ cellspacing=”0″ bgcolor=”#FFFFFF”>
<tr>

<td width=”91%”>
<?

include(“../includefiles/logo.php”);
?>
</td>
</tr>
</table>
</div></td>
</tr>
<tr>
<td><div align=”center”></div></td>
</tr>
<tr>
<td><table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>

<td width=”94%”>

<table width=”100%” border=”0″ cellpadding=”0″ cellspacing=”0″ background=”../images/top_center_back2.jpg” bgcolor=”#FFFFFF”>
<tr>
<td>
<table width=”100%” height=”125″ border=”0″ cellpadding=”1″ cellspacing=”1″>
<form name=”form” method=”Post” action=”” >
<tr>
<td background=”../images/fondo2.jpg” bgcolor=”#999966″><div align=”center”><strong>Business Info</strong></div></td>
</tr>
<tr>
<td><table width=”100%” border=”0″ cellspacing=”1″ cellpadding=”1″>
<tr>
<td width=”17%”>Business Name</td>
<td width=”22%”><input type=”text” name=”BusinessName” Value=”<? echo “$BusinessName”; ?>” > </td>

</tr>
<tr>
<td>Slogan</td>
<td><input type=”text” name=”Slogan” value=”<?php echo”$Slogan”; ?>”></td>
<td>Website</td>
<td><input type=”text” name=”Website ” value=”<?php echo “$Website”; ?>”></td>
</tr>
<tr>
<td>Tel</td>
<td><input type=”text” name=”Tel” value=”<?php echo “$Tel”; ?>”></td>
<td>Key Words</td>
<td><input type=”text” name=”Keyword value=”<?php echo “$Keyword”; ?>”> </td>
</tr>
<tr>
<td>Fax</td>
<td><input type=”text” name=”Fax” value=”<?php echo “$Fax”; ?>”> </td>
<td>Address</td>
<td><input type=”text” name=”Business_Address” value=”<?php ?> “> </td>
</tr>
</table></td>
</tr>
<tr>
<td>

<table width=”101%” height=”35″ border=”0″ cellpadding=”0″ cellspacing=”0″>
<tr>
<td width=”13%”>State</td>
<td width=”7%”> <select name=”make” style=”width:160px;”></td>

<td width=”16%”>City</td>
<td width=”8%”><select name=”type” style=”width:160px;”>
</select>

</td>
<td width=”9%”>Category</td>
<td width=”16%”> <TEXTAREA rows=3 name=”Categories” value=”<?php echo “$Categories”;?>”> </TEXTAREA> </td>

</tr>
</table><br>
<table width=”100%” border=”0″ cellspacing=”1″ cellpadding=”1″>
<tr>
<td background=”../images/fondo2.jpg” bgcolor=”#CCCCCC”><div align=”center”><strong><font color=”#000000″>Business
Webpage</font></strong></div></td>
</tr>
<tr>
<td>Headline</td>
</tr>
<tr>
<td><input type=”text” name=”Headline” value=”<?php echo “$Headline”; ?>”> </td>
</tr>
<tr>
<td>Slogan </td>
</tr>
<tr>
<td><input type=”text” name=”Slogan2″ value=”<?php echo “$Slogan2″; ?>” ></td>
</tr>
<tr>
<td>Description1 </td>
</tr>
<tr>
<td><TEXTAREA ROWS=5 COLS=65 NAME=”Description1″ value=”<?php echo” $Description1″; ?>” > </TEXTAREA></td>
</tr>
<tr>
<td>Description2</td>
</tr>
<tr>
<td><TEXTAREA ROWS=5 COLS=65 NAME=”Description2″ value=”<?php echo “$Description2″; ?>”></TEXTAREA></td>
</tr>
<tr>
<td>Description3</td>
</tr>
<tr>
<td><TEXTAREA ROWS=5 COLS=65 NAME=”Description3″ value=”<?php echo “$Description3” ?> “></TEXTAREA></td>
</tr>
<tr>
<td>Contact Name
<TEXTAREA ROWS=1 COLS=25 NAME=”Contact2″ value=”<?php echo “$Contact2″; ?>”> </TEXTAREA></td>
</tr>
<tr>
<td>

[/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@Phill_PaffordJan 27.2007 — ? Please explain more, give errors if any.
Copy linkTweet thisAlerts:
@franknuauthorJan 27.2007 — ok, i am not getting any error, it is just that the data from the database it is not being display so when the user update the data it gets replace by the new one. i want the data that is already in the database to show in the value space so it doesn't get replace
Copy linkTweet thisAlerts:
@NightShift58Jan 27.2007 — The code that you posted contains a form that isn't closed and not submit button.

Also prior to replacing, you're asking for some GET information although you're dealing primarily with POST. Is that right?

On which form is the ata supposed to be displayed for updating? On the one you posted?
Copy linkTweet thisAlerts:
@franknuauthorJan 27.2007 — ok, that is the form to update the database wich is running with the scripts it is just too long and i shorten it. and the only problem that i am having is that it is not showing the data
Copy linkTweet thisAlerts:
@NightShift58Jan 27.2007 — I did my best... I'm not sure where some of the variables are coming when the user first displays the page. You'll have to double-check that one...[code=php]<?php
$host = "localhost";
$username = "townsfin_localho";
$password = "abc123";
$database = "townsfin_contacts";


$db = mysql_connect($host, $username, $password) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());

$BusinessName = (isset($_POST['BusinessName']) ? $_POST['BusinessName'] :'');
$Slogan = (isset($_POST['Slogan']) ? $_POST['Slogan'] :'');
$Business_Address = (isset($_POST['Business_Address']) ? $_POST['Business_Address'] :'');
$Tel = (isset($_POST['Tel']) ? $_POST['Tel'] :'');
$Website = (isset($_POST['Website']) ? $_POST['Website'] :'');
$Email = (isset($_POST['Email']) ? $_POST['Email'] :'');
$Member_Status = (isset($_POST['Member_Status']) ? $_POST['Member_Status'] :'');
$Fax = (isset($_POST['Fax']) ? $_POST['Fax'] :'');
$type = (isset($_POST['type']) ? $_POST['type'] :'');
$make = (isset($_POST['make']) ? $_POST['make'] :'');
$Categories = (isset($_POST['Categories']) ? $_POST['Categories'] :'');
$Keyword = (isset($_POST['Keyword']) ? $_POST['Keyword'] :'');
$Picture1 = (isset($_POST['Picture1']) ? $_POST['Picture1'] :'');
$Headline = (isset($_POST['Headline']) ? $_POST['Headline'] :'');
$Slogan2 = (isset($_POST['Slogan2']) ? $_POST['Slogan2'] :'');
$Description1 = (isset($_POST['Description1']) ? $_POST['Description1'] :'');
$Description2 = (isset($_POST['Description2']) ? $_POST['Description2'] :'');
$Description3 = (isset($_POST['Description3']) ? $_POST['Description3'] :'');
$Contact2 = (isset($_POST['Contact2']) ? $_POST['Contact2'] :'');
$Picture2 = (isset($_POST['Picture2']) ? $_POST['Picture2'] :'');
$Picture3 = (isset($_POST['Picture3']) ? $_POST['Picture3'] :'');
$Picture4 = (isset($_POST['Picture4']) ? $_POST['Picture4'] :'');
$User_Name = (isset($_POST['User_Name']) ? $_POST['User_Name'] :'');
$Password = (isset($_POST['Password']) ? $_POST['Password'] :'');

// IF we are coming here from a a form where the user has modified data
IF (isset($_POST['BusinessName']) :

$query = "UPDATE business_info ";
$query .= " SET BusinessName = '" . mysql_real_escape_string($BusinessName) . "', ";
$query .= " Slogan = '" . mysql_real_escape_string($Slogan) . "', ";
$query .= " Business_Address = '" . mysql_real_escape_string($Business_Address) . "', ";
$query .= " Tel = '" . mysql_real_escape_string($Tel) . "', ";
$query .= " Website = '" . mysql_real_escape_string($Website) . "', ";
$query .= " Email = '" . mysql_real_escape_string($Email) . "', ";
$query .= " Fax = '" . mysql_real_escape_string($Fax) . "', ";
$query .= " type = '" . mysql_real_escape_string($type) . "', ";
$query .= " make = '" . mysql_real_escape_string($make) . "', ";
$query .= " Categories = '" . mysql_real_escape_string($Categories) . "', ";
$query .= " Keyword = '" . mysql_real_escape_string($Keyword) . "', ";
$query .= " Picture1 = '" . mysql_real_escape_string($Picture1) . "', ";
$query .= " Headline = '" . mysql_real_escape_string($Headline) . "', ";
$query .= " Slogan2 = '" . mysql_real_escape_string($Slogan2) . "', ";
$query .= " Description1 = '" . mysql_real_escape_string($Description1) . "', ";
$query .= " Description2 = '" . mysql_real_escape_string($Description2) . "', ";
$query .= " Description3 = '" . mysql_real_escape_string($Description3) . "', ";
$query .= " Picture2 = '" . mysql_real_escape_string($Picture2) . "', ";
$query .= " Picture3 = '" . mysql_real_escape_string($Picture3) . "', ";
$query .= " Password = '" . mysql_real_escape_string($Password) . "' ";
$query .= " WHERE User_Name='" . mysql_real_escape_string($User_Name) . "'";
$query .= " LIMIT 1 ";

$result = mysql_query($query) or die ("SQL Error: $query<br>" . mysql_error());

ENDIF;

////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
//
// Here we have problem: Are "$BusinessName" and "$User_Name", GET, POST or SESSION variable?
//
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
$query = "SELECT * FROM business_info ";
$query .= "WHERE BusinessName = '" . mysql_real_escape_string($BusinessName) . "' ";
$query .= " AND User_Name = '" . mysql_real_escape_string($User_Name) . "' ";

$result = mysql_query($query) or die (mysql_error());
$res2 = mysql_fetch_assoc($result);

FOREACH ($res as $key => $value) :
$$key = value;
ENDFOREACH;

echo "$BusinessName";
?>
<table width="83%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bordercolor="#FFFFFF" bgcolor="#FFFFFF"><div align="left"><br>
<table width="96%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td width="91%">
<? include("../includefiles/logo.php"); ?>
</td>
</tr>
</table>
</div></td>
</tr>
<tr><td><div align="center"></div></td></tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="94%">
<table width="100%" border="0" cellpadding="0" cellspacing="0" background="../images/top_center_back2.jpg" bgcolor="#FFFFFF">
<tr>
<td>
<table width="100%" height="125" border="0" cellpadding="1" cellspacing="1">
<form name="form" method="Post" action="" >
<tr>
<td background="../images/fondo2.jpg" bgcolor="#999966"><div align="center"><strong>Business Info</strong></div></td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td width="17%">Business Name</td>
<td width="22%"><input type="text" name="BusinessName" Value="<? echo $BusinessName; ?>" > </td>
</tr>
<tr>
<td>Slogan</td>
<td><input type="text" name="Slogan" value="<?php echo $Slogan; ?>"></td>
<td>Website</td>
<td><input type="text" name="Website " value="<?php echo $Website; ?>"></td>
</tr>
<tr>
<td>Tel</td>
<td><input type="text" name="Tel" value="<?php echo $Tel; ?>"></td>
<td>Key Words</td>
<td><input type="text" name="Keyword value="<?php echo $Keyword; ?>"> </td>
</tr>
<tr>
<td>Fax</td>
<td><input type="text" name="Fax" value="<?php echo $Fax; ?>"> </td>
<td>Address</td>
<td><input type="text" name="Business_Address" value="<?php echo $Business_Address; ?>"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width="101%" height="35" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="13%">State</td>
<td width="7%"> <select name="make" style="width:160px;"></td>
<td width="16%">City</td>
<td width="8%"><select name="type" style="width:160px;"></select></td>
<td width="9%">Category</td>
<td width="16%"> <TEXTAREA rows=3 name="Categories" value="<?php echo $Categories; ?>"> </TEXTAREA> </td>
</tr>
</table><br>

<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr><td background="../images/fondo2.jpg" bgcolor="#CCCCCC">
<div align="center"><strong><font color="#000000">Business Webpage</font></strong></div>
</td></tr>
<tr><td>Headline</td></tr>
<tr><td><input type="text" name="Headline" value="<?php echo $Headline; ?>"> </td></tr>
<tr><td>Slogan </td></tr>
<tr><td><input type="text" name="Slogan2" value="<?php echo $Slogan2; ?>" ></td></tr>
<tr><td>Description1 </td></tr>
<tr><td><TEXTAREA ROWS=5 COLS=65 NAME="Description1" value="<?php echo $Description1; ?>" > </TEXTAREA></td></tr>
<tr><td>Description2</td></tr>
<tr><td><TEXTAREA ROWS=5 COLS=65 NAME="Description2" value="<?php echo $Description2; ?>"></TEXTAREA></td></tr>
<tr><td>Description3</td></tr>
<tr><td><TEXTAREA ROWS=5 COLS=65 NAME="Description3" value="<?php echo $Description3 ?> "></TEXTAREA></td></tr>
<tr><td>Contact Name</tr>
<tr><TEXTAREA ROWS=1 COLS=25 NAME="Contact2" value="<?php echo $Contact2; ?>"> </TEXTAREA></td></tr>
<tr><td>
[/code]
×

Success!

Help @franknu spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...