Jump to content

Recommended Posts

hi, i am not a php guru, and need some help.

 

i have one page, search.htm, that ties to search.php, which successfully infills a form. this form is what is subject to any changes, if any, and the submit button hits updated.php. but updated php doesnt update the db.

 

here is the search page:

<html>
    <head>
        <title>Search the Database</title>
    </head>

    <body>

    <form action="search.php" method="post">
     Search: <input type="text" name="term" /><br />
    <input type="submit" name="submit" value="Submit" />
    </form>

    </body>
</html>

 

this is search.php, where the form contents are successfully filled in from the search:

 

<?php
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
mysql_select_db($database) or die( "Unable to select database");
$term = $_POST['term'];
$sql = mysql_query("select * from data1 where id = '$term'");
while ($row = mysql_fetch_array($sql)){
echo "Record:  ";  
echo $term;
?>

      <form action="updated.php">
        <input type="hidden" name="id" value="<?php echo $row['id']; ?>">
        First Name: <input type="text" name="first" value="<?php echo $row['first'];?>"><br>
        Last Name: <input type="text" name="last" value="<?php echo $row['last'];?>"><br>
Street: <input type="text" name="street" value="<?php echo $row['street'];?>"><br>
City: <input type="text" name="city" value="<?php echo $row['city'];?>"><br>
State: <input type="text" name="state" value="<?php echo $row['state'];?>"><br>
Zip: <input type="text" name="zip" value="<?php echo $row['zip'];?>"><br>
Fee Rcd (Y/N): <input type="text" name="fee_rcpt" value="<?php echo $row['fee_rcpt'];?>"><br>
Date Rcd: <input type="text" name="date_rcd" value="<?php echo $row['date_rcd'];?>"><br>
Opened By: <input type="text" name="opnd_by" value="<?php echo $row['opnd_by'];?>"><br>
Check Encl (Y/N): <input type="text" name="check_encl" value="<?php echo $row['check_encl'];?>"><br>

<input type="Submit" value="Update">
      </form>

<?php
}
?>

and this is the code for updated.php, which does not do anything

 

<?php
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
mysql_select_db($database) or die( "Unable to select database");

mysql_query($query);
$first = mysql_real_escape_string ($_POST['first']);
echo $first;
$last = mysql_real_escape_string($_POST['last']);

$street = mysql_real_escape_string($_POST['street']);
$city = mysql_real_escape_string($_POST['city']);
$state = mysql_real_escape_string($_POST['state']);
$zip = mysql_real_escape_string($_POST['zip']);
$fee_rcpt = mysql_real_escape_string($_POST['fee_rcpt']);
$date_rcd = mysql_real_escape_string($_POST['date_rcd']);
$opnd_by = mysql_real_escape_string($_POST['opnd_by']);
$check_encl = mysql_real_escape_string($_POST['check_encl']);


$query="UPDATE data1 SET first='$first', last='$last', street='$street', city='$city', state='$state', zip='$zip', fee_rcpt='$fee_rcpt', date_rcd='$date_rcd', opnd_by='$opnd_by', check_encl='$check_encl' WHERE id=''";

echo "Record Updated";
mysql_close();
?>


 

what i want is the form contents to go into the MySQL db record indicated by the 'id'

 

any ideas are welcome!

<?php
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
mysql_select_db($database) or die( "Unable to select database");

// mysql_query($query); you can't run the query until you build the query string...

$id    = (int)$_POST['id'];
$first = mysql_real_escape_string ($_POST['first']);
echo $first;
$last = mysql_real_escape_string($_POST['last']);

$street = mysql_real_escape_string($_POST['street']);
$city = mysql_real_escape_string($_POST['city']);
$state = mysql_real_escape_string($_POST['state']);
$zip = mysql_real_escape_string($_POST['zip']);
$fee_rcpt = mysql_real_escape_string($_POST['fee_rcpt']);
$date_rcd = mysql_real_escape_string($_POST['date_rcd']);
$opnd_by = mysql_real_escape_string($_POST['opnd_by']);
$check_encl = mysql_real_escape_string($_POST['check_encl']);


$query="UPDATE data1 SET first='$first', last='$last', street='$street', city='$city', state='$state', zip='$zip', fee_rcpt='$fee_rcpt', date_rcd='$date_rcd', opnd_by='$opnd_by', check_encl='$check_encl' WHERE id=$id";

if (mysql_query($query)) {
   echo "Record Updated";
} else {
   echo "An error has occured.";
}

mysql_close();
?>


it looks good

 

but it wont fire

 

here are the links to the site so you can see what i am seeing

 

the database output where i can see if there are any changes or not

 

http://inovacapitalmanagement.com/mysql

 

this is the page to run the search

 

http://inovacapitalmanagement.com/mysql/search.htm

 

and from there search.php get the contents, but when i click 'update' the updated.php file isn't working. and when i try to echo something from the incoming search.php file nothing appears on the screen

 

not sure how to connect the contents of search.php tp updated.php.

 

thanks for the reply

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.