adding a record to a mySQL table
| From: | leffa Olausson | Date: | Fri, 06 Oct 2000 00:42:37 +0000 |
| Subject: | adding a record to a mySQL table | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-2973@lists.php.net to get a copy of this message | ||
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