[SOLVED] Editing records

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

[SOLVED] Editing records

Post by mohson »

Can anyone see where I am going wrong with this line of code im trying to link the person_id on my people table to the editpeopl.html page and load the record that is selected into this editpeople form

Code: Select all

<td>'.'<a href='editpeople.html?.$row->person_id. '>' .$row->person_id .'</a></td>
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

You're adding arguments into a plain HTML file?
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

dont worry about that our University server reads all .html files as .php files if you have any php script in them thats not a problem we dont have to save our files as .php

Ignore the html bit can you help with the code
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Not much to go on since you only post one line but you haven't defined the GET var, and you have your quotes in the wrong places:

Code: Select all

<a href="editpeople.html?somevar='.$row->person_id. '">' .$row->person_id .'</a>
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

Ok here is the entire code I tried out what you stated in your last reply but I am not having any luck - never mind loading the selected record in the editform I cant ever get the person_id to appear as a hyperlink??

Have a look through tell me what you think


Code: Select all

<p>


 


<?php

 

// config-------------------------------------
$host = "****"; //your database host
$user = "****"; // your database user name
$pass = "*****"; // your database password
$db = "contact_management_system"; // your database name

$filename = "people.html"; // name of this file
$option = array (5, 10, 20, 50, 100, 200);
$default = 100; // default number of records per page
$action = $_SERVER['PHP_SELF']; // if this doesn't work, enter the filename


// database query. Enter your query here

 $query = 	"SELECT 
		o.org_id,o.web_url,
		p.person_id,p.org_id,p.salutation,p.firstname,p.surname,
		p.organisation,p.role,p.address1,p.address2,p.city,
		p.postcode,p.telephone,p.mobile,p.fax,p.dateoflastcontact,
		p.datecontactagain,p.notes,p.email, 

		DATE_FORMAT(dateoflastcontact, '%M/%Y') 
		AS dateoflastcontact, DATE_FORMAT(datecontactagain, '%M/%Y') 
		AS datecontactagain 

		FROM people p LEFT JOIN organisations o
     		ON o.org_id = p.org_id		
		ORDER BY firstname";



// end config---------------------------------

	
$opt_cnt = count ($option);

$go = $_GET['go'];
// paranoid
if ($go == "") {
$go = $default;
}
elseif (!in_array ($go, $option)) {
$go = $default;
}
elseif (!is_numeric ($go)) {
$go = $default;
}
$nol = $go;
$limit = "0, $nol";
$count = 1; 

echo "<form name=\"form1\" id=\"form1\" method=\"get\" action=\"$action\">\r\n";
echo "<select name=\"go\" id=\"go\">\r\n";

for ($i = 0; $i <= $opt_cnt; $i ++) {
if ($option[$i] == $go) {
echo "<option value=\"".$option[$i]."\" selected=\"selected\">".$option[$i]."</option>\r\n";
} else {
echo "<option value=\"".$option[$i]."\">".$option[$i]."</option>\r\n";
}
}

echo "</select>\r\n";
echo "<input type=\"submit\" name=\"Submit\" id=\"Submit\" value=\"Go\" />\r\n";
echo "</form>\r\n";

$connection = mysql_connect ($host, $user, $pass) or die ("Unable to connect");
mysql_select_db ($db) or die ("Unable to select database $db");



// control query------------------------------
/* this query checks how many records you have in your table.
I created this query so we could be able to check if user is
trying to append number larger than the number of records
to the query string.*/
$off_sql = mysql_query ("$query") or die ("Error in query: $off_sql".mysql_error());
$off_pag = ceil (mysql_num_rows($off_sql) / $nol);
//-------------------------------------------- 


$off = $_GET['offset'];
//paranoid
if (get_magic_quotes_gpc() == 0) {
$off = addslashes ($off);
}
if (!is_numeric ($off)) {
$off = 1;
}
// this checks if user is trying to put something stupid in query string
if ($off > $off_pag) {
$off = 1;
}

if ($off == "1") {
$limit = "0, $nol";
}
elseif ($off <> "") {
for ($i = 0; $i <= ($off - 1) * $nol; $i ++) {
$limit = "$i, $nol";
$count = $i + 1;
}
} 




// Query to extract records from database.
$sql = mysql_query ("$query LIMIT $limit") or die ("Error in query: $sql".mysql_error()); 



// Define your colors for the alternating rows

$color1 = "#ADD8E6";$color2 = "#E0FFFF";
$color = $color2;echo 

"<table width=\"50%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">

    <tr>
		<td><b><small>RecNo</small></b></td>
		<td><b><small>PID</small></b></td>
		<td><b><small>OID</small></b></td>
		<td><b><small>Title</small></b></td>
		<td><b><small>First Name</small></b></td>
		<td><b><small>Surname</small></b></td>
		<td><b><small>Organisation</small></b></td>
		<td><b><center><small>Role</small></center></b></td>
		<td><b><small>Address(1)</small></b></td>
		<td><b><small>Address(2)</small></b></td>
		<td><b><small>City</small></b></td>
		<td><b><small>Post Code</small></b></td>
		<td><b><small>Telephone</small></b></td>
		<td><b><small>Mobile</small></b></td>
		<td><b><small>Fax</small></b></td>
		<td><b><small>Last Contact</small></b></td>
		<td><b><small>Contact Again</small></b></td>
		<td><b><small>Notes</small></b></td>";




while ($row = mysql_fetch_object($sql)) 






{($color==$color2)? $color = $color1 : $color = $color2;


echo "<tr bgcolor=\"$color\"><td>".$count . '</td>

<td>'.'<a href="editpeople.html?person_id='.$row->person_id. '">' .$row->person_id
.'</a></td>
<td>'.$row->org_id.'</td>
<td>'.$row->salutation .'</td>
<td>'.'<a href=mailto:'.$row->email.'>'.$row->firstname .'</a></td>
<td>'.'<a href=mailto:'.$row->email.'>'.$row->surname .'</a></td>
<td>'.'<a href=http://'.$row->web_url.'>'.$row->organisation . '</a></td>
<td>'.$row->role.'</td>
<td>'.$row->address1 .'</td>
<td>'.$row->address2 .'</td>
<td>'.$row->city .'</td>
<td>'.$row->postcode .'</td>
<td>'.$row->telephone .'</td>
<td>'.$row->mobile .'</td>
<td>'.$row->fax .'</td>
<td>'.$row->dateoflastcontact.'</td>
<td>'.$row->datecontactagain.'</td>
<td>'.$row->notes.'</td><td>';

$count += 1;
}

echo "</table>"; 

echo "<br /><br />\r\n";
if ($off <> 1) {
$prev = $off - 1;
echo "[ < <a href=\"$filename?offset=$prev&go=$go\">prev</a> ] \r\n";
}
for ($i = 1; $i <= $off_pag; $i ++) {
if ($i == $off) {
echo "[<b> $i </b>] \r\n";
} else {
echo "[ <a href=\"$filename?offset=$i&go=$go\">$i</a> ] \r\n";
}
}
if ($off < $off_pag) {
$next = $off + 1;
echo "[ <a href=\"$filename?offset=$next&go=$go\">next</a> > ] \r\n";
}

echo "<br /><br />\r\n";
echo "Page $off of $off_pag<br />\r\n";




?>
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

sorry my mistake - it works perrfect
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Editing

Post by mohson »

Ok,

I can manage to make my selected record load in my editpeople form - the problem is once I try and update the record what happens is I get this error message:
UPDATE people SET salutation='Mr', firstname='', surname='Baros', organisation='Liverpool', role='Striker', address1='', address2='', city='', telephone='', mobile='', fax='', dateoflastcontact='2005-02-28', datecontactagain='2005-03-28', notes='', email='milan@soi.city.ac.uk', org_id='950', WHERE person_id=654
could not insertYou have an error in your SQL syntax near 'WHERE person_id=654' at line

heres the code for my edit page:

Code: Select all

<strong><font size="4">Change Details</font></strong><br>
<?
		
/* Connecting, selecting database */
$link = mysql_connect("*******", "******", "*******")
   or die("Could not connect : " . mysql_error());
echo "";
mysql_select_db("contact_management_system") or die("Could not select database");
	
		if(isset($_GET['person_id'])){
			$person_id=$_GET['person_id'];
		}

		if ($_POST['Submit'] == 'Submit'){

			foreach ($_POST as $formName => $phpName){
				$$formName = $phpName;
			}

			$sql ="UPDATE people SET "
					. " salutation='"	.			$salutation						."'," 
					. " firstname='"	.			$firstName						."'," 
					. " surname='"		.			$surname						."'," 
					. " organisation='" .			$organisation					."'," 
					. " role='"			.			$role							."'," 
					. " address1='"	.				$address1						."'," 
					. " address2='" .				$address2						."'," 
					. " city='" .					$city							."'," 
					. " telephone='" .				$telephone						."'," 
					. " mobile='" .					$mobile							."'," 
					. " fax='" .					$fax							."'," 
					. " dateoflastcontact='" .		$dateoflastcontact				."',"
					. " datecontactagain='" .		$datecontactagain				."',"
					. " notes='" .					$notes							."',"
					. " email='" .					$email							."',"
					. " org_id='" .					$org_id							."',"
				. " WHERE person_id=" . $person_id;

			
			echo "<br><div align=center>" . $sql . "<br>";
			mysql_query($sql) or die('could not insert' . mysql_error());

			echo  "		<div align=left><table width=70% border=1 cellpadding=10 align=center>"
				. "			<tr>"
				. "				<td width=40%>"
				. "					<font face=arial size=2><b>"
				. "					person_id"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $person_id . " </font>"
				. "				</td>"
				. "			</tr>"
				. "		<tr>"
				. "			<td>"
				. "					<font face=arial size=2><b>"
				. "					salutation"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $salutation . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					firstname"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $firstname . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					surname"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $surname . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					organisation"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $organisation . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					role"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $role . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					address1"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $address2 . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					city"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $city . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					postcode"
				. "					</font>"
				. "				</td>"
				. "					<td>"
				. "					<font face=arial size=2>"
				. "					" . $postcode . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "						telephone"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $telephone . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					mobile"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $mobile . "</font>"
				. "				</td>"
				. "			</tr>"
				."			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					fax"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $fax . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					dateoflastcontact"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $dateoflastcontact . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					datecontactagain"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $datecontactagain . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					notes"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $notes . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					email"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $email . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					org_id"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $org_id . "</font>"
				. "				</td>"
				. "			</tr>"
				. "		</table>"; 
		}
		//else{
			$sql = "SELECT * FROM people WHERE person_id='" . $person_id . "'";
			echo "<br><div align=center>" . $sql . "<br>";
			$memb = mysql_query($sql) or die(mysql_error());
			$row = mysql_fetch_array($memb);

			echo  "\n"
				. "		</div>\n"
				. "		<form name=form2 method=post action=editpeople.html?person_id=" . $person_id . ">\n"
				. "			<table width=70% border=1 cellpadding=10 align=center>\n"
				. "				<tr>\n"
				. "					<td width=40%>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Person ID\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=person_id type=text id=person_id value='" . $row['person_id'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n" 
				. "				<tr>\n"
				. "					<td width=40%>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Salutation\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=salutation type=text id=salutation value='" . $row['salutation'] . "'></font>\n"
				. "				<tr>\n"
				. "					<td width=40%>\n"
				. "						<font face=arial size=2><b>\n"
				. "						First Name\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=firstname type=text id=firstname value='" . $row['firstname'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Surame\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=surname type=text id=surname value='" . $row['surname'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Organisation\n"
				. "						</font>\n"
				. "						</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=organisation type=text id=organsation value='" . $row['organisation'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Role \n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=role type=text id=role value='" . 
				$row['role']		. "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Address 1\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=address1 type=text id=address1 value='" . $row['address1'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Address2\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=address2 type=text id=address2 value='" . $row['address2'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						City\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=city type=text id=city value='" . 
				$row['city']	. "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Telephone\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=telephone type=text id=telephone value='" . $row['telephone'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Mobile\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=mobile type=text id=mobile value='" . 
				$row['mobile'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Fax\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=fax type=text id=fax value='" . 
				$row['fax'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Last Contact\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=dateoflastcontact type=text id=dateoflastcontact 								value='" . 
				$row['dateoflastcontact'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Contact Again\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=datecontactagain type=text id=datecontactagain 									value='" . 
				$row['datecontactagain'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Notes\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=notes type=text id=notes value='" . 
				$row['notes'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Email\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=email type=text id=email value='" . 
				$row['email'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						OID\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=org_id type=text id=org_id value='" . 
				$row['org_id'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td colspan=2>\n"
				. "						&nbsp\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td colspan=2 align=center>\n"
				. "						<input type=reset name=Reset value=Reset>\n"
				. "						<input type=submit name=Submit value=Submit>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "			</table>\n"
				. "		</form>\n";
	//	}
		?>


		</td>
anyone got any advice on how I can make the update work properly also could someone explain why the statement
SELECT * FROM people WHERE person_id=
appears at the top of my edit form am I missing something.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Editing

Post by Chris Corbyn »

Missing the single quotes around person_id :wink:

Code: Select all

$sql ="UPDATE people SET "
					. " salutation='"	.			$salutation						."'," 
					. " firstname='"	.			$firstName						."'," 
					. " surname='"		.			$surname						."'," 
					. " organisation='" .			$organisation					."'," 
					. " role='"			.			$role							."'," 
					. " address1='"	.				$address1						."'," 
					. " address2='" .				$address2						."'," 
					. " city='" .					$city							."'," 
					. " telephone='" .				$telephone						."'," 
					. " mobile='" .					$mobile							."'," 
					. " fax='" .					$fax							."'," 
					. " dateoflastcontact='" .		$dateoflastcontact				."',"
					. " datecontactagain='" .		$datecontactagain				."',"
					. " notes='" .					$notes							."',"
					. " email='" .					$email							."',"
					. " org_id='" .					$org_id							."',"
				. " WHERE person_id='" . $person_id."'";
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

made the change still got the same problem??
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Editing

Post by Chris Corbyn »

You still get this error even using the code I posted? Could you show me your updated code please :?
UPDATE people SET salutation='Mr', firstname='', surname='Baros', organisation='Liverpool', role='Striker', address1='', address2='', city='', telephone='', mobile='', fax='', dateoflastcontact='2005-02-28', datecontactagain='2005-03-28', notes='', email='milan@soi.city.ac.uk', org_id='950', WHERE person_id=654
could not insertYou have an error in your SQL syntax near 'WHERE person_id=654' at line
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Just noticed... you have a comma before WHERE... remove it :wink:
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

i see a lot of code (too lazy to dig through it right now...) but i think you could reduce your typing efforts by using a simple loop to generate all that html....

there is a comma before WHERE... as the error says... after you have add org_id you should not add a , anymore... or if you are generating the query in a loop you could use rtrim to remove the last ,.
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

ok d11wtq,

heres the code:

Code: Select all

/* Connecting, selecting database */
$link = mysql_connect("***", "****", "****")
   or die("Could not connect : " . mysql_error());
echo "";
mysql_select_db("contact_management_system") or die("Could not select database");
	
		if(isset($_GET['person_id'])){
			$person_id=$_GET['person_id'];
		}

		if ($_POST['Submit'] == 'Submit'){

			foreach ($_POST as $formName => $phpName){
				$$formName = $phpName;
			}

				 $sql ="UPDATE people SET "
					. " salutation='"	.$salutation."'," 
					. " firstname='"	.$firstName	."'," 
					. " surname='"		.$surname."'," 
					. " organisation='" .$organisation	."'," 
					. " role='"			.$role."'," 
					. " address1='"	.	$address1."'," 
					. " address2='" .$address2."'," 
					. " city='" .$city."'," 
					. " telephone='" .$telephone."'," 
					. " mobile='" .	$mobile	."'," 
					. " fax='" .$fax."'," 
					. " dateoflastcontact='" .$dateoflastcontact."',"
					. " datecontactagain='" .$datecontactagain."',"
					. " notes='" .$notes."',"
					. " email='" .$email."',"
					. " org_id='" .	$org_id	."'"
					. " WHERE person_id='" . $person_id."'";

			echo "<br><div align=center>" . $sql . "<br>";
			mysql_query($sql) or die('could not insert' . mysql_error());

			echo  "		<div align=left><table width=70% border=1 cellpadding=10 align=center>"
				. "			<tr>"
				. "				<td width=40%>"
				. "					<font face=arial size=2><b>"
				. "					person_id"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $person_id . " </font>"
				. "				</td>"
				. "			</tr>"
				. "		<tr>"
				. "			<td>"
				. "					<font face=arial size=2><b>"
				. "					salutation"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $salutation . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					firstname"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $firstname . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					surname"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $surname . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					organisation"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $organisation . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					role"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $role . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					address1"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $address2 . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					city"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $city . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					postcode"
				. "					</font>"
				. "				</td>"
				. "					<td>"
				. "					<font face=arial size=2>"
				. "					" . $postcode . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "						telephone"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $telephone . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					mobile"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $mobile . "</font>"
				. "				</td>"
				. "			</tr>"
				."			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					fax"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $fax . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					dateoflastcontact"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $dateoflastcontact . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					datecontactagain"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $datecontactagain . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					notes"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $notes . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					email"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $email . "</font>"
				. "				</td>"
				. "			</tr>"
				. "			<tr>"
				. "				<td>"
				. "					<font face=arial size=2><b>"
				. "					org_id"
				. "					</font>"
				. "				</td>"
				. "				<td>"
				. "					<font face=arial size=2>"
				. "					" . $org_id . "</font>"
				. "				</td>"
				. "			</tr>"
				. "		</table>"; 
		}
		
		$sql = "SELECT * FROM people WHERE person_id='" . $person_id . "'";
			echo "<br><div align=center>" . $sql . "<br>";
			$memb = mysql_query($sql) or die(mysql_error());
			$row = mysql_fetch_array($memb);

			echo  "\n"
				. "		</div>\n"
				. "		<form name=form2 method=post action=editpeople.html?person_id=" . $person_id . ">\n"
				. "			<table width=70% border=1 cellpadding=10 align=center>\n"
				. "				<tr>\n"
				. "					<td width=40%>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Person ID\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=person_id type=text id=person_id value='" . $row['person_id'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n" 
				. "				<tr>\n"
				. "					<td width=40%>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Salutation\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=salutation type=text id=salutation value='" . $row['salutation'] . "'></font>\n"
				. "				<tr>\n"
				. "					<td width=40%>\n"
				. "						<font face=arial size=2><b>\n"
				. "						First Name\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=firstname type=text id=firstname value='" . $row['firstname'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Surame\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=surname type=text id=surname value='" . $row['surname'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Organisation\n"
				. "						</font>\n"
				. "						</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=organisation type=text id=organsation value='" . $row['organisation'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Role \n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=role type=text id=role value='" . 
				$row['role']		. "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Address 1\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=address1 type=text id=address1 value='" . $row['address1'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Address2\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=address2 type=text id=address2 value='" . $row['address2'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						City\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=city type=text id=city value='" . 
				$row['city']	. "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Telephone\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=telephone type=text id=telephone value='" . $row['telephone'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Mobile\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=mobile type=text id=mobile value='" . 
				$row['mobile'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Fax\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=fax type=text id=fax value='" . 
				$row['fax'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Last Contact\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=dateoflastcontact type=text id=dateoflastcontact 								value='" . 
				$row['dateoflastcontact'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Contact Again\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=datecontactagain type=text id=datecontactagain 									value='" . 
				$row['datecontactagain'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Notes\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=notes type=text id=notes value='" . 
				$row['notes'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						Email\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=email type=text id=email value='" . 
				$row['email'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td>\n"
				. "						<font face=arial size=2><b>\n"
				. "						OID\n"
				. "						</font>\n"
				. "					</td>\n"
				. "					<td>\n"
				. "						<font face=arial size=2>\n"
				. "						<input name=org_id type=text id=org_id value='" . 
				$row['org_id'] . "'></font>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td colspan=2>\n"
				. "						&nbsp\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "				<tr>\n"
				. "					<td colspan=2 align=center>\n"
				. "						<input type=reset name=Reset value=Reset>\n"
				. "						<input type=submit name=Submit value=Submit>\n"
				. "					</td>\n"
				. "				</tr>\n"
				. "			</table>\n"
				. "		</form>\n";
	//	}
		?>


		</td>

<p>
and heres the error message
UPDATE people SET salutation='Mr', firstname='', surname='dcfv', organisation='', role='', address1='cvc', address2='dfx', city='', telephone='', mobile='', fax='', dateoflastcontact='0000-00-00', datecontactagain='0000-00-00', notes='', email='', org_id='0' WHERE person_id='650'
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

See last two posts by timvw and I...
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

yeh had a look and removed the quote but still getting the same error message
Post Reply