What is the error?  We have no idea what to look for if you don't tell us
what error you are receiving.  Have you (like someone else has suggested
earlier) printed the SQL statement?  I would add: print( '<!-- SQL
Statement: $sql -->' ); in your code after you build the statement.

In your SQL statement, shouldn't it be state=\"$state\" and zip=\"$zip\"?
--
> $sql = "UPDATE $table_name SET
>
c_name=\"$c_name\",s_addy=\"$s_addy\",city=\"$city\",state=\"state\",zip=\"z
> ip\",phone=\"$phone\"";
--

Also, I would suggest putting: print("<p>Your changes have been saved to the
database</p>");  after the query has ACTUALLY finished.  That way if for
some reason it didn't work, your visitor doesn't feel "Well, you told me it
was completed! Why isn't???".  Like if the DB server was down or something.



--
William Fong - [EMAIL PROTECTED]
Phone: 626.968.6424 x210  |  Fax: 626.968.6877
Wireless #: 805.490.7732    |  Wireless E-mail: [EMAIL PROTECTED]




----- Original Message -----
From: "jas" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, January 31, 2002 9:41 PM
Subject: Re: [PHP-DB] Updating Database problem...


> Sorry, but I figured it out.  You were right, I do need to call the sql
> update function after the error field returns a 0.  Here is the code if
any
> one else out there is having the same problem.
> <?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;
>
>  }
> ?>
> ----- Then in body of document ------
> <?php
>
> if($formerr > 0)
> {
> print('You need to fill out the form completely.  Click the back button on
> your browser to make the necessary changes.<br>');
>  echo $c_nameerr;
>  echo $s_addyerr;
>  echo $cityerr;
>  echo $stateerr;
>  echo $ziperr;
>  echo $phoneerr;
> }
>
> if($formerr == 0)
>  {
>   print("<p>Your changes have been saved to the database</p>");
> # ------------- 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.");
> # --------------------------------------------------------------
> }
> ?>
> "Rick Emery" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > 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
>
>



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

Reply via email to