Jump to content

$_POSTed data cannot be assigned to local variables ? :wtf:


Recommended Posts

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 ! :confused:

 

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

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?

//...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 == ''){... ...}

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 !

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.