Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I've set up a web page to query a database based on a user search that returns database row values into an HTML table via PHP and jQuery. Next to each returned row sits a button that displays 'Add to wish list'. I'd like for this button to be able to add that given row to a table on another web page, and store it there whilst the user navigates and searches the database further, adding more rows to the new table if necessary.
I've looked into this and the best solution I've come up with so far seems to be utilising PHP to store a $session like shopping carts on web pages do. However most of the scripts on the web are far more complex than I'll need for this web page as it's not an e-commerce site.
Is there a simpler way to do this, perhaps in jQuery that on click of 'wishlist' simply appends the data from a row to an HTML table on another page in a similar fashion?
Probably you can use HTML5 WebStorage supported by about 87% of browsers click to see browsers support here http://caniuse.com/namevalue-storage. Otherwise you have to use PHP session or Database or something with Jquery as you said. You can follow this to learn basic about HTML 5 LocalStorage http://diveintohtml5.info/storage.html
Remember this feature only supports strings to save data. Use JSON.stringify() and JSON.parse() to parse and save array if you want. You can use some code like this
//To set user's selected wishlist
var wishlistarray = [];
wishlistarray[0] = 'save data in whatever way you like';
localStorage["wishlist"] = JSON.stringify(wishlistarray);
//To get previously saved user's wishlist
var wishlistarray = JSON.parse(localStorage["wishlist"]);
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm doing a web app with PHP in which users have different number of tabs in the menu depending on a certain number of things, one user can have one tab in the menu where another user has ten.
I've managed to dynamically generate the menu items but now I don't know how to create files (pages) where the user gets redirected once he presses on any of the menu tabs.
All these files look the same the only thing that changes are the text, just some strings.
Summing up, what I want to do is:
Generate and destroy files automatically when the user has to consult something
How to link the menu tabs (href) to them automatically
The best would be to use a PHP page as template you could call it.
Lets say for example a user is logged in and clicks the view data page (data.php)
on your link you could have something like this:
and in data.php:
<?php
$USER_ID = htmlspecialchars($_GET["id"])
//SQL Request to get user priviledge and authentificate
//OR
//Check the cookie session for information
if (user_priviledge == 0)
{
//
//Show only data for 0 users
//
}elseif (user_priviledge == 1) {
//
//Show only data for 1 users
//
}
?>
This may not be the solution you wanted but your question wasn't very clear either so if you need any other information make sure to bring more precision.
The condition which are using for tab use same condition to show page. But add that condition in your text.Because your text is changing not page I think.
I this this might help you.
since all files will look the same and only variables will change, you can create one php file and just send the necessary data when a user clicks on the tab to assign to the variables in that page. You do not need to keep on creating custom pages for each and every tab.
Provide some code which you have written for this so that we can help you further
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Similar to how you create a post in wordpress or even ask a question on this very website.
I want to know how to create a page by just filling out a form?
Here's what I know:
-I know how to make an html form
-I know how to place data in a database and take it out
-I know some php
What I don't know is how to to tie all of these things together. Please be as specific as possible and if you know of a tutorial on how to do this or you have the time to make a small example I would be very very grateful.
Thank you in advance for your time :-)
EDIT: To provide more details
I want to send data from a form (even a few text inputs would be enough) and for them to be placed in a page where I can display them.
And also that page should have an unique identifier so it gets stored similar to the questions on stack overflow where there is www.stackoverflow.com/posts/'identifiernumber'
And I would always to go back to that information provided I access the link which I assumed will be stored in the database.
Wordpress uses wysiwyg this is used to convert normal text into html code you can find jquery plugins for it.After user has entered the content of the page and hits submit. Wordpress directly stores the content in the database in HTML FORMAT . Now all it does is echo out the content stored in the database.
Now for the identifier , it should point out to the primary key of the database row where the content is stored. Wordpress stores a unique url as the identifier like the questions you asked is How to create a page using a form? php/html it will store it as how-to-create-a-page-using-a-form-php-html . This is then put in the href attribute of <a> tag , on click of this unique identifier it echo out the content of that row.
All you have to do now is make a form and textarea , apply the wysiwyg plugin on the textarea . Then onsubmit store the data in the database and also creating a unique identifier for it.
You question now is how to pass the identifier in the URL?
First you must know how to pass a variable in the URL and then capture it in the required place eg : www.yourwebsite.com?identifier=something and to make this a link on you website
Something
Once you have mastered this you can then study a concept called MOD REWRITE and in layman term for this is called clean URL or SEO URL . There are many blogs and methods of achieving this goal. You can google MOD REWRITE and SEO URL.
Create your website theme
on first page create form like you want
concept is like registration form and second page is edit profile
now what you stored in database from registration form
now echo in your edit profile form
for example username in database can be viewed in edit profile form
select * FROM registrationtable WHERE userid='$userid'
then store values in variables like for example
while ($query = mysql_fetch_array($request))
{
$username = $query['username'];
}
<input type="text" name="username" value="<?php echo $username; ?>"/>
p.s dont use mysql better options are mysqli and PDO
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have a simple page that shows 4 different divs, all with a <h1> title (or other tag that shows text) and a form (with 1 input text) and a submit button... so far so good.
My answer is simple: I am looking for a way that:
when the user inserts a text and submit the form, the <h1> title shows the text that the user wrote
the form disappear (or takes style display:none)
this will take effect even if I refresh the page or view page in a different computer (probably need to save the data in a DB)
restart this process from the beginning (even if I need to code again).
This is for a mini game to provide to users 4 different choices and, if the user A select option 1, the <h1> will show text something like "User A was the first to choose this option. Please select a blank option" and, after the 1st raw over (point 4 described above), restart all forms.
NOTE: I am not asking in the way to "please do the code for me". I also searching for a way to store data in <php ?> - finding redbeanphp project.
I am also a newbie in SQL (just started to study SQLi last month to android development). My question is ONLY to looking for the best way to do this and what I need.
This would be the workflow:
When you click a button to submit the form JavaScript will send the form data to the server as an AJAX request and wait for a response from the server.
The PHP code on the server will read the data from the AJAX request and save it in a database and echo a success response along with the text to display.
Your JavaScript will receive this success message and hide form from the DOM and display the text in the header.
If you want the data to persist on the page on reload then you can save a flag in PHP session. Sessions persist in until you close browser window.
4.1 Use another AJAX call remove the flag from the session and reload the content.
So, if you are good with HTML and CSS you need:
JavaScript, AJAX, a JavaScript library to make things easier such as JQuery.
A server side language such as PHP.
A database to persist data. There are many choices. I am going to recommend MySQL just because there so many tutorials for it out there.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a very simple site (PHP) that allows user changes (via jQuery) that modify elements' classes, and add/delete rows from a table.
I want to write these changes to the actual PHP file in question on the server every time a user makes a change, so that when the page is refreshed or revisited, the changes remain intact.
What's the simplest / best way to accomplish this? Thank you!
For addition/deletion of rows, fire ajax call and update records associated with the user. This is in addition to client-side (jQuery/JavaScript) changes to page. Whenever they revisit/refresh the page, data will be fetched from db, and as such will always be latest.
When you say that users modify elements' classes, I assume you mean their page's looks and styling (like some sites have on-page options to change background color, font-sizes). If that is the case, I suggest you:
Create a list of all possible states and store them in a new table in db, say display_options. You could store details like option_type (e.g. background color, font-size etc) and option_back_value (e.g. #FFF, #000 etc).
Create a new table say user_display_options where you store things like user_id, option_type and their chosen option_id.
While loading page, do a join on these tables using user_id. Then while creating your page, conditionally add classes etc to the page.
When user edits page, fire ajax call sending required data like user_id, option_type, option_id. As mentioned for other task, these changes to db will be in addition to client-side changes.
Also read #David 's comment to your question - it clears an important concept.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 months ago.
Improve this question
I doubt I'm using the correct vocabulary (or tags) to explain what I'm looking for, but bear with me:
Eventually part of my page will have a section where things like list items and table data(<td>) can be entered/changed by logged in users. Let's say this is one of the <li>'s:
<!--template-->
<li><a title=""href=""><span></span></a></li>
So far my understanding is that if these entries are generated by a UI somewhere (à la Wordpress) these entries need(?) to be written in a database before becoming the generated page. Another thing I'm realizing is that the user of these CMS's doesn't automatically 'get' a copy of the generated page as source code.
What I would like to know is if it would be possible for me to make changes in HTML to this generated record/list inside notepad (I'll likely be messing with some other part of the page) and somehow have the site detect/record any changes as if they were entered through the UI?
Have PHP code create a file of the generated page
Have that page scanned for certain patterns/templates
Add the values found within the template to the DB, repeat
What language/approach could scan text and make database entries from its findings like how I'm describing? I just discovered sscanf(), but have no idea how to use it yet. I realize it's stupid to not just use the CMS, but the self-referential and text-scanning quality of it also interests me.
It sounds to me like you can implement a jQuery "Edit in Place" plug-in with a php script handler. I did something exactly this and their plug-in does all the heavy lifting, all you have to do is feed out the raw HTML with various clues about the table structure.
See this SO q/a... I used it to generate pages that displayed orders. Via editing in place, I made the orders (click-to-edit)-able. In the code, put everything in a foreach loop, then the jQuery links elements to the database through attributes like <tr id="<? echo $database_ID ?>"> to tie a row to a record and each <td> might have the database's column name as ID or a class name.
Let me preface this answer by saying it's almost certainly a bad idea, only tangentially relates to PHP, and creates at least as many problems as it solves. In particular, the security loopholes are terrible. But recently I saw an HTML form on a government website that reinvigorated my sense of humour about "lateral thinking", so just call me Pandora.
Theoretically you could implement something like this with a bit of Javascript and a cross-domain <form> post. In a nutshell, you would:
Create an HTML template with all of the tables, lists and other structures you require, plus a <form> containing a hidden input and a submit button. This template would be populated with data by the server application when the user initially requests a particular record.
Create a script for the template that parses the tables and lists for values (say, with DOM methods), serializes them (eg, into a JSON string), and sets the value of the form's hidden input to the serialized data.
Set the form's action attribute to a PHP script designed to deserialize the form data and persist it to a database. Also assign an event handler on the submit button that executes the serializer script before the form is posted.
Now, the trick here is in the user sequence. The user requests some record, which the server returns in a populated template. Ordinarily, a user would work with whatever CMS-style fields the template provides, but expiredninja instead saves the HTML source of the page, makes changes to the designated tables and lists, opens the modified HTML file in a browser, and clicks submit. The script serializes the data and the client posts the form to the server, which deserializes and saves the data.