junky
08-05-2003, 08:16 AM
Hey all
I'm new to this forum and new to PHP as well :)
I'm trying to run a script that adds info to my database by the way of user input,
its an example from a book
being that I'm new to php its hard to problem solve and I am stuck !!
<?php
if (isset($domain) && isset($sex) && isset($mail) ) {
$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){
$db = "sample";
$link = mysql_connect("localhost");
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 method=\"POST\">\n";
print "<input type\"text\" name\"domain\"> ";
print "The domain you want<p>\n";
print "<input TYPE=\"text\" name=\"mail\"> ";
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";
}
?>
any help would be appreciated
thanks
I'm new to this forum and new to PHP as well :)
I'm trying to run a script that adds info to my database by the way of user input,
its an example from a book
being that I'm new to php its hard to problem solve and I am stuck !!
<?php
if (isset($domain) && isset($sex) && isset($mail) ) {
$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){
$db = "sample";
$link = mysql_connect("localhost");
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 method=\"POST\">\n";
print "<input type\"text\" name\"domain\"> ";
print "The domain you want<p>\n";
print "<input TYPE=\"text\" name=\"mail\"> ";
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";
}
?>
any help would be appreciated
thanks