by solarblitz » Fri May 04, 2012 11:56 am
Hey I'm relatively new to php and mysql, and teaching myself.
I have the following scripts:- The main Form page
<?php
session_start();
// Must have first line of page
?>
<!DOCTYPE HTML>
<html>
<?php include('../includes/mysqlconnection.php');
$becompany = $_SESSION['becompany'];
$customerid = $_SESSION['customerid'];
$data = mysql_query ("SELECT * FROM customer WHERE customerid ='$customerid'");
//$page = mysql_query("SELECT * FROM pages WHERE siteid = $siteid");
$info = mysql_fetch_array( $data ); ?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php echo '<title> Welcome to '.$becompany.'s - ************ C.M.S.</title>';?>
<meta name="description" content="CMS for ********.co.uk - Web Design Firm"/>
<meta name="author" content="**********" />
<meta charset="UTF-8" />
<link rel="stylesheet" href="../css/site.css" type="text/css">
<link rel="shortcut icon" href="images/favicon.ico" >
</head>
<body>
<div id="wrap">
<header id="page_header">
<nav></nav>
</header>
<div id="sectop"></div>
<section id="controlpanel">
<p>Below is your Customer Details - Some of these you can change and some you will need to send an email to request a change. </p>
<?php echo $info['name'];?>
<table>
<form method="post" action="">
<input type="hidden" name="id" value="<? echo "$info[$customerid]"?>">
<tr>
<td>Name</td>
<td>
<input type="text" name="name"
size="20" value="<? echo "$info[name]"?>">
</td>
</tr>
<tr>
<td>Address</td>
<td>
<input type="text" name="address1" size="40"
value="<? echo "$info[address1]"?>">
</td>
</tr>
<tr>
<td></td>
<td>
<input type="text" name="address2" size="40"
value="<? echo "$info[address2]"?>">
</td>
</tr>
<tr>
<td></td>
<td>
<input type="text" name="address3" size="40"
value="<? echo "$info[address3]"?>">
</td>
</tr>
<tr>
<td>Town</td>
<td>
<input type="text" name="town" size="40"
value="<? echo "$info[town]"?>">
</td>
</tr>
<tr>
<td>County</td>
<td>
<input type="text" name="county" size="40"
value="<? echo "$info[county]"?>">
</td>
</tr>
<tr>
<td>Postcode</td>
<td>
<input type="text" name="postcode" size="40"
value="<? echo "$info[postcode]"?>">
</td>
</tr>
<tr>
<td>Telephone</td>
<td>
<input type="text" name="telephone" size="40"
value="<? echo "$info[telephone]"?>">
</td>
</tr>
<tr>
<td>Mobile</td>
<td>
<input type="text" name="mobile" size="40"
value="<? echo "$info[mobile]"?>">
</td>
</tr>
<tr>
<td>Longitude</td>
<td>
<input type="text" name="longitude" size="40"
value="<? echo "$info[longitude]"?>">
</td>
</tr>
<tr>
<td>Latitude</td>
<td>
<input type="text" name="latitude" size="40"
value="<? echo "$info[latitude]"?>">
</td>
</tr>
<tr>
<td>Email (Default)</td>
<td>
<input type="text" name="email1" size="40"
value="<? echo "$info[email1]"?>">
</td>
</tr>
<tr>
<td>Email (Other)</td>
<td>
<input type="text" name="email2" size="40"
value="<? echo "$info[email2]"?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Submit Changes">
</td>
</tr>
</form>
</table>
</section>
<div id="secbottom"></div></div>
<?php
echo $becompany."<br>";
echo $customerid; // name class and mark will be printed with one line break
if(isset($_POST['edit']))
{
$name=addslashes($_POST['name']);
$address1=addslashes($_POST['address1']);
$address2=addslashes($_POST['address2']);
$address3=addslashes($_POST['address3']);
$town=addslashes($_POST['town']);
$county=addslashes($_POST['county']);
$postcode=addslashes($_POST['postcode']);
$telephone=addslashes($_POST['telephone']);
$mobile=addslashes($_POST['mobile']);
$latitude=addslashes($_POST['latitude']);
$longitude=addslashes($_POST['longitude']);
$email1=addslashes($_POST['email1']);
$email2=addslashes($_POST['email2']);
//$data = "UPDATE 'customer' SET name='$name', address1='$address1',address2='$address2', address3='$address3', town='$town', county='$county', postcode='$postcode', telephone='$telephone', mobile='$mobile', latitude='$latitude', longitude='$longitude', email1='$email1' email2='$email2', WHERE customerid='$customerid'";
// Insert data into data
mysql_query("UPDATE 'customer' SET name='$name', address1='$address1',address2='$address2', address3='$address3', town='$town', county='$county', postcode='$postcode', telephone='$telephone', mobile='$mobile', latitude='$latitude', longitude='$longitude', email1='$email1' email2='$email2', WHERE customerid='$customerid'") or die (mysql_error());
}
?>
</body>
</html>
And the following page validating it -
<?
session_start();
//edit_data.php
include('../includes/mysqlconnection.php');
$becompany = $_SESSION['becompany'];
$customerid = $_SESSION['customerid'];
// Get values from form
if(isset($_POST['edit']))
{
$name=addslashes($_POST['name']);
$address1=addslashes($_POST['address1']);
$address2=addslashes($_POST['address2']);
$address3=addslashes($_POST['address3']);
$town=addslashes($_POST['town']);
$county=addslashes($_POST['county']);
$postcode=addslashes($_POST['postcode']);
$telephone=addslashes($_POST['telephone']);
$mobile=addslashes($_POST['mobile']);
$latitude=addslashes($_POST['latitude']);
$longitude=addslashes($_POST['longitude']);
$email1=addslashes($_POST['email1']);
$email2=addslashes($_POST['email2']);
//$data = "UPDATE 'customer' SET name='$name', address1='$address1',address2='$address2', address3='$address3', town='$town', county='$county', postcode='$postcode', telephone='$telephone', mobile='$mobile', latitude='$latitude', longitude='$longitude', email1='$email1' email2='$email2', WHERE customerid='$customerid'";
// Insert data into data
mysql_query("UPDATE 'customer' SET name='$name', address1='$address1',address2='$address2', address3='$address3', town='$town', county='$county', postcode='$postcode', telephone='$telephone', mobile='$mobile', latitude='$latitude', longitude='$longitude', email1='$email1' email2='$email2', WHERE customerid='$customerid'") or die (mysql_error());
}
//$info = mysql_query($data);
// if successfully updated.
//if($info){
//echo "Successful";
//echo "<BR>";
//echo "<a href='details.php'>View result</a>";
//}
//else {
//echo "ERROR";
//}
header("location:details.php");
?>
As you will see from my note out comments' I have tried various technic's illistrated on various tutorial sites, and have very little success. It just appears to be not updating the database, even though it's pulling the data from it. I'm sure it's a newbie error,missing bracket or quotes, but after 3 hrs of trial and error, I thought I'd ask.
Thanks in advance
Rich