jamesmcd87 Posted May 21, 2009 Share Posted May 21, 2009 Hiya, Working on a site using PHP and MySQL but I am having difficulty with a simple INSERT statement, originaly it was much bigger but I made it simpler to trouble-shoot. Running PHP 5 on IIS6 with MySQL 5. I know I am connected because I can retrive row data. I am not getting any errors. mysql_query("INSERT INTO users (family_name) VALUES ('$family_name')"); Unfortunetely there isnt much more I can share about this problem, hoping someone out there will be able to share some clues. Regards James Quote Link to comment Share on other sites More sharing options...
waynew Posted May 21, 2009 Share Posted May 21, 2009 Try ysql_query("INSERT INTO users (family_name) VALUES ('$family_name')") or trigger_error(mysql_error()); And see what you get. Quote Link to comment Share on other sites More sharing options...
madspof Posted May 21, 2009 Share Posted May 21, 2009 Is there a value already in the field? Quote Link to comment Share on other sites More sharing options...
jamesmcd87 Posted May 21, 2009 Author Share Posted May 21, 2009 Thanks for the quick reply but it didnt do anything at all. Try ysql_query("INSERT INTO users (family_name) VALUES ('$family_name')") or trigger_error(mysql_error()); And see what you get. Quote Link to comment Share on other sites More sharing options...
jamesmcd87 Posted May 21, 2009 Author Share Posted May 21, 2009 Sorry mate, not exactly sure what you mean. Is there a value already in the field? Quote Link to comment Share on other sites More sharing options...
madspof Posted May 21, 2009 Share Posted May 21, 2009 Ok fore example the field that your trying to update with a value if it already has a number or charachter in using insert will not work you have to use the mysql command UPDATE Quote Link to comment Share on other sites More sharing options...
jamesmcd87 Posted May 21, 2009 Author Share Posted May 21, 2009 Oh right, no, there is nothing in the field. I am trying to INSERT it as a new row. Ok fore example the field that your trying to update with a value if it already has a number or charachter in using insert will not work you have to use the mysql command UPDATE Quote Link to comment Share on other sites More sharing options...
madspof Posted May 21, 2009 Share Posted May 21, 2009 ok are you not getting any error or notic from the script? try using this mysql_query("INSERT INTO users (family_name) VALUES ('$family_name')"); Quote Link to comment Share on other sites More sharing options...
jamesmcd87 Posted May 21, 2009 Author Share Posted May 21, 2009 I am not getting any errors whatsoever. The only thing I can think of is that it may be some sort of config problem, this is the first time I have used PHP and mySQL under IIS and it took me about a week to get it all running thanks to MS :-) I have used PHP and MySQL statement thousands of times under WAMP. This problem is really quite puzzling. Your code didnt do any better I'm afraid. ok are you not getting any error or notic from the script? try using this mysql_query("INSERT INTO users (family_name) VALUES ('$family_name')"); Quote Link to comment Share on other sites More sharing options...
madspof Posted May 21, 2009 Share Posted May 21, 2009 can you paste any more code to me maybye all of it ? Quote Link to comment Share on other sites More sharing options...
jamesmcd87 Posted May 21, 2009 Author Share Posted May 21, 2009 Here is the whole page, <?php //include("inc/db_class.php"); include("inc/generate_userid.php"); mysql_connect("localhost", "root", "*******"); mysql_select_db("ghl"); //$dbconn = new database; $generate_userid = new generate_userid; $title = $_POST['title']; $first_name = $_POST['first_name']; $family_name = $_POST['family_name']; $email_address = $_POST['email_address']; $street_address = $_POST['street_address']; $suburb = $_POST['suburb']; $state = $_POST['state']; $zip_code = $_POST['zip_code']; $home_phone = $_POST['home_phone']; $work_phone = $_POST['work_phone']; $mobile_phone = $_POST['mobile_phone']; $occupation = $_POST['occupation']; $lender = $_POST['lender ']; $interested_in_investing = $_POST['interested_in_investing']; $find_us = $_POST['find_us']; $user_id = $generate_userid -> userid($family_name); if(isset($_POST['frm_membership'])) { $submit = "membership"; $signup_date = date("Y-m-d"); $have_home_loan = $_POST['have_home_loan']; $use_mortgage_broker = $_POST['use_mortgage_broker']; $password = $_POST['password']; } elseif(isset($_POST['frm_coachreq'])) { $submit = "coachreq"; $coach_req = "yes"; $date_req = date("Y-m-d"); $long_home_loan = $_POST['long_home_loan']; $purpose_of_loans_seeking = $_POST['purpose_of_loans_seeking']; $amount_borrowing = $_POST['amount_borrowing']; $current_loan_balance = $_POST['current_loan_balance']; $approx_value_property = $_POST['approx_value_property']; $comb_household_income = $_POST['comb_household_income']; $have_cred_probs = $_POST['have_cred_probs']; $rate_cred = $_POST['rate_cred']; $coach_comments = $_POST['coach_comments']; $accept_terms = $_POST['accept_terms']; $hqaccess = $_POST['hqaccess']; } if($submit == 'membership') { echo "membership"; echo $user_id; mysql_query("INSERT INTO users (family_name) VALUES ('$family_name')"); } elseif($submit == 'coachreq') { echo "coach"; if($hqaccess == 'true') { $password = $_POST['password']; echo "both"; } } ?> can you paste any more code to me maybye all of it ? Quote Link to comment Share on other sites More sharing options...
madspof Posted May 21, 2009 Share Posted May 21, 2009 I cant see the variable $family_name in that script are you sure it is there or am i missing it ? Quote Link to comment Share on other sites More sharing options...
madspof Posted May 21, 2009 Share Posted May 21, 2009 ok forgot that i can sorry lol and echo the variable before the mysql insert to make sure it is in there and then we know if it is a problem with the database. Quote Link to comment Share on other sites More sharing options...
jamesmcd87 Posted May 21, 2009 Author Share Posted May 21, 2009 I am definitely receiving it because I use it as part of the 'generate_userid' class and that is working as expected. ok forgot that i can sorry lol and echo the variable before the mysql insert to make sure it is in there and then we know if it is a problem with the database. Quote Link to comment Share on other sites More sharing options...
madspof Posted May 21, 2009 Share Posted May 21, 2009 ok can you tell me the field you have in your data base and what the table is and ill make a script that definitely works and you can run that to find out once and for all if your database is working or not Quote Link to comment Share on other sites More sharing options...
jamesmcd87 Posted May 21, 2009 Author Share Posted May 21, 2009 here is the sql CREATE TABLE IF NOT EXISTS `users` ( `user_id` varchar(20) NOT NULL, `signup_date` date NOT NULL, `coach_req` text NOT NULL, `date_req` date NOT NULL, `title` text NOT NULL, `first_name` text NOT NULL, `family_name` text NOT NULL, `email_address` text NOT NULL, `street_address` text NOT NULL, `suburb` text NOT NULL, `state` text NOT NULL, `zip_code` text NOT NULL, `home_phone` text NOT NULL, `work_phone` text NOT NULL, `mobile_phone` int(11) NOT NULL, `occupation` int(11) NOT NULL, `have_home_loan` text NOT NULL, `long_home_loan` text NOT NULL, `lender` text NOT NULL, `use_mortgage_broker` text NOT NULL, `interested_in_investing` text NOT NULL, `find_us` text NOT NULL, `purpose_of_loan_seeking` text NOT NULL, `amount_borrowing` text NOT NULL, `current_loan_balance` text NOT NULL, `approx_value_property` text NOT NULL, `comb_household_income` text NOT NULL, `have_cred_probs` text NOT NULL, `rate_credit` text NOT NULL, `coach_comments` text NOT NULL, `accept_terms` text NOT NULL, `password` text NOT NULL, PRIMARY KEY (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; ok can you tell me the field you have in your data base and what the table is and ill make a script that definitely works and you can run that to find out once and for all if your database is working or not Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 21, 2009 Share Posted May 21, 2009 The trigger_error() code that was suggested, which isn't in the code you posted anyway, assumes (i.e. make an ass out of u and me) that the error_reporting and display_errors settings are such that the resulting error would be displayed or logged. For debugging, add the following two lines of code immediately after your first opening <?php tag - ini_set("display_errors", "1"); error_reporting(E_ALL); And change your query to the following - mysql_query("INSERT INTO users (family_name) VALUES ('$family_name')") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
jamesmcd87 Posted May 21, 2009 Author Share Posted May 21, 2009 OK, getting somewhere... Notice: Undefined index: lender in C:\Inetpub\wwwroot\20090429_GHL\process_membership.php on line 30 membership20090521-1426-DSFField 'user_id' doesn't have a default value The trigger_error() code that was suggested, which isn't in the code you posted anyway, assumes (i.e. make an ass out of u and me) that the error_reporting and display_errors settings are such that the resulting error would be displayed or logged. For debugging, add the following two lines of code immediately after your first opening <?php tag - ini_set("display_errors", "1"); error_reporting(E_ALL); And change your query to the following - mysql_query("INSERT INTO users (family_name) VALUES ('$family_name')") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 21, 2009 Share Posted May 21, 2009 The first error is likely because you have a space after the r and before the closing single-quote in the following - $lender = $_POST['lender ']; The second error is because you have declared user_id as a primary key but you have not supplied a value for it in the query or defined a default value in the table definition. Quote Link to comment Share on other sites More sharing options...
jamesmcd87 Posted May 21, 2009 Author Share Posted May 21, 2009 Ok, awesome, sorted mate. Cheers for everyones assistance. The first error is likely because you have a space after the r and before the closing single-quote in the following - $lender = $_POST['lender ']; The second error is because you have declared user_id as a primary key but you have not supplied a value for it in the query or defined a default value in the table definition. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.