Currently I am creating a form (70+ questions) but I am stuck on one part.
I would like to get people to fill in the opening hours for every day of the week.
This will consist of the day of the week followed by 4 dropdowns,
from : to (afternoon break) from : to
That part of the form looks like this:
http://dgoods.eu/php/form.jpg
How can I get these values into the mysql table? Also please keep in mind that I will have to be able to extract the values from the table and work with them later on.
You would have to retrieve the data from the form, and add it to a MySQL table using and INSERT statement with the values. You can then get the values from the table using SELECT statements.
EDIT:
I don't know much php, but it would be something like:
$sql="INSERT INTO tablename (morning_time, evening_time)
VALUES ('$_POST[combobox1]','$_POST[combobox2]')";
mysql_real_query($sql,$con)
Also you can use $_GET instead of $_POST
You can also take a look at this.
Related
Im having some troubles showing the unique values from my database.
As an example, I have this very simple test table:
Where you can see that there is a duplicated value on the Tags column, named intro.
I would like to echo all of the UNIQUE tags, and I've tried with the DISTINCT command, but I might be doing something wrong.
This is my actual query:
SELECT DISTINCT tags FROM blog
But this gives me ALL of the tags.
Any help would be appreciated, thanks.
According to the image there are just to rows in the table, one contains "intro" and the other contains "intro, php, warning, errors".
If so, there are not the same.
I think you try to use a row for each value.
To do it you should insert each value in a separated sentence, or in the same but using different rows, something like:
insert into blog(tags) values ("intro"),values ("intro"),values ("php")
I have created a website (you don't want to see that). Now i want to input students details there. I created a tiny table for testing, only 3 rows - firstname, lastname, age.
I created a simple HTML form and a PHP script, now I can input data and save there easily.
Now the problem is I don't seem to find an easy way to update data.
I have some knowledge in Oracle database, forms and reports. I was thinking to populate HTML forms from MySQL data (similar to Oracle Forms) and update and save. I did not find a way to do that. I searched Google and got some complicated long code, did not understand properly.
If possible, please give me the simplest way (no validation, no security check, etc) to do that.
Since you provide no code of your website, I can only assume that you are using a query to insert data into the database? Should be something like:
$query = "INSERT INTO table_name VALUES (value1,value2,...)";
To update, you can use the same type of form, except the query would be:
$query = "UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE some_column = some_value";
You can find more information here: http://www.w3schools.com/sql/sql_update.asp
If you want more help, show us more code and tell us what the column names are in the database. I can the provide exact variables to put in the query.
I have a column in table which has possible values of tom,john,jerry(SET). I have a variable that a user enter and I store it in $var and want that at some point. I could check that if the value in $var exists in particular row then don't update else update, How I can do this in PHP.
I have several rows like tom,john
john,jerry
I dont want tom,john,tom
I have one suggestion.
Please change the database values so that you have: ,tom,john,tom, (Notice the appending and preceding commas ,.
Now if you want to search for tom, fire an SQL like:
SELECT id FROM DB_TBL WHERE field LIKE '%,$val,%'
Repeat this for all values user has entered OR put in a single text box with commas.
Hope this works.
I m designing a website in which I want to add multiple rows into database on single click.
I want to add the results of the students of whole class in the students database which contains columns "s_id, subject_name, subject_result". I have design a simple form which list all the students and a text box in which result is to be added and on the submit button the results to be updated on the students database.
plzz give me some suggestions or link
There's a very good example on how to achieve this using PHP's implode statement right here in this very site. Mind you, I'm not sure what DB you're using but I'm going under the assumption that you're using a *AMP stack.
INSERT INTO results (`s_id`, `subject_name`, `subject_result`)
VALUES (1, 'a1', 's1'), (2, 'a2', 's2'), ...;
If they are submitting the information via a form then the variables should be in an array. You can just loop through the array inserting into the database upon each loop.
I know it's not multiple multiple rows being inserted at once, but it is very fast and works. I've used this method to insert thousands of records at a time with this.
Hope it helps.
Take care,
Shannon
I have a page that retrieves records from 1 table in a database when a certain condition is met.
What I want to achieve is to provide the use to with an opportunity to update each record displayed using text boxes.
I am having trouble interpreting what logic to proceed with after the user hits the 'submit' button.
Normally, if I'm updating one record (or a static number of records), I will use the apporpriate amount of SQL statements.
Since the amount of records are dynamically generated, what is the best way to update all at once? How would I know which records were retrieved in the first place to update?
FOR EXAMPLE:
OK, We have a table with student ids (ID), names (SNAME), subjects (SUBJ), grade for each subject (GRADE) and general remarks (COMMENTS).
I want to retrieve information about all students that got an 'A', and write UNIQUE congratulatory remarks for each student (such as 'good job', or 'congratulations', or etc.)
I'd retrieve the records and lay them out on the page, with a text box next to each student record for the comments to be entered. Because I don't know how many text boxes to make, I give the text boxes dynamically generated names using the student ID. The user now enters unique comments for each student, and clicks on submit.
Now, how am I supposed to update these records with the values entered in each text box?
I wouldn't know which students were retrieved in the first place - how would I know what names to use? I'm trying to avoid having to execute the query again after submitting - but is there any other way?
Hope this question was not too confusing.
thanks
Further expanding earlier answers:
You need a loop (e.g. foreach) to display and save the textareas. If the names of the textareas include the students ID, you don't need to know the name, because the text is inserted to the database by the primary key (the students ID). You may name your form-elements as array, to iterate over them, for example (where the numbers are the IDs):
<textarea name="comment[2345234]"></textarea>
<textarea name="comment[8957485]"></textarea>
Read it out as described by #evan:
foreach((array)$_POST['comment'] as $studentId => $studentComment)
{
var_dump($studentId, $studentComment);
}
And if you implement this whole thing as self-requesting form (Affenformular in german), you may also use just one single loop to save and output the textareas.
"I don't think you're understanding what I'm trying to ask." Maybe you don't understand the answers, even you stated it. You don't need a students name to save a database record. But if you really want to submit it, you may also use hidden inputs.
Use foreach() to find the values you care about, put them in an array, and process the array.
Expanding on #Ignacio's answer to make it more easily understandable:
foreach($_POST as $name_of_input => $value_of_input)
{
// do stuff - here is something so you can see the results after the submit
echo "$name_of_input :: $value_of_input <br>";
}