PHP Code:
<?php
$query="UPDATE table1 SET `contact_email` = '".$formVars["contact_email"]."', `contact_phone` = '".$formVars["contact_phone"]."', `city` = '".$formVars["city"]."', `title`= '".$formVars["title"]."', `brief_des` = '".$formVars["brief_des"]."', `comments` = '".$formVars["comments"]."', `price` = '".$formVars["price"]."' WHERE `id` = '".$formVars["id"]."' LIMIT 1";
?>
LIMIT 1 used because id is unique, isn't it? If not, delete it... Don't use
" for all cases, those backslashes look really ugly - better use " and '.
Also, you should put the code after
foreach in { and }, like that (it's increasing code readibility):
PHP Code:
<?
foreach($HTTP_POST_VARS as $varname => $value)
{
$formVars[$varname]=$value;
}
?>
mysql_connect doesn't really take $DBName parameter, you're selecting DB in your next line, with mysql_select_db...
PHP Code:
<?
foreach($HTTP_POST_VARS as $varname => $value)
{
$formVars[$varname]=$value;
}
// require_once("mydatabaseconnection"); <-- And that line is for what?
$db1=mysql_connect($Host, $User, $Pass);
mysql_select_db("mydatabase");
$query="UPDATE table1 SET `contact_email` = '".$formVars["contact_email"]."', `contact_phone` = '".$formVars["contact_phone"]."', `city` = '".$formVars["city"]."', `title`= '".$formVars["title"]."', `brief_des` = '".$formVars["brief_des"]."', `comments` = '".$formVars["comments"]."', `price` = '".$formVars["price"]."' WHERE `id` = '".$formVars["id"]."' LIMIT 1";
mysql_query($query);
mysql_close($db1);
?>
If you're debuging it, I'd first comment out all the DB connection and print $formVars array - if it's set properly, then it's your DB connection that is the problem. Check the query (echo it) after passing values with foreach...
At last, use DB layer to make the connection and working with MySQL easier.