How to make a user wish list in PHP - php

So, basically I'm making a little site that has some pages with video game's info and media. I have a user account system setup, but there's something I've been wanting to know how to add. I'm still new to PHP, and I made the user account system only by following a tutorial. Anyways, here's the HTML code that shows on a game info page when a user is logged in:
<form name="wishlistAdd" action="wish_list.php">
<input type="checkbox" name="wagakkiwa_wish" id="wagakkiwa_wish" />
<label for=wagakkiwa_wish>Add <b>WAGAKKIWA</b> to your Wish List?</label><br />
<input type="submit" class="button" value="Add to List" /> This is a alpha feature. It won't work currently.
</form></div>
Basically, what I'm wanting to achieve is if the user logged in checks the box then clicks 'Add to List' it will add it to a list in their User Account Home page under the section 'Wishlist.' For example, if I added that game to my wishlist and I went back to the /user/ section of the site, in the right column under 'Wishlist' it would show 'WAGAKKIWA' as an a tag to that page. Then, if I did it for another game it would add it ontop.
So, what would I need to do to accomplish this? Do I have to add a certain column to the user's table in my DB and have the posted items for the wishlist submitted and retrieved?
Any and all answers are appreciated, thank you.

for the table wishlist, the fields are : Id,UserIP, ProductsID
Id only autoincrement ID
UserIP to record visitor's IP
ProductsID to record ProductsID which cliked by visitor
After you click submit, then you must insert record to table wishlist, then to display you must select all table wishlist and left outer join with table product with ProductsID.
Hopefully you understand with my short explanation

Related

How to display updated field in MySQL in new textarea in php

I have a SQL Database where the users can create a ticket then update the ticket if need be. This all works and the user can view the updated field in the , but what I would to achieve is to display the newly updated field in a different textarea field but not be able to edit it and only edit a new textarea field. Once saved and the user needs to update it again it needs to then display the 2 uneditable textfields and display new textfield to update.
Here is my code what i have at the moment:
<div class="form-group col-lg-12 col-md-12 col-sm-12 <?php echo (!empty($description_err)) ? 'has-error' : ''; ?>">
<label>Description</label>
<textarea name="descriptionfield" class="form-control" required="required" placeholder="Enter Description"><?php echo $description; ?></textarea>
</div>
So with this code I can update and delete but only displays in the same textarea.
Can someone point me in the right direction to achieve this?
Hoping what I explained makes sense.
Thanks
Something like the below image
So you are only able to update and delete a textarea but you want to show the original one and a new empty text area after they submit, then if they update that one, the original one and second one show all while allowing a new textfield to be there?
You aren't creating the text-boxes, submitting queries, and fetching results in a way the allows you to do that.
What you need to do is:
In your general application you will need 2 things, the empty text area field for the which you already have. An empty div area where you could display the old text areas.
In your database you need to add another table because you you will basically be joining these child text area updates updates. new table: textareachildren.
When somebody submits a ticket, that text area information should go into your first table where the info is going which is already happening. Now I'm assuming your table for those posts has a primary ID correct? so lets say we just put a ticket in and the ID is 1. Here is where #Padmanabhan is trying to find out, when the ticket is submitted the page is refreshed correct? and it shows that ticket they just submitted?
Now they want to edit that ticket's text area, I assume you already are pulling in the ticket by it's ID. Since you said they could already edit/update but it just shows the value they submitted. It looks by your picture that theres a note added and new note section. OK so thats good, so within that function where they could update the ticket text area field, a few important things need to happen. Once they click update, you need to run a sql query to input this new textarea value into the textareachildren table. within that table there should be 3 columns, the primary ID of the new items in there, the value of the textarea field, and third the important the connecting_ID which is the same value of the ID of the original ticket ID. this is how they will be connected and you could display those historical text areas.
Now go back to your original query that displays the ticket when they first submit, in there you need to also query by joining the the original ticket id with the connecting_ID of the new child textarea. The query will say ah yes, I am pulling this textarea value from the other table because my connecting_ID is 1 and it matches my 'parents' so I know I belong to them. Then just display that in the html within a new text area field that does not have the option to update/edit, since its probably a for loop for all those children that you want to show, you could add in the HTML textarea disabled readonly attributes, and even add classes to it so its like grayed out or something that shows you can't edit.
So to summarize every time somebody updates the text field you aren't changing that original value since you want to display that, you just add this new child textarea field value in a new table, when you query to show those old values to you just join them and display those historical textareas how ever you want.

How to select and process the selected records from a list of displayed records in php and mysql

I have a php/mysql application in which I have a database broadly having the following fields:
Employee No.
Employee Name
Year of Joining
Location
Job Profile
I am able to display the records using the SELECT statement with no problem.
Now, I want to be able to do the following and this is where I need your help/suggestion on how to achieve it:
Select a few records randomly (using a checkbox or any other method suggested here) from the list of records displayed.
Have a button saying "Processed" on the screen. When I click on the button, the screen should refresh and the records selected in Step 1 above should be moved to another database and only the unchecked records should now be displayed.
Please let me know your suggestion on how to do the above.
Thanks
TS
For this you can use the id of the record, to get the information of the particular record using another single select query, and also can update the record with the id of the record. (create an edit link and pass the id, on edit page get the information with the id and save it.)
<?php //your db connection and select query here ?>
<form action="process.php" method="post" enctype="multipart/form-data">
<?php
// loop starts here
echo "<input type='checkbox' name='ids[]' value='".$row["id"]."' />";
// loop ends here
?>
<input type="submit" name="process" value="Processed"/>
</form>
This will create the checkboxes and on the process.php page
you can get the ids your need to process and can move your data
to other table/db where you want and after than redirect back to
to the page where your code is.

Saving dynamic list items efficiently

I have supermarkets stored in my database. For each supermarket, in an admin area the user can create a shopping list with products and keep track of the products by checking (= user has already bought the product) or unchecking them (= user still needs to buy the product). My question is how to efficiently store the shopping list items in MySQL?
My markup with example data:
<form>
<h1>Supermarket: "City Store"</h1>
<p>Create/edit your shopping list:</p>
<ul id="shopping-list">
<li><input type="text">Tomatoes</input> <input type="checkbox"></li>
<li><input type="text">Apples</input> <input type="checkbox" checked="checked"></li>
<li><input type="text"></input> <input type="checkbox"></li>
</ul>
<button id="add-list-item">Add list item</button>
<button id="save-list-items">Save</button>
</form>
$('#add-list-item').on('click', function() {
$('#shopping-list').append('<li> <input type="text"></input><input type="checkbox"></li>');
});
In this scenario, when the user logs in, he sees that in the past he already added two products to the list, tomatoes and apples. As he already has bought apples, he had checked them. If he wants to add products, he can press the button.
In my MySQL environment I already have a table "supermarkets". For storing the shopping list items I want to create an additional table "shopping-list-items" with the following fields:
- id
- id_supermarket
- content
- status (1 = 'checked', 0 = 'still unchecked')
- date_created
- date_updated
- date_checked
As you can see, I want the date of each list item being saved, for when it is being created, updated AND checked.
How can I send the data of the shopping list to my database via POST and distinguish between checked and unchecked items? I basically know how to send data via the name attribute to a database and to save them, but in this case I want to save each entry individually and at the same time consider the checkbox state and I have no idea how to handle that.

How to display MySQL results from previous page in PHP?

I'm doing a flight booking site with PHP for my assignment. The search page returns a table of related flight details from the key word that was entered. Then in the table it gives the option to choose only one flight to book. After selecting a certain flight by radio button and clicking "make booking for selected flight" button, the next page is required to display the flight details that have been selected from the previous page.
The problem is: how do I display the selected flight details?
I'm sure you did use the form for user to selected the appropriate options. Let's say:
<form action="nextpage.php" method="post">
<input type="radio" name="flight" value="flight1" />Option 1<br />
<input type="radio" name="flight" value="flight2" />Option 2<br />
......
<input type="submit" name="booking" value="Make Booking for the Selected Flight" />
</form>
Then on page nextpage.php you can get the flight that user have selected by using the php code below:
<?php
$flight = $_POST['flight'];
//do things u need here, for example
echo $flight;
?>
Pass some unique identifier from your flight to the details page via URL variable. To access those variables, simply use the PHP $_GET['id'] variable (in this case to access a url variable named id).
To pass an "id" url variable, simply append ?id=value to your redirect: http://page.com/details.php?id=5
Once you have this on your second page, it is very easy to do another MySQL query to retrieve the details from flight, say, 5 and display it on the second page.
You can use following method to send data on next page.
1) Session
2) Cookies
3) Get method
4) Post method(Using hidden fields).

Singleform with different database

I want to make a form in php where there will be two categories. One for the Student profile details and another for the student's
marks details. Now the main problem is all this will be in one single form means in one page and the categories like student details will be save in student detail table of the database and the marks will be save in another database called marks database. I also need CRUD for these two categories.So how to do that?
Any suggestion and help will be highly appreciable.
Well there is no direct link between a form and a database table, so what is your problem?
Why don't you do the mysql_query() on each table one after another when you handle the form post?
You can build your form like this in order to separate the tables:
<input type="text" name="data[student][name]" />
<input type="text" name="data[category][name]" />
you PHP script then goes through the data and save it in the corresponding tables:
foreach($_POST['data'] as $table=>$row){
// do your insert statemnet here (don't foregt to escape the Parameters!)
}

Categories