Hello Everyone
Very new to this so please bear with me.
I am trying to code an address book for a small workshop intranet. So far all has gone well except the passing of the value (tbl_row) that identifies a particular row in the database table from contacts.php to update.php. Although I have tried GET, POST and session methods nothing seems to happen. Any help would be greatly apprectiated.
Here is the code of contacts.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
<title>WorkWeb - Contacts</title>
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="imagetoolbar" content="no" />
<meta name="MSSmartTagsPreventParsing" content="true" />
<meta name="description" content="Description" />
<meta name="keywords" content="Keywords" />
<meta name="author" content="Enlighten Designs" />
<style type="text/css" media="all">@import "css/master.css";</style>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=475,height=575');");
}
// End -->
</script>
</head>
<body>
<div id="page-container">
<div id="header">
<div class="padding">
<H1>WorkWeb</h1>
</div>
<H1>WorkWeb</h1>
</div>
<div id="main-nav">
<div id="links">
<dl>
<dt id="Home"><a href="iisstart.php">Calendar |</a></dt>
<dt id="Contacts"><a href="contacts.php">Contacts |</a></dt>
<dt id="Downloads"><a href="Downloads.php">Downloads |</a></dt>
<dt id="Knowledge"><a href="Knowledge.php">Knowledge Base |</a></dt>
<dt id="stock"><a href="stockandparts.php">Stock</a></dt>
</dl>
</div>
</div>
<div id="sidebar">
<div class="padding">
<a href="javascript:popUp('add.php')">Add a Contact</A><br>
<a href="update.php">Update</a>
</div>
</div>
<div id="content">
<div class="padding">
<h2>Search for Contact Details</h2>
<p>You may search by Company Name or Surname</br>
Use % as the wildcard character</p>
<form method="post" action="contacts.php?go" id="searchform">
<input type="text" name="name">
<input type="submit" name="submit" value="Search">
</form>
<?php
if(isset($POST['submit'])){
if(isset($GET['go'])){
if(preg_match("/[A-Z | a-z]+/", $POST['name'])){
$name=$POST['name'];
//connect to the database
$db=mysql_connect ("*****", "*", "*****") or die ('I cannot connect to the database because: ' . mysql_error());
//-select the database to use
$mydb=mysql_select_db("addressdb");
//-query the database table
$sql="SELECT id, company, dept, surname FROM tbl_addressbook WHERE company LIKE '%" . $name . "%' OR dept LIKE '%" . $name ."%' OR surname LIKE '%" . $name ."%'";
//-run the query against the mysql query function
$result=mysql_query($sql);
//-count results
$numrows=mysql_num_rows($result);
echo "<p>" .$numrows . " results found for " . stripslashes($name) . "</p>";
//-create while loop and loop through result set
while($row=mysql_fetch_array($result)){
$company=$row['company'];
$dept=$row['dept'];
$surname=$row['surname'];
$id=$row['id'];
//-display the result of the array
echo "<ul>\n";
echo "<li>" . "<a href=\"contacts.php?id=$id\">" .$company . " " . $dept . " " . $surname . "</a></li>\n";
echo "</ul>";
}
}
else{
echo "<p>Please enter a search query</p>";
}
}
}
if(isset($GET['id'])){
$contactid=$GET['id'];
//connect to the database
$db=mysql_connect ("localhost", "root", "windjammer") or die ('I cannot connect to the database because: ' . mysql_error());
//-select the database to use
$mydb=mysql_select_db("addressdb");
//-query the database table
$sql="SELECT * FROM tbl_addressbook WHERE id=" . $contactid;
//-run the query against the mysql query function
$result=mysql_query($sql);
//-create while loop and loop through result set
while($row=mysql_fetch_array($result)){
$company=$row['company'];
$dept=$row['dept'];
$first=$row['first'];
$surname=$row['surname'];
$address=$row['address'];
$phone=$row['phone'];
$mobile=$row['mobile'];
$fax=$row['fax'];
$email=$row['email'];
$website=$row['website'];
$notes=$row['notes'];
//-display the result of the array
echo "<ul>\n";
echo "<li>" . $company . "</li>\n";
echo "<li>" . $dept . "</li>\n";
echo "<li>" . $first . " " . $surname . "</li>\n";
echo "<li>" . $address . "</li>\n";
echo "<li>" . $phone . "</li>\n";
echo "<li>" . $mobile . "</li>\n";
echo "<li>" . $fax . "</li>\n";
echo "<li>" . "<a href=mailto:" . $email . ">" . $email . "</a></li>\n";
echo "<li>" . $website . "</li>\n";
echo "<li>" . $notes . "</li>\n";
echo "</ul>";
}
}
?>
<form method="post" action="update.php">
<input type="hidden" name="tbl_row" value="<?php echo $_GET['id'] ?>">
</form>
<div id="adlink">
<a href="phpmyadmin/index.php">Administrator</a>
</div>
</div>
</div>
<div id="footer">
<div id="altnav">
<a href="iisstart.php">Calendar|</a>
<a href="contacts.php">Contacts|</a>
<a href="Downloads.php">Downloads|</a>
<a href="Knowledge.php">Knowledge Base|</a>
<a href="stockandparts.php">Stock</a>
</div>
Copyright **********November 2009
</div>
</body>
</html>
Here is update.php
<?php
$id = $_POST['tbl_row'];
$username="****";
$password="*";
$database="**";
$server = "*****";
mysql_connect($server,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM tbl_addressbook WHERE id='$id'";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$company=mysql_result($result,$i,"company");
$dept=mysql_result($result,$i,"dept");
$first=mysql_result($result,$i,"first");
$surname=mysql_result($result,$i,"surname");
$address=mysql_result($result,$i,"address");
$phone=mysql_result($result,$i,"phone");
$mobile=mysql_result($result,$i,"mobile");
$fax=mysql_result($result,$i,"fax");
$email=mysql_result($result,$i,"email");
$website=mysql_result($result,$i,"website");
$notes=mysql_result($result,$i,"notes");
?>
<form action="update.php">
<input type="hidden" name="ud_id" value="<?php echo "$id"; ?>">
company: <input type="text" name="ud_company" value="<?php echo "company"?>"><br>
dept: <input type="text" name="ud_dept" value="<?php echo "$dept"?>"><br>
first: <input type="text" name="ud_first" value="<?php echo "$first"?>"><br>
surname: <input type="text" name="ud_surname" value="<?php echo "$surname"?>"><br>
address: <input type="text" name="ud_address" value="<?php echo "$address"?>"><br>
phone: <input type="text" name="ud_phone" value="<?php echo "$phone"?>"><br>
mobile: <input type="text" name="ud_mobile" value="<?php echo "$mobile"?>"><br>
fax: <input type="text" name="ud_fax" value="<?php echo "$fax"?>"><br>
email: <input type="text" name="ud_email" value="<?php echo "$email"?>"><br>
website: <input type="text" name="ud_website" value="<?php echo "$website"?>"><br>
notes: <input type="text" name="ud_notes" value="<?php echo "$notes"?>"><br>
<input type="Submit" value="Update">
</form>
<?php
$username="***";
$password="**";
$database="*";
$server = "*****";
mysql_connect($server,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
//-select the database to use
///$mydb=mysql_select_db("addressdb");
$ud_id=$POST['ud_id'];
$ud_company=$POST['ud_company'];
$ud_dept=$POST['ud_dept'];
$ud_first=$POST['ud_first'];
$ud_surname=$POST['ud_surname'];
$ud_address=$POST['ud_address'];
$ud_phone=$POST['ud_phone'];
$ud_mobile=$POST['ud_mobile'];
$ud_fax=$POST['ud_fax'];
$ud_email=$POST['ud_email'];
$ud_website=$POST['ud_website'];
$ud_notes=$POST['ud_notes'];
$query="UPDATE tbl_addressbook SET company='$ud_company', dept='$ud_dept', first='$ud_first', surname='$ud_surname' address='$ud_address, phone='$ud_phone', mobile='$ud_mobile', fax='$ud_fax', email='$ud_email', webiste='$ud_website', notes='$ud_notes'";
@mysql_select_db($database) or die( "Unable to select database");
mysql_query($query);
echo "Record Updated";
mysql_close();
++$i;
}
?>