2 basic Questions
Posted: Sat Dec 15, 2007 9:50 am
Hi all,
1) How do you determine whether an INSERT or UPDATE was successful? I had a look and thought it was done via mysql_num_rows but this doesn't seem to be working for me
e.g
Basic example. But I need to be able to relay back to the user if it was successful or not.
2) Inserting a date of birth into a date formatted MYSQL column (yyyy-mm-dd)?
I have drop down menus to choose date of birth, and then have a function that changes these 'pretty' months ('jan 'etc..) into plain numbers, e.g output would be.... 19970222 for 22 feb 1997
But it doesn't seem to update properly. Date functions aren't my thing at all!
Heres my function (could be alot tidier, but want to make it work first!)
This function seems to work for months and days which do not have a proceeding '0' - so for 18 dec 1967 it would work fine, but if I choose a month or day such as 7 jan 1967 it will not - but I thought the date format wants leading zeros 
1) How do you determine whether an INSERT or UPDATE was successful? I had a look and thought it was done via mysql_num_rows but this doesn't seem to be working for me
e.g
Code: Select all
$ourquery = "INSERT INTO tableone (username, city) VALUES ('$username','$city')";
$excute = mysql_query($ourquery);
if (mysql_num_rows($excute ) > 0)
{
echo "success";
}
else
{
echo "could not enter details";
{
2) Inserting a date of birth into a date formatted MYSQL column (yyyy-mm-dd)?
I have drop down menus to choose date of birth, and then have a function that changes these 'pretty' months ('jan 'etc..) into plain numbers, e.g output would be.... 19970222 for 22 feb 1997
But it doesn't seem to update properly. Date functions aren't my thing at all!
Heres my function (could be alot tidier, but want to make it work first!)
Code: Select all
function convert_dob_to_mysqldate($year,$month,$day)
{
if ($month == "jan") {$output_month = 01;}
if ($month == "feb") {$output_month = 02;}
if ($month == "mar") {$output_month = 03;}
if ($month == "apr") {$output_month = 04;}
if ($month == "may") {$output_month = 05;}
if ($month == "jun") {$output_month = 06;}
if ($month == "jul") {$output_month = 07;}
if ($month == "aug") {$output_month = 08;}
if ($month == "sep") {$output_month = 09;}
if ($month == "oct") {$output_month = 10;}
if ($month == "nov") {$output_month = 11;}
if ($month == "dec") {$output_month = 12;}
if ($day == "1") {$output_day = 01;}
if ($day == "2") {$output_day = 02;}
if ($day == "3") {$output_day = 03;}
if ($day == "4") {$output_day = 04;}
if ($day == "5") {$output_day = 05;}
if ($day == "6") {$output_day = 06;}
if ($day == "7") {$output_day = 07;}
if ($day == "8") {$output_day = 08;}
if ($day == "9") {$output_day = 09;}
if ($day == "10") {$output_day = 10;}
if ($day == "11") {$output_day = 11;}
if ($day == "12") {$output_day = 12;}
if ($day == "13") {$output_day = 13;}
if ($day == "14") {$output_day = 14;}
if ($day == "15") {$output_day = 15;}
if ($day == "16") {$output_day = 16;}
if ($day == "17") {$output_day = 17;}
if ($day == "18") {$output_day = 18;}
if ($day == "19") {$output_day = 19;}
if ($day == "20") {$output_day = 20;}
if ($day == "21") {$output_day = 21;}
if ($day == "22") {$output_day = 22;}
if ($day == "23") {$output_day = 23;}
if ($day == "24") {$output_day = 24;}
if ($day == "25") {$output_day = 25;}
if ($day == "26") {$output_day = 26;}
if ($day == "27") {$output_day = 27;}
if ($day == "28") {$output_day = 28;}
if ($day == "29") {$output_day = 29;}
if ($day == "30") {$output_day = 30;}
if ($day == "31") {$output_day = 31;}
$output_date = $year.$output_month.$output_day;
return $output_date;
}