hi i have 2 functions that take data from html forms and submit them to different tables in a mysql db.
function register_mjp2($userid,$validaddressmo,$validaddressday,$validaddressyr,$address1,$address2,$address3,$city,$state,$zip,$country,$phone1,$phone2,$phone3,$evephone1,$evephone2,$evephone3,$email,$permaddress1,$permaddress2,$permaddress3,$permcity,$permstate,$permzip,$permphone1,$permphone2,$permphone3,$permphoneb1,$permphoneb2,$permphoneb3,$prefenrollment,$prefenrollmentyr,$jointdegreewith,$concentration,$amp,$ber)
// save mjp_pg2 info
// return true or error message
{
// connect to db
$conn = db_connect();
if (!$conn)
return "Could not connect to database server - please try later.";
//updating table user
$result = mysql_query("update user
set address1='$address1',address2='$address2',address3='$address3',city='$city',state='$state',zip='$zip',country='$country',phone1='$phone1',phone2='$phone2',phone3='$phone3',email='$email'
where userid='$userid'");
if (!$result)
return "Could not save your information in the database - please try again later.";
$result = mysql_query( "select *
from mjp2
where userid = '$userid'");
$row = mysql_fetch_array($result); //getting info from row in db
//if 1st time submitting info
$pass = $row['pass'];
if ($pass == "0")
$result = mysql_query("insert into mjp2 values
('$userid', '1', '$validaddressmo', '$validaddressday', '$validaddressyr', '$evephone1', '$evephone2', '$evephone3', '$permaddress1', '$permaddress2', '$permaddress3', '$permcity', '$permstate', '$permzip', '$permphone1', '$permphone2', '$permphone3', '$permphoneb1', '$permphoneb2', '$permphoneb3', '$prefenrollment', '$prefenrollmentyr', '$jointdegreewith', '$concentration', '$amp', '$ber', now('$savedmjp2'))");
if (!$result)
return "Could not save your information in the database - please try again later.";
//if not the 1st time submitting info
if ($pass == "1")
$result = mysql_query("update mjp2
set validaddressmo='$validaddressmo', validaddressday='$validaddressday', validaddressyr='$validaddressyr', evephone1='$evephone1', evephone2='$evephone2', evephone3='$evephone3', permaddress1='$permaddress1', permaddress2='$permaddress2', permaddress3='$permaddress3', permcity='$permcity', permstate='$permstate', permzip='$permzip', permphone1='$permphone1', permphone2='$permphone2', permphone3='$permphone3', permphoneb1='$permphoneb1', permphoneb2='$permphoneb2', permphoneb3='$permphoneb3', prefenrollment='$prefenrollment', prefenrollmentyr='$prefenrollmentyr', jointdegreewith='$jointdegreewith', concentration='$concentration', amp='$amp', ber='$ber', savedmjp2=now()
where userid='$userid'");
if (!$result)
return "Could not save your information in the database - please try again later.";
return true;
}
function register_mjp3($userid,$institution,$location)
// save mjp_pg3 info
// return true or error message
{
// connect to db
$conn = db_connect();
if (!$conn)
return "Could not connect to database server - please try later.";
//updating table user
$result = mysql_query("update user
set institution='$institution'
where userid='$userid'");
if (!$result)
return "Could not save your information in the database - please try again later.";
$result = mysql_query("select *
from mjp3
where userid = '$userid'");
$row = mysql_fetch_array($result); //getting info from row in db
//if 1st time submitting info
$pass = $row['pass'];
if ($pass == "0")
$result = mysql_query("insert into mjp3 values
('$userid', '1', '$location')");
if (!$result)
return "Could not save your information in the database - please try again later.";
//if not the 1st time submitting info
if ($pass == "1")
$result = mysql_query("update mjp3
set location='$location'
where userid='$userid'");
if (!$result)
return "Could not save your information in the database - please try again later.";
return true;
}
function register_mjp_pg2 works perfectly. the 2 functions are supposed to
update the contents of table 'user' in the db, then based on whether or not it is the first time the user is saving their information with a particular form (this is checked by a value in tables mjp2 and mjp3 called 'pass' which is incremented to '1' after the first time the user submits his information into that table), the functions either insert into or update tables mjp2 or mjp3, respectively.
function register_mjp3 doesn't work correctly. it updates table 'user' fine. if i plug values into table mjp3 in the db to simulate that it is not the first time info is being submitted into the db for that particular userid, then it works and updates the db successfully. however, it doesn't insert into the db the first time for a particular userid. i've been looking at the code all afternoon and i can't what i need to change to get this to work.
can someone take a look?
thanks
posszum