RE: [PHP-WIN] adding a record to a mySQL table

From: Date: Fri, 06 Oct 2000 10:43:06 +0000
Subject: RE: [PHP-WIN] adding a record to a mySQL table
Groups: php.windows 
Request: Send a blank email to php-windows+get-2994@lists.php.net to get a copy of this message
My first suggestion would be to try a VERY SIMPLE script to test the database connection. But it also looks like the first IF statement is never closed. In fact, the closer I look at it, the more missing { } I think there might be... oh, wait... it's closed, but the internal IF ELSE combination is never bracketed, see comments below > if ( isset( $domain ) && isset( $sex ) && isset( $domain )) //doesn't look like it's closed > { > # check user input here ! > $dberror = " " ; > $ret = add_to_database($domain, $sex, $mail, $dberror); > if ( ! $ret) //no brackets? > print "Error: $dberror<br>"; > else //no brackets? > print "Thank you very much"; > } > else { > write_form(); > } Hope that helps... --------------------- John Asendorf - jasendorf@lcounty.com Web Applications Developer http://www.lcounty.com - NEW FEATURES ADDED DAILY! Licking County, Ohio, USA 740-349-3631 > -----Original Message----- > From: leffa Olausson [mailto:leffa@usa.com] > Sent: Thursday, October 05, 2000 8:43 PM > To: php-windows@lists.php.net > Subject: [PHP-WIN] adding a record to a mySQL table > > > PLEASE !!! > Anybody out there, able to explain why the code below dosn't > add records to mySQL table as expected ???? > ..and why isn't there anything indicating what's going on ?? > No errormessage, no nothing, just plain silence ? > 1. I'm on a win 95. > 2. I have installed a precompiled php 4.02 from php.net. > I guess its ok, because the phpinfo shows up on demand. > 3. Apache 1.3.11 , is in place, doing everyting expected from it. > 4. mysql is installed an works fine. > I've tried a few script for connecting to the databas and > everyting works fine, except for adding records to the database !!! > This is what Apache access.log say: > 127.0.0.1 - - [05/Oct/2000:20:28:41 +0200] "GET > /ab/inp_test.php?domain=newdomain&mail=new@post.com&sex=F > HTTP/1.1" 200 384 > and nothing in the error logg. > Nothing in the mySQL error logg. > ???? and PHP dosn't report anything, right ???? > HELP...what is wrong here ????? > ## the code > <HTML> > <HEAD> > <TITLE>Listing 12.3 Adding user input.</TITLE> > </HEAD> > <BODY> > <?php > if ( isset( $domain ) && isset( $sex ) && isset( $domain )) > { > # check user input here ! > $dberror = " " ; > $ret = add_to_database($domain, $sex, $mail, $dberror); > if ( ! $ret) > print "Error: $dberror<br>"; > else > print "Thank you very much"; > } > else { > write_form(); > } > > function add_to_database( $domain, $sex, $mail, &$dberror ) > { > $user = "myName"; > $pass = "myPWD"; > $db = "myDB"; > $link = mysql_pconnect( "localhost", $user, $pass ); > if ( ! $link ) > { > $dberror = "Couldn't connect to mySQL server."; > return FALSE; > } > if ( ! mysql_select_db($db, $link)) > { > $dberror = mysql_error(); > return FALSE; > } > $query = "INSERT INTO domains (domain, sex, mail) > VALUES('$domain', '$sex', '$mail')"; > if ( ! mysql_query($query, $link)) > { > $dberror = mysql_error(); > return FALSE; > } > return TRUE; > } > > function write_form() > { > global $PHP_SELF; > print "<form action =\"$PHP_SELF\" method=\"GET\">\n"; > print "<input type=\"text\" name=\"domain\">\n"; > print "The domain you would like<p>\n"; > print "<input type=\"text\" name=\"mail\">\n"; > print "Your mail address<p>\n"; > print "<select name=\"sex\">\n"; > print "\t<option value=\"F\">Female\n"; > print "\t<option value=\"M\">Male\n"; > print "</select>\n"; > print "<input type=\"submit\" > value=\"Submit!\">\n</form>\n"; > } > ?> > </BODY> > </HTML> > > ______________________________________________ > FREE Personalized Email at Mail.com > Sign up at http://www.mail.com/?sr=signup > > > -- > PHP Windows Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net > For additional commands, e-mail: php-windows-help@lists.php.net > To contact the list administrators, e-mail: > php-list-admin@lists.php.net >

« previous php.windows (#2994) next »