Hi I'm using a WordPress Theme which appears to be doing something weird. I'm fairly new to the PHP side of things more familiar with older ASP stuff and can't seem to wrap my head around it or find anything on it either.
I'm using a prepared statement to insert text from a textarea into the database and also to pull back the information back into the textarea. Since I'm using a prepared statement I think I'm correct in that I don't need to escape any characters etc. and can insert just as is?
The problem I'm having is when the text from the database is being displayed inside of the textarea, it's obtaining some formatting somehow. Mainly it's open and closing p tags, this doesn't happen though when I create a test page outside of the theme. I did notice that the ' and " are being escaped I guess by the prepared statement?
All I'm doing is using echo between the open and close textarea where the value goes in both situations but I'm getting different results. What I don't get is how the theme could be overwriting my value at the time I overwrite in server side code? Are there some kind of events inside of PHP that could be capturing this with a function from the theme?
Right now the only way I can figure out to work around this is to create a separate page that echo's the information for that field and if I pull it back with ajax in JQuery it looks the way it should but there is a small delay for the box to load which I don't like…
I appreciate any help I can get here ahead of time…
Related
Right this has been asked before in similar context but the answer was not given.. I need to know how to change the contents of "homepage.php" (Example) PERMANENTLY by filling out a form on the webpage itself, I know I have to store data in MySQL database but how should I go about doing this (which way). I know how to store and retrieve data but just this particular problem has me baffled.
Do I save single css values into the database (e.g. blue, green, margin-left, margin-right) or can I store a whole css block of code as a variable then save it in the database
|| body { //Content of body } .navbar{ //navbar content here }? ||
End result I need is to edit a page without altering the code so that everyone can see it not just by using cookies. (Please do not tell me about needing a server ETC I know..)
I am using the Procedural method of PHP programming with no framework for those seeking to give an example.
Thanks in Advance =D!
I would post a comment but I don't have enough points to comment.
Would you be able to utilize jQuery for the webpage? I have had to do this exact same thing with php/mysql, and using jQuery .css() and .html() provides a working solution.
I'm trying to realize a dynamic website for exercise. All contents are stored in the database:
I included html code(FORMS) as DB content with no ploblem, but when i try to insert php code as DB content nothing happens. The field type for Content is TEXT.
I tryed various ways :
INSERT INTO TableContent(Name_Content, Content, ID_Menu) values ("Amministration Area", "<?php include('LogIn.php')", 5);
INSERT INTO TableContent(Name_Content, Content, ID_Menu) values ("Amministration Area", "<?php include(\"LogIn.php\")", 5);
In the website page i see Amministrazion Area, but not what Login.php does.
I thought i made a mistake in Login.php page code so i changed it in a simply echo ("Hi"); but nothing appears anyway. I see only the text Amministration Area.
How can i solve it ?
It's just text! Text in a database. Nothing happens when you just insert text into a database and read from it. You have to actually get something to execute that text as PHP code. That doesn't happen automatically, thankfully! In PHP, the way to execute arbitrary strings as code is by using eval. But this is overall a very bad idea; storing all PHP code in a database is not making anything easier, on the contrary it makes everything more difficult to work with and more prone to exploits if you execute arbitrary code. I'd advice you to stop doing that and go back to PHP code in .php files, not databases.
PHP see <?php include("LogIn.php");? as a string, when you look in the source code of your file, you'll probably see it. It doesn't show up on screen because it starts with a <.
To execute the code instead of handling it as a string, you can use the eval() function.
You however don't want every row of your database be seen as PHP code, so you'll probably need to add a extra column that defines what the row is, i.e. a string, php code. Or you make an extra table where you store your includes.
i'm working on an app that will have a listing of the data you've saved previously. if you have a typo, didn't enter all the data points originally, etc. you'll have the opportunity to edit the data chunk.
right now i have javascript getting the values of each element (that was created via foreach loop in php with data from the server) within a given chunk, saving it to an object and then replacing those elements (<p>) with textarea inputs then filling it with the data from the js object that grabbed it previously.
for one i'm having issues with escaping quotes from the dynamic content but also it feels like this may not be the most elegant solution.
in comes contenteditable.
basically: should i go that route and just make each of the elements in the data chunk contenteditable='true' on click of 'edit' button or is that too fishy with browser support?
is my current course a solid plan?
or is there a third (fourth, fifth, etc.) option?
thanks!
Unless you specifically need the user to edit HTML content (or do complex syntax hilighting etc), go with input/textarea solution. Much cleaner, much more lightweight and easier to do. Contenteditable gets complicated really quickly and using something like tinyMCE or similar would probably be an overkill.
If you've used JSfiddle, you know how well contentedible works. That's what they use. You can use a jQuery plugin for the syntax highlighting if you need it (Snippet, jquery-syntaxhighlighter).
So im doing a project and i have made a webpage, on this page i have a total value which is a float inside of a div called total. What i want to do is save this value to a database on my webspace (im hosted by 123 reg) so each user saves the total that they get and then the total in the database in the website is constantly updated and displayed again on the website as a "Global total".
I have no idea about how i would go about doing this any takers?
Ok so basically you might want to take a look at Javascript, especially how to submit a form using javascript:
http://www.javascript-coder.com/javascript-form/javascript-form-submit.phtml
Then you want to take a look on how to process this data in PHP.
The data should come in within the $_GET or $_POST variables.
And you might want to learn about SQL INSERT statements.
http://www.ntchosting.com/mysql/insert-data-into-table.html (somewhere around the bottom)
And then you might want to learn about using the MySQL SELECT-Statement. With that you can use a summation operation to get the sum of all totals and then using PHP echo that into the page again.
Or using AJAX you could load it into the page in a somewhat "live" action.
I'm new here and I'm very new at programming but I need some serious hand-by-hand help here.
I was searching jquery and found a script to drag and drop stuff on the screen, basicly i just want to move some divs around, thats the easy part, the script I found has a callback function that writes onto the div that you just moved "dropped", this is exactly what I need but instead of writting dropped I want to save the 2 postion variables into a database (mysql), this is so that if I close the browser and open it again the div's will be on the last place I dropped them.
Can you help? Is there a jquery user interface with this already built in ?
I think this is easy to do with jquery ajax functions right? basicly I should send the serialized data (json right?) into a page that processes that data once its feed into it, then jason returns the handler with success or even with some output right?
It would be cool for the dragabble div to have a handler with last know position retrieve by jason from an external page that acts like a buffer to the database.
Is this the correct pipeline?
Best Regards
Joricam
you have kind of a vague question here, but I can try to help you get closer to the answer.
Imagine two sides of the puzzle:
When the page loads, the two (or more) DIVs are drawn on the screen. If you want them to draw in a specific order, you need to keep track of that in the database. So be sure your db has a field called something like display_order, and then display the DIVs in that order. (You can usually just add ORDER BY display_order to the SQL, so they are retrieved in the order you want, and then draw the DIVs right out in a loop.)
When someone drags and drops a DIV, you use AJAX/JSON/etc to tell your PHP script the new order. In this case, when that happens, rather than draw the word 'dropped' in the DIV, you should instead immediately update the display_order fields in the database. This way you are remembering each DIV's position.
Does that help/make sense?
UPDATED: thinking more about your question, here is the pseudo code:
in "display.php":
Fetch the contents for each DIV from the database, with ORDER BY display_order on the rows.
Draw them on the screen, looping through each database row.
Also in this HTML, use the jQuery script you already have to call another PHP script (dragged.php) when a row is dragged.
in "dragged.php":
This script is called when a row is dragged on the screen.
Currently it puts the word "dropped" in the DIV that is dragged. That's not helpful, so remove that.
Instead, you now know (from the variables passed to you) that a specific DIV needs to be in a specific place.
So grab a list of the DIVs from the database, then change the order of them (by altering the display_order column) based on the new position(s) you know.
Save that back to the database, so when display.php is called again next time, it draws the DIVs in the order you want.
Hope this helps explain further. If you are still struggling, I respectfully suggest you try to write the code, and post a more specific question about the part that you're stuck on. This will help you get a good answer quickly. (You may also want to Google this one a lot; I'm sure there are code samples out there showing how to do all this.)