shturm681 Posted January 27, 2010 Share Posted January 27, 2010 Hi all, As this is my first topic here and I am a beginner web developer, any outside of the current topic critiques will be valued. To the problem... I post data from a.php to b.php and in b.php I can access the values only with the $_POST function, assigning them to local variables doesn't really work. Here are the main problem parts of b.php: $ordEnterprise = $_POST['ordEnterprise']; $ordBulstat = $_POST['ordBulstat']; $ordVAT = $_POST['ordVAT']; $ordAddress = $_POST['ordAddress']; $ordReciever = $_POST['ordReciever']; $ordContactPerson = $_POST['ordContactPerson']; $ordTel = $_POST['ordTel']; $ordMail = $_POST['ordMail']; $ordParticipationAddress = $_POST['ordParticipationAddress']; $ordProduct = $_POST['ordProduct']; $ordProductDetails = $_POST['ordProductDetails']; $ordSum = $_POST['ordSum']; $ordRemoteAddress = $_POST['ordRemoteAddress']; $ordDateOfOrder = $_POST['ordDateOfOrder']; $ordComment = ''; //...bla bla bla bla... checking for user fraud, validating the values etc... //have this query string to insert the validated data to a mysql database $query = "INSERT INTO $dbtable (`ID`, `ordEnterprise`, `ordBulstat`, `ordVAT`, `ordAddress`, `ordReciever`, `ordContactPerson`, `ordTel`, `ordMail`, `ordParticipationAddress`, `ordProduct`, `ordProductDetails`, `ordSum`, `ordRemoteAddress`, `ordDateOfOrder`,`ordComment`) VALUES (NULL, '$_POST[ordEnterprise]', '$ordBulstat', '$ordVAT', '$ordAddress', '$ordReciever', '$ordContactPerson', '$ordTel', '$ordMail', '$ordParticipationAddress', '$ordProduct', '$ordProductDetails', '$ordSum', '$ordRemoteAddress', '$ordDateOfOrder', '$ordComment');"; //...blablablabla, user is informed about his order status etc The problem is, the mysql entries in the table are EMPTY. Nulls, nothing, nada ! Later in the b.php script I echo the posted data in a different view, more convinient for the user: <table> <tr> <td>Наименование на предприятието</td> <td><?php echo $_POST['ordEnterprise']; ?></td> </tr> <tr> <td>Булстат</td> <td><?php echo $_POST['ordBulstat']; ?></td> </tr> <tr> <td>Регистрация по ДДС</td> <td><?php echo $_POST['ordVAT']; ?></td> </tr> <tr> <td>Адрес на регистрация</td> <td><?php echo $_POST['ordAddress']; ?></td> </tr> <tr> <td>Получател на фактурата</td> <td><?php echo $_POST['ordReciever']; ?></td> </tr> <tr> <td>Лице за контакт</td> <td><?php echo $_POST['ordContactPerson']; ?></td> </tr> <tr> <td>Телефон</td> <td><?php echo $_POST['ordTel']; ?></td> </tr> <tr> <td>E-Mail</td> <td><?php echo $_POST['ordMail']; ?></td> </tr> <tr> <td>Адрес за кореспонденция</td> <td><?php echo $_POST['ordParticipationAddress']; ?></td> </tr> <tr> <td>Продукт</td> <td><?php echo $_POST['ordProduct']; ?></td> </tr> <tr> <td>Детайли</td> <td><?php echo $_POST['ordProductDetails']; ?></td> </tr> <tr></tr> <tr> <td><b>Сума за плащане</b></td> <td><?php echo '<b>' . $_POST['ordSum'] . ' лева</b>'; ?></td> </tr> </table> AND THE DATA IS DISPLAYED ! So, I can reach my values via the $_POST function, but can't assign it to local variables ? I echoed just to test some of the variables like echo $ordEnterprise; and it showed nothing - so the locals ARE empty/nulls. I tried assigning values manually like $ordEnterprise = 'asdf'; echo $ordEnterprise; and it was displayed! I just can't figure it out.. The query is successful, the data is displayed via $_POST, but when say $localVariable = $_POST['someVariable']; my variable stays empty The scripts are direct content of joomla articles, if it is important (I have a plugin allowing PHP proccession in articles), each script in a separate article. I was confused if I had to post in the CMS section, but the problem is more like for this one. If needed, I can display the whole content of script b.php (and/or a.php) Any help is highly appreciated Your hopeless web commrade, Alex Quote Link to comment https://forums.phpfreaks.com/topic/189970-_posted-data-cannot-be-assigned-to-local-variables-wtf/ Share on other sites More sharing options...
teamatomic Posted January 27, 2010 Share Posted January 27, 2010 Why are you using backticks? Use single quote instead. HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/189970-_posted-data-cannot-be-assigned-to-local-variables-wtf/#findComment-1002453 Share on other sites More sharing options...
akitchin Posted January 27, 2010 Share Posted January 27, 2010 no, you'll want to either stick with the backticks or remove the backticks. changing to single quotes will likely jog an error if placed in the column list. have you checked that your validation functions don't change the values of the local variables? and have you checked whether some unescaped characters are causing your issues? have you tried echoing the local variables AND the query before you actually run them? Quote Link to comment https://forums.phpfreaks.com/topic/189970-_posted-data-cannot-be-assigned-to-local-variables-wtf/#findComment-1002454 Share on other sites More sharing options...
PFMaBiSmAd Posted January 27, 2010 Share Posted January 27, 2010 //...bla bla bla bla... checking for user fraud, validating the values etc... I'm going to go with with a guess that there is some code like - if($var = ''){... ...} instead of code that should be - if($var == ''){... ...} Quote Link to comment https://forums.phpfreaks.com/topic/189970-_posted-data-cannot-be-assigned-to-local-variables-wtf/#findComment-1002473 Share on other sites More sharing options...
shturm681 Posted January 28, 2010 Author Share Posted January 28, 2010 I solved it myself ! The problem was that in b.php I directly wrote the html, when needed instead of echoing it. So my script was like <?php code,code,doing php stuff... ?> <table> <!--- display some stuff ---> </table> <?php PHP coding again... ?> etc. So when assigned the variables in the 1st section of the file, they seemed to be available only there, but not within the other PHP tags. Thank you everybody Have a nice day ! Quote Link to comment https://forums.phpfreaks.com/topic/189970-_posted-data-cannot-be-assigned-to-local-variables-wtf/#findComment-1002962 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.