View Single Post
Old 02-17-2009, 03:27 PM   #1 (permalink)
dp2
The Visitor
 
Join Date: Feb 2009
Posts: 4
Thanks: 0
dp2 is on a distinguished road
Default Basic php form update mysql script

I am attempting to build a php form to update my database

I can php read from but trying to put this data into a form that will update my database. Is proving difficult In this example the first part is reading ok I'm now trying to get the data into the form fields, What is happerning is the data and variables are being erased.

Any ideas where I am going wrong? Thank you

Code:
<HTML>
<HEAD>
<TITLE> The Reg Directory </TITLE>
<HEAD>
<BODY>
<?php 

$dbcnx = @mysql_connect("localhost", "username", "password");
if (!$dbcnx) {
  echo( "<P>Unable to connect to the" .
        "database server at this time.</P>" );
  exit();
}

//select which database you want to edit
mysql_select_db("aynsley_phpbb1",$dbcnx);

if (! @mysql_select_db("aynsley_phpbb1") ) {
  echo( "<P>Unable to locate the regdir " .
        "database at this time.</P>" );
  exit();
}

 // Request the text of all the business names
  $result = mysql_query(
            "SELECT BusinessName FROM regdir");
  if (!$result) {
    echo("<P>Error performing query: " .
         mysql_error() . "</P>");
    exit();
  }
//mysql_query(<query>, <connection id>);
while ($row=mysql_fetch_array($result)) {
  echo("<P>" . $row["BusinessName"] . "</P>");
}
?>
<P> Here are all the Businesses in our database: </P>
<BLOCKQUOTE>

<?php

 // Request the text of all the business names
  $result = mysql_query(
            "SELECT BusinessStreet FROM regdir");
  if (!$result) {
    echo("<P>Error performing query: " .
         mysql_error() . "</P>");
    exit();
  }

  // Display the text of each BusinessName in a paragraph
  while ( $row = mysql_fetch_array($result) ) {
  }
?>
<html>
<body>
<form method="post"action="<?php echo $PHP_SELF ?>">
<input type=text name="action" value="">
Business Name 
<input type=text name="BusinessName" value="<?PHP echo $BusinessName ?>"></br>
<input type=text name="BusinessStreet" value="<?PHP echo $BusinessStreet ?>">
<input type=submit name="submit" value="submit">
</form>
<?php
  echo("$BusinessStreet");
  

?>
</BLOCKQUOTE>
</BODY>
</HTML>
dp2 is offline  
Reply With Quote