Jump to content

Recommended Posts

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) );

 

Link to comment
https://forums.phpfreaks.com/topic/310638-user-entry-in-form/
Share on other sites

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 by mac_gyver
Link to comment
https://forums.phpfreaks.com/topic/310638-user-entry-in-form/#findComment-1577155
Share on other sites

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. 

Link to comment
https://forums.phpfreaks.com/topic/310638-user-entry-in-form/#findComment-1577157
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.