Re: cannot write to mySQL database

From: Date: Mon, 04 Mar 2002 17:50:08 +0000
Subject: Re: cannot write to mySQL database
References: 1 2 3 4 5  Groups: php.windows 
Request: Send a blank email to php-windows+get-12442@lists.php.net to get a copy of this message
Another thing I suggest is, instead of relying on the value from $submit (your submit button), create a hidden field and call it "action" or whatever you want that makes sense to you. This hidden field will store the value of the action you will take when the form is submitted. For example, you can call it "action" and give it the value "submit." Ex: <input type="hidden" name="action" value="submit"> Then, in your php, you can do this: If ( $action == "submit" ) ## do your insert query here } else { ## display the form } Good luck, Nicole www.aeontrek.com "Pilotdave" <pilotdaveg@yahoo.com> wrote in message news:20020304173427.66115.qmail@pb1.pair.com... > > "Nicole Amashta" <430ntr3k@bellsouth.net> wrote in message > news:20020304162709.7403.qmail@pb1.pair.com... > > Could you post the code you are trying to use to do this? It may just be a > > coding issue and not MySQL at all. > > > > > Sure. The database is called movies1db, username is movies, password is > database. This definitely could be an issue with how i set up the user or > something. Here's the code for one form I'm trying: > ------- > <html> > <body> > <?php > > if ($submit) { > > // process form > > $db = mysql_connect("localhost", "movies","database"); > > mysql_select_db("movies1db",$db); > > $sql = "INSERT INTO tbl1 (name,location,length,size,description) VALUES > > ('$name','$location','$length','$size','description')"; > > $result = mysql_query($sql); > > echo "Thank you! Information entered.\n"; > > } else{ > > // display form > > ?> > > <form method="post" action="<?php echo $PHP_SELF ?>"> > > Name:<input type="Text" name="name"><br> > > Location:<input type="Text" name="location"><br> > > Length:<input type="Text" name="length"><br> > > Size:<input type="Text" name="size"><br> > > Description:<input type="Text" name="description"><br> > > <input type="Submit" name="submit" value="Enter > information"> > > </form> > > <?php > } // end if > ?> > </body> > </html> > ------ > > Here's more info. I checked my apache error log and found that when I open > that page, I get the following errors: > [Mon Mar 04 12:14:27 2002] [error] PHP Warning: Undefined variable: submit > in c:\homepage\phptest\dataform2.php on line 11 > [Mon Mar 04 12:14:27 2002] [error] PHP Warning: Undefined variable: > PHP_SELF in c:\homepage\phptest\dataform2.php on line 37 > > I get the same errors when I hit the submit button. Hope this helps! > > Dave > >

« previous php.windows (#12442) next »