Jas,

Why are you initiating an UPDATE command when you've not changed the
information you wish to update?
For instance, if $c_name is blank, you display a message to enter the data;
yet, you DO NOT ASK the user to enter the correct information.  Then, you do
an UPDATE statment to enter that blank info into the record.

You also update $formerr, yet do not use it.

I've got a feeling you're not sharing all your code.  Please do so if we are
to help.

You also need a WHERE clause in you UPDATE; otherwise, ALL records will be
changed

-----Original Message-----
From: jas [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 31, 2002 11:14 PM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Updating Database problem...


I am having a problem with a script that simply updates a few fields in a
database however, I am having a problem having the script to not update the
database fields if the form is invalid... Here is my script, I don't want
you to fix it for me unless you show me where I am going wrong or can point
me to a good tutorial on this type of function.   Thanks in advance,
Jas
<?php
# trim extra spaces from these variables
$c_name = trim($c_name);
$s_addy = trim($s_addy);
$city = trim($city);
$state = trim($state);
$zip = trim($zip);
$phone = trim($phone);
if($c_name == "")
 {
   $c_nameerr = "Please enter your Company Name<br>";
   $formerr = $formerr + 1;

 }
if($s_addy == "")
 {
   $s_addyerr = "Please enter your Street Address<br>";
   $formerr = $formerr + 1;

 }
if($city == "")
 {
   $cityerr = "Please enter your City<br>";
   $formerr = $formerr + 1;

 }
if($state == "")
 {
   $stateerr = "Please enter your State<br>";
   $formerr = $formerr + 1;

 }
if($zip == "")
 {
   $ziperr = "Please enter your Zip Code<br>";
   $formerr = $formerr + 1;

 }
if($phone == "")
 {
   $phoneerr = "Please enter your Phone Number<br>";
   $formerr = $formerr + 1;

 }
# ------------- connects to the mysql database to edit information
$db_name = "test";
$table_name = "www_demo";
$connection = @mysql_connect("localhost", "user", "password") or die ("Could
not connect to database.  Please try again later.");
$db = @mysql_select_db("$db_name",$connection) or die ("Could not select
database table. Please try again later.");
$sql = "UPDATE $table_name SET
c_name=\"$c_name\",s_addy=\"$s_addy\",city=\"$city\",state=\"state\",zip=\"z
ip\",phone=\"$phone\"";
$result = @mysql_query($sql, $connection) or die ("Could not execute query.
Please try again later.");
# --------------------------------------------------------------
?>



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to