sfia Posted April 23, 2020 Share Posted April 23, 2020 Hi, I was just trying to post form data to MySQL and trying to also post value of logged in user? but that code below doesnt work..Do you see a typo? or is it done some other way? $uid =$_SESSION[ "uid" ]; $sql = "INSERT INTO Date (uid) VALUES (:uid)"; $query= $conn->prepare( $sql ); $query->execute( array( ':uid'=>$uid) ); Quote Link to comment https://forums.phpfreaks.com/topic/310638-user-entry-in-form/ Share on other sites More sharing options...
Barand Posted April 23, 2020 Share Posted April 23, 2020 Just telling us that something "doesn't work" doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/310638-user-entry-in-form/#findComment-1577154 Share on other sites More sharing options...
mac_gyver Posted April 23, 2020 Share Posted April 23, 2020 (edited) there's nothing technically wrong with the posted snippet of code. however - do you have php's error reporting set to E_ALL and display_errors set to ON, so that php would help you by reporting and displaying all the errors it detects? do you have error handling for all the database statements that can fail - connection, query, prepare, and execute, so that you would know if/why they are failing? the easiest way of doing this, taking just one line of code, is to use exceptions for errors and let php catch the exception where it will use its error related settings (see the point above) to control what happens with the actual error information. have you validated all the inputs (the session variable) before executing the code so that you know if the inputs have expected value(s)? have you determined if the posted code is even being executed by outputting a test message where these lines of code are at? Edited April 23, 2020 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/310638-user-entry-in-form/#findComment-1577155 Share on other sites More sharing options...
sfia Posted April 23, 2020 Author Share Posted April 23, 2020 Actually I got it figured now. Query was right. my column name is different on database side. I was getting HTTP 500 error. Quote Link to comment https://forums.phpfreaks.com/topic/310638-user-entry-in-form/#findComment-1577156 Share on other sites More sharing options...
sfia Posted April 23, 2020 Author Share Posted April 23, 2020 1 minute ago, mac_gyver said: there's nothing technically wrong with the posted snippet of code. however - do you have php's error reporting set to E_ALL and display_errors set to ON, so that php would help you by reporting and displaying all the errors it detects? do you have error handling for all the database statements that can fail - connection, query, prepare, and execute, so that you would know if/why they are failing? the easiest way of doing this, taking just one line of code, is to use exceptions for errors and let php catch the exception where it will use its error related settings to control what happens with the actual error information. have you validated all the inputs (the session variable) before executing the code so that you know if the inputs have expected value(s)? have you determined if the posted code is even being executed by outputting a test message where these lines of code are at? Thanks, its working now. Quote Link to comment https://forums.phpfreaks.com/topic/310638-user-entry-in-form/#findComment-1577157 Share on other sites More sharing options...
mac_gyver Posted April 23, 2020 Share Posted April 23, 2020 1 minute ago, sfia said: Actually I got it figured now. Query was right. my column name is different on database side. having error handling, using exceptions and php's error related settings, would have immediately told you about a column naming problem. Quote Link to comment https://forums.phpfreaks.com/topic/310638-user-entry-in-form/#findComment-1577158 Share on other sites More sharing options...
sfia Posted April 23, 2020 Author Share Posted April 23, 2020 OK, thanks, i will try to set it up Quote Link to comment https://forums.phpfreaks.com/topic/310638-user-entry-in-form/#findComment-1577159 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.