ok code gets ugly at the end but its work in progress.
anyways.. i think the way im trying to update a table isnt working ..ie wrong sytax or something
any suggestions?
<?
// TO DO
print("<pre>");
print_r($_REQUEST);
print("</pre>");
$dbcnx = @mysql_connect("*****************");
if (!$dbcnx)
{
print("unable to connect to database");
exit();
}
else
{
mysql_select_db("onstage");
}
// start read cookie
if ($_COOKIE['loggedin'])
{
if ($foo != "bar") // this means if the form is submitted it wont check up the database again
{
$id = $_COOKIE['id'];
// gets client information based on id from the client database
$sql = "SELECT * FROM clientdb where clientid = '$id'";
$result=mysql_query($sql)
or die(mysql_error());
while($row=mysql_fetch_array($result))
{
$fname = ($row['fname']);
$lname = ($row['lname']);
$phone = ($row['phone']);
$email = ($row['email']);
$street = ($row['street']);
$city = ($row['city']);
$state = ($row['state']);
$postcode = ($row['postcode']);
$country = ($row['country']);
} // end of if foo bar
//check for errors
if ($showerror == "error")
{
// check input is correct
if (!preg_match("/^[a-z ]+$/i", $_REQUEST["fname"]))
{
print("<font color=\"red\" align=\"center\">First Name missing</font>");
}
else if (!preg_match("/^[a-z ]+$/i", $_REQUEST["lname"]))
{
print("<font color=\"red\">Last Name Missing</font>");
}
else if (!preg_match("/^[0-9\ ]+[0-9\ ]$/", $_REQUEST["phone"]))
{
Print("<font color=\"red\">Invalid Phone Number</font>");
}
else if (!preg_match("/^[a-z0-9\_\.\-]{2,}\@[a-z0-9\-]{2,}(\.[a-z0-9\-]{2,})+$/i", $_REQUEST["email"]))
{
Print("<font color=\"red\">Invalid Email Address</font>");
}
else if (!$_REQUEST['street'])
{
Print("<font color=\"red\">Please Enter Your Street Address</i></font>");
}
else if (!preg_match("/^[a-z0-9\ ]+[a-z0-9\ ]+[a-z0-9\ ]+[a-z0-9\ ]+$/i", $_REQUEST["city"]))
{
Print("<font color=\"red\">Please Enter Your City</font>");
}
else if (!preg_match("/^[a-z]+$/i", $_REQUEST["state"]))
{
Print("<font color=\"red\">Please Enter Your State</font>");
}
else if (!preg_match("/^[0-9]+$/", $_REQUEST["postcode"]))
{
Print("<font color=\"red\">Please Enter Postcode</font>");
}
else if (!preg_match("/^[a-z]+$/i", $_REQUEST["country"]))
{
Print("<font color=\"red\">Please Enter Your Country</font>");
}
else
{
$foo = "bar"; // means form has been submitted once
//update the tables
$fname = $_REQUEST['fname'];
$lname = $_REQUEST['lname'];
$phone = $_REQUEST['phone'];
$email = $_REQUEST['email'];
$street = $_REQUEST['street'];
$city = $_REQUEST['city'];
$stte = $_REQUEST['state'];
$postcode = $_REQUEST['postcode'];
$country = $_REQUEST['country'];
$sql = "UPDATE clientdb SET fname='$fname', lname ='$lname', phone = '$phone' , email = '$email' , street = '$street' , city = '$city' , state = '$state' , postcode = '$postcode' , country = '$country' where clientid = '$clientid'";
$result = mysql_query($sql)
or die (mysql_error());
$fullname = ($fname." ".$lname);
$sql = "UPDATE Control SET name='$fullname', email = '$email' where clientid = '$clientid'";
$result = mysql_query($sql)
or die (mysql_error());
print("<tr><td colspan=\"3\" align=\"center\"><b><font color=\"red\">Data successfully Updated</b></font></td></tr>");
}
}
?>
<table cellpadding="10" cellspacing="0" border="1" VALIGN="TOP">
<tr class="cellbg">
<td>
<form name="update" action="clientupdate.php" method="post">
<input type="hidden" name="showerror" value="error">
<table class="tcellbg" width="100%" height="100%" cellpadding="0" cellpadding="4" align="center" valign="top">
<tr>
<td colspan="2" align="center"><h1>Update Details</h1></td>
</tr>
<tr>
<td align="right">First Name : </td>
<td align="left"><input type="text" name="fname" size="20" value="<?=$fname?>"></td>
</tr>
<tr>
<td align="right">Last Name : </td>
<td align="left"><input type="text" name="lname" value="<?=$lname?>" size="20"></td>
</tr>
<tr>
<td align="right">Phone Number : </td>
<td align="left"><input type="text" name="phone" size="20" value="<?=$phone?>"></td>
</tr>
<tr>
<td align="right">Email Address : </td>
<td align="left"><input type="text" name="email" size="30" value="<?=$email?>"></td>
</tr>
<tr>
<td align="right">Street Number / Name : </td>
<td align="left"><input type="text" name="street" size="30" value="<?=$street?>"></td>
</tr>
<tr>
<td align="right">City : </td>
<td align="left"><input type="text" name="city" size="20" value="<?=$city?>"></td>
</tr>
<tr>
<td align="right">State: </td>
<td align="left"><input type="text" name="state" size="20" value="<?=$state?>"></td>
</tr>
<tr>
<td align="right">Post Code: </td>
<td align="left"><input type="text" name="postcode" size="5" value="<?=$postcode?>"></td>
</tr>
<tr>
<td align="right">Country: </td>
<td align="left"><input type="text" name="country" size="20" value="<?=$country?>"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Update"></td>
</tr>
<?
}
}
else // if no cookies set
{
Print("Sorry you are not logged in <a href=\"login.php\">click here</a> to login");
}
?>