How to read and write into the database (with a page)

How to read and write into the database (with a page) 1.0

No permission to download

Fuhrmann

Well-known member
Fuhrmann submitted a new resource:

How to read and write into the database (with a page) (version 1.0) - I'll teach you how to read and write to the database using XenForo.

Step 1 - Setting the table

To start we must know what are the fields that we use to read/write in the database. That is, the fields that will store the information we want to read later.

I'll start setting the table name, fields and types of each:

Table:
xf_simple_text

Fields:

simple_id -> The autoincrement field of each row.
simple_text -> This is the field that will contain our written text. Type: varchar; Lenght: 200;...

Read more about this resource...
 
Fuhrmann updated How to read and write into the database (with a page) with a new update entry:

Part 2

Step 6 - The Controller

We want save and read in our table, right? Yes! Note that these are two actions.

To define actions, we use Controllers . But what is this thing?


Controller (XenForo_Controller) - Handle user interaction, work with the model, and ultimately select a view to render that displays UI. In an MVC application, the view only displays information; the controller handles and responds to user input and interaction. E.G.:...

Read the rest of this update entry...
 
On step 10 you have to add
PHP:
<input type="hidden" name="_xfToken" value="{$visitor.csrf_token_page}" />

Otherwise you get a security error.
IDK if there's another work around but I just searched the error and that's the line that seems to be suggested to solve the security error.

Great tutorial :)
 
I managed to get this to write, however when it tries to read it seems as if it's trying to add my subdomain on it as well. I changed all the Simpletexts to my addon name "mcstore".

"dev" is my subdomain. Everything is hosted locally.

Here is my error.
Code:
The following error occurred:
 
Mysqli prepare error: Table 'dev.xf_mcstore_text' doesn't exist
Zend_Db_Statement_Mysqli->_prepare() in Zend/Db/Statement.php at line 115
Zend_Db_Statement->__construct() in Zend/Db/Adapter/Mysqli.php at line 381
Zend_Db_Adapter_Mysqli->prepare() in Zend/Db/Adapter/Abstract.php at line 478
Zend_Db_Adapter_Abstract->query() in XenForo/Model.php at line 218
XenForo_Model->fetchAllKeyed() in mcstore/Model/mcstore.php at line 19
mcstore_Model_mcstore->getAllmcstore() in mcstore/ControllerPublic/MCStore.php at line 34
mcstore_ControllerPublic_mcstore->actionRead() in XenForo/FrontController.php at line 310
XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 132
XenForo_FrontController->run() in C:/xampp/htdocs/dev/index.php at line 13

So is there anyway I can change it so that it doesn't read from the subdomain, or set it to an IP?
 
I managed to get this to write, however when it tries to read it seems as if it's trying to add my subdomain on it as well. I changed all the Simpletexts to my addon name "mcstore".

"dev" is my subdomain. Everything is hosted locally.

Here is my error.
Code:
The following error occurred:
 
Mysqli prepare error: Table 'dev.xf_mcstore_text' doesn't exist
Zend_Db_Statement_Mysqli->_prepare() in Zend/Db/Statement.php at line 115
Zend_Db_Statement->__construct() in Zend/Db/Adapter/Mysqli.php at line 381
Zend_Db_Adapter_Mysqli->prepare() in Zend/Db/Adapter/Abstract.php at line 478
Zend_Db_Adapter_Abstract->query() in XenForo/Model.php at line 218
XenForo_Model->fetchAllKeyed() in mcstore/Model/mcstore.php at line 19
mcstore_Model_mcstore->getAllmcstore() in mcstore/ControllerPublic/MCStore.php at line 34
mcstore_ControllerPublic_mcstore->actionRead() in XenForo/FrontController.php at line 310
XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 132
XenForo_FrontController->run() in C:/xampp/htdocs/dev/index.php at line 13

So is there anyway I can change it so that it doesn't read from the subdomain, or set it to an IP?
Well it's in the first line- the table does not exist in the database you are trying to read from.
I'm not sure what else you're talking about with subdomains and such. I'm not sure if that really matters if the config file is pointed to correctly and the table name is correct.

Is the table name "xf_simple_text" the same in the read and write databases? I suspect there might be a slight typo in your select table_name in the first few instructions of the tutorial.

And I'm not trying to be mean. I'm also wondering if you did create the database xf_mcstore_text? Is it there?

Make sure all the table_names are correct basically!
 
Well it's in the first line- the table does not exist in the database you are trying to read from.
I'm not sure what else you're talking about with subdomains and such. I'm not sure if that really matters if the config file is pointed to correctly and the table name is correct.

Is the table name "xf_simple_text" the same in the read and write databases? I suspect there might be a slight typo in your select table_name in the first few instructions of the tutorial.

And I'm not trying to be mean. I'm also wondering if you did create the database xf_mcstore_text? Is it there?

Make sure all the table_names are correct basically!
My table "xf_mcstore_text" is there, but the code is for some reason trying to add "dev" infront of it.
 
Hello, here:

1kTNK


I have an error:

1kTOk



Is this normal please ?
 
I know this is quite a bump, but I'm trying to do this and getting a security error (even though I've included "<input type="hidden" name="_xfToken" value="{$visitor.csrf_token_page}" />" in the HTML section for the page. Any ideas how I can fix the security error?

Thank you!
 
I know this is quite a bump, but I'm trying to do this and getting a security error (even though I've included "<input type="hidden" name="_xfToken" value="{$visitor.csrf_token_page}" />" in the HTML section for the page. Any ideas how I can fix the security error?

Thank you!
what's the exact error?
 
could you provide the code you used?
I believe I followed all the instructions perfectly (actually copy and pasted the code step by step), only thing I changed is adding the security token as mentioned earlier in the thread.

Code:
<input type="hidden" name="_xfToken" value="{$visitor.csrf_token_page}" />
 
<ul class="tabs Tabs" data-panes="#simpleTextPanes > li">
<li class="active"><a href="{$requestPaths.requestUri}#write">Write</a></li>
<li><a href="{$requestPaths.requestUri}#read">Read</a></li>
</ul>
<ul id="simpleTextPanes">
<li id="write">
<form action="{xen:link 'simpletext/write'}" method="post" class="xenForm">
<dl class="ctrlUnit">
<dt><label for="ctrl_message">{xen:phrase message}:</label></dt>
<dd><textarea name="simple_text" class="textCtrl Elastic" id="ctrl_message" rows="5"></textarea></dd>
</dl>
<dl class="ctrlUnit submitUnit">
<dt></dt>
<dd><input type="submit" value="{xen:phrase send_message}" accesskey="s" class="button primary" /></dd>
</dl>
</form>
</li>
 
<li id="read" class="profileContent" data-loadUrl="{xen:link simpletext/read}">
<span class="jsOnly">{xen:phrase loading}...</span>
</li>
</ul>
 
I believe I followed all the instructions perfectly (actually copy and pasted the code step by step), only thing I changed is adding the security token as mentioned earlier in the thread.

Code:
<input type="hidden" name="_xfToken" value="{$visitor.csrf_token_page}" />
 
<ul class="tabs Tabs" data-panes="#simpleTextPanes > li">
<li class="active"><a href="{$requestPaths.requestUri}#write">Write</a></li>
<li><a href="{$requestPaths.requestUri}#read">Read</a></li>
</ul>
<ul id="simpleTextPanes">
<li id="write">
<form action="{xen:link 'simpletext/write'}" method="post" class="xenForm">
<dl class="ctrlUnit">
<dt><label for="ctrl_message">{xen:phrase message}:</label></dt>
<dd><textarea name="simple_text" class="textCtrl Elastic" id="ctrl_message" rows="5"></textarea></dd>
</dl>
<dl class="ctrlUnit submitUnit">
<dt></dt>
<dd><input type="submit" value="{xen:phrase send_message}" accesskey="s" class="button primary" /></dd>
</dl>
</form>
</li>
 
<li id="read" class="profileContent" data-loadUrl="{xen:link simpletext/read}">
<span class="jsOnly">{xen:phrase loading}...</span>
</li>
</ul>
needs to be included in the <form></form> somewhere. Personally, I put the security line after the submit input.
If that doesn't work I'm not sure what went wrong lol
 
Hello, possible to cache Xenforo integration with symfony2 ?
 
Top Bottom