I've seen some people have the same issue, but different scenarios. And searching just gives me 'how to use joins'.
When I execute this through my php page, two records are inserted. One with the content, and one with just the date. I can't seem to find where the date field is being executed. I've had this issue in the past, but with a past version of mySQL and with depreciated values, so using the new values is someone newer to me.
Below is my php and sql statement:
<?php
$link = mysqli_connect('server', 'username', 'password');
if (!$link) {
die('Could Not Connect: ' . mysqli_error());
}
else echo 'Connected Succesffully';
mysqli_select_db($link, 'database');
mysqli_query($link, "INSERT INTO tblcc
(date , production , productionco , city , state ,
genre , type , details , part1 , gender1 ,
char1 , part2 , gender2 , char2 , part3 ,
gender3 , char3 , part4 , gender4 , char4 , part5 ,
gender5 , char5)
VALUES(now() , '$_POST[production]' , '$_POST[productionco]' , '$_POST[city]' , '$_POST[state]' ,
'$_POST[genre]' , '$_POST[type]' , '$_POST[details]' , '$_POST[part1]' , '$_POST[gender1]' ,
'$_POST[char1]' , '$_POST[part2]' , '$_POST[gender2]' , '$_POST[char2]' , '$_POST[part3]' ,
'$_POST[gender3]' , '$_POST[char3]' , '$_POST[part4]' , '$_POST[gender4]' , '$_POST[char4]' ,
'$_POST[part5]' , '$_POST[gender5]', $_POST[char5]')");
mysqli_close($link);
?>
The HTML:
<form action="http://enhstudios.com/bc1/submitcc.php/" method="post">
<table border="3" cellpadding="3" cellspacing="3">
<tr>
<th>Production:</th>
<th>Production Company:</th>
<th colspan="2">Location:</th>
</tr>
<tr>
<td><input type="text" name="production"></td>
<td><input type="text" name="productionco"></td>
<td><input type="text" name="city"></td>
<td><select name="state">
<option value=""></option>
<option value="Illinois">Illinois</option>
<option value="Indiana">Indiana</option>
<option value="Iowa">Iowa</option>
<option value="Kentucky">Kentucky</option>
<option value="Missouri">Missouri</option>
<option value="Ohio">Ohio</option>
<option value="Wisconsin">Wisconsin</option>
</select>
</td>
</tr>
<tr>
<th>Genre:</th>
<th>Type:</th>
<th colspan="2">Details:</th>
</tr>
<tr>
<td><select name="genre">
<option value=""></option>
<option value="Action">Action</option>
<option value="Comedy">Comedy</option>
<option value="Drama">Drama</option>
<option value="Horror">Horror</option>
<option value="Romance">Romance</option>
</select>
</td>
<td><select name="type">
<option value=""></option>
<option value="Feature Length">Feature Length</option>
<option value="Mini-Series">Mini-Series</option>
<option value="Short">Short</option>
<option value="Web Series">Web Series</option>
</select>
</td>
<td colspan="2"><textarea maxlength="255" rows="5" cols="30" name="details"></textarea></td>
</tr>
<tr>
<th colspan="4">Parts:</th>
</tr>
<tr>
<th>Role Type:</th>
<th>Gender:</th>
<th colspan="2">Character:</th>
</tr>
<tr>
<td><select name="part1">
<option value=""></option>
<option value="Extra">Extra</option>
<option value="Leading">Leading</option>
<option value="Supporting">Supporting</option>
</select>
</td>
<td><select name="gender1">
<option value=""></option>
<option value="Female">Female</option>
<option value="Male">Male</option>
</select>
</td>
<td colspan="2"><input type="text" name="char1">
</td>
</tr>
<tr>
<td><select name="part2">
<option value=""></option>
<option value="Extra">Extra</option>
<option value="Leading">Leading</option>
<option value="Supporting">Supporting</option>
</select>
</td>
<td><select name="gender2">
<option value=""></option>
<option value="Female">Female</option>
<option value="Male">Male</option>
</select>
</td>
<td colspan="2"><input type="text" name="char2">
</td>
</tr>
<tr>
<td><select name="part3">
<option value=""></option>
<option value="Extra">Extra</option>
<option value="Leading">Leading</option>
<option value="Supporting">Supporting</option>
</select>
</td>
<td><select name="gender3">
<option value=""></option>
<option value="Female">Female</option>
<option value="Male">Male</option>
</select>
</td>
<td colspan="2"><input type="text" name="char3">
</td>
</tr>
<tr>
<td><select name="part4">
<option value=""></option>
<option value="Extra">Extra</option>
<option value="Leading">Leading</option>
<option value="Supporting">Supporting</option>
</select>
</td>
<td><select name="gender4">
<option value=""></option>
<option value="Female">Female</option>
<option value="Male">Male</option>
</select>
</td>
<td colspan="2"><input type="text" name="char4">
</td>
</tr>
<tr>
<td><select name="part5">
<option value=""></option>
<option value="Extra">Extra</option>
<option value="Leading">Leading</option>
<option value="Supporting">Supporting</option>
</select>
</td>
<td><select name="gender5">
<option value=""></option>
<option value="Female">Female</option>
<option value="Male">Male</option>
</select>
</td>
<td colspan="2"><input type="text" name="char5">
</td>
</tr>
<tr>
<td><input type="submit" value="Submit"></td>
<td colspan="3"></td>
</tr>
</table>
</form>
I found the "issue". I nestled the form inside the table instead of the table inside the form.
Related
Hello freinds i am unable to print in newline after clicking submit form i am getting all the data in a same row even I have used "\r\n", here is my MWE for html coding
<html>
<head>
<script type="text/javascript" src="validate.js"></script>
</head>
<body>
<form name="StudentRegistration" action="proces.php" method="post">
<table cellpadding="2" width="20%" bgcolor="99FFFF" align="center" cellspacing="2">
<tr>
<td colspan=2>
<center><font size=4><b>Student Registration Form</b></font></center>
</td>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
<td>Name</td>
<td><input type=text name=textnames id="textname" size="30"></td>
</tr>
<tr>
<td>Father Name</td>
<td><input type="text" name="fathername" id="fathername" size="30"></td>
</tr>
<tr>
<td>Mother Name</td>
<td><input type="text" name="mothername" id="mothername" size="30"></td>
</tr>
<tr>
<td>Institute</td>
<td><select name="institute">
<option value=" " selected>Select..</option>
<option value="Institute-1">Institute-1</option>
<option value="Institute-2">Institute-2</option>
</select></td>
</tr>
<td>Category</td>
<td><select name="category">
<option value=" " selected>Select..</option>
<option value="Regular">Regular</option>
<option value="Private">Private</option>
</select></td>
</tr>
<tr>
<td>Sex</td>
<td><input type="radio" name="sex" value="Male" size="10">Male
<input type="radio" name="sex" value="Female" size="10">Female</td>
</tr>
<td>Stream</td>
<td><select name="stream">
<option value=" " selected>Select..</option>
<option value="ARTS">ARTS</option>
<option value="COMMERCE">COMMERCE</option>
<option value="SCIENCE">SCIENCE</option>
</select></td>
</tr>
<tr>
<td>Core-1</td>
<td><select name="core-1">
<option value=" " selected>Select..</option>
<option value="ENGL">English</option>
</select></td>
</tr>
<tr>
<td>Core-2</td>
<td><select name="core-2">
<option value=" " selected>Select..</option>
<option value="ALTE">Alternative English</option>
</select></td>
</tr>
<tr>
<td>Elective-1</td>
<td><select name="elective-1">
<option value=" " selected>Select..</option>
<option value="HIST">History</option>
<option value="LOPH">Logic & Philosophy</option>
<option value="MATH">Mathematics</option>
<option value="MBEN">MIL (Bengali)</option>
<option value="MBOD">MIL (Bodo)</option>
<option value="MHIN">MIL (Hindi)</option>
<option value="MNEP">MIL (Nepali)</option>
<option value="PHYS">Physics</option>
<option value="POSC">Political Science</option>
<option value="SOCI">Sociology</option>
<option value="STAT">Statistics</option>
</select></td>
</tr>
<tr>
<td>Elective-2</td>
<td><select name="elective-2">
<option value=" " selected>Select..</option>
<option value="HIST">History</option>
<option value="LOPH">Logic & Philosophy</option>
<option value="MATH">Mathematics</option>
<option value="MBEN">MIL (Bengali)</option>
<option value="MBOD">MIL (Bodo)</option>
<option value="MHIN">MIL (Hindi)</option>
<option value="MNEP">MIL (Nepali)</option>
<option value="PHYS">Physics</option>
<option value="POSC">Political Science</option>
<option value="SOCI">Sociology</option>
<option value="STAT">Statistics</option>
</select></td>
</tr>
<tr>
<td>Elective-3</td>
<td><select name="elective-3">
<option value=" " selected>Select..</option>
<option value="HIST">History</option>
<option value="LOPH">Logic & Philosophy</option>
<option value="MATH">Mathematics</option>
<option value="MBEN">MIL (Bengali)</option>
<option value="MBOD">MIL (Bodo)</option>
<option value="MHIN">MIL (Hindi)</option>
<option value="MNEP">MIL (Nepali)</option>
<option value="PHYS">Physics</option>
<option value="POSC">Political Science</option>
<option value="SOCI">Sociology</option>
<option value="STAT">Statistics</option>
</select></td>
</tr>
<tr>
<td>Elective-4</td>
<td><select name="elective-4">
<option value=" " selected>Select..</option>
<option value="HIST">History</option>
<option value="LOPH">Logic & Philosophy</option>
<option value="MATH">Mathematics</option>
<option value="MBEN">MIL (Bengali)</option>
<option value="MBOD">MIL (Bodo)</option>
<option value="MHIN">MIL (Hindi)</option>
<option value="MNEP">MIL (Nepali)</option>
<option value="PHYS">Physics</option>
<option value="POSC">Political Science</option>
<option value="SOCI">Sociology</option>
<option value="STAT">Statistics</option>
</select></td>
</tr>
<tr>
<td>Compulsory</td>
<td><select name="compulsory">
<option value=" " selected>Select..</option>
<option value="ENVE">Environmental Education</option>
</select></td>
</tr>
<tr>
<td><input type="reset"></td>
<td colspan="2"><input type="submit" value="Submit Form" /></td>
</tr>
</table>
</form>
</body>
</html>
Here is MWE for php for exporting data to .csv file to save data, I want for every each Submit Form i want to print data in newlines
<?php
$fieldAA = $_POST[" "];
$fieldA = $_POST["textnames"];
$fieldB = $_POST["fathername"];
$fieldC = $_POST["mothername"];
$fieldD = $_POST["institute"];
$fieldE = $_POST["category"];
$fieldF = $_POST["sex"];
$fieldG = $_POST["stream"];
$fieldH = $_POST["core-1"];
$fieldI = $_POST["core-2"];
$fieldJ = $_POST["elective-1"];
$fieldK = $_POST["elective-2"];
$fieldL = $_POST["elective-3"];
$fieldM = $_POST["elective-4"];
$fieldN = $_POST["compulsory"];
$keys = array($fieldAA,$fieldA,$fieldB,$fieldC,$fieldD,$fieldE,$fieldF,$fieldG,$fieldH,'','',$fieldI,'','',$fieldJ,'','',$fieldK,'','',$fieldL,'','',$fieldM,'','',$fieldN,''); //THIS IS WHERE YOU PUT THE FORM ELEMENTS ex: array('$fieldA','$fieldB',etc)
$csv_line = $keys;
foreach( $keys as $key ){
array_push($csv_line,'' . $_GET[$key]);
}
$fname = 'data.csv'; //NAME OF THE FILE
$csv_line = implode(',',$csv_line);
if(!file_exists($fname)){$csv_line = "\r\n" . $csv_line ;}
$fcon = fopen($fname,'a');
$fcontent = $csv_line ;
fwrite($fcon,$csv_line);
fclose($fcon);
echo "Successfully done! $keys[1]"
?>
In php we can use the PHP_EOL to echo out the end of a line, using this method will not rely on the current document(s)/platforms line endings.
Example:-
$string = "I want a new line here" . PHP_EOL . "This is my new line";
Line breaks in csvs are dependent on what you use to view them also.
Also you probably want to explain what MWE means in your question.
I am new and beginner and got some codes from internet by searching and editted according to my needs, but now i want to save the data entry in html form to data.csv file, when i click submit button it should save the contents into data.csv in new line for every click submit button. This html codes i am running local computer only. I don't know how do i that here is MWE. Thanking you in advance for any help
<html>
<head>
<script type="text/javascript" src="validate.js"></script>
</head>
<body>
<form action="#" name="StudentRegistration" onSubmit="return(validate());">
<table cellpadding="2" width="20%" bgcolor="99FFFF" align="center"
cellspacing="2">
<tr>
<td colspan=2>
<center><font size=4><b>Student Registration Form</b></font></center>
</td>
</tr>
<tr>
<td>Name</td>
<td><input type=text name=textnames id="textname" size="30"></td>
</tr>
<tr>
<td>Father Name</td>
<td><input type="text" name="fathername" id="fathername"
size="30"></td>
</tr>
<tr>
<td>Postal Address</td>
<td><input type="text" name="paddress" id="paddress" size="30"></td>
</tr>
<tr>
<td>Personal Address</td>
<td><input type="text" name="personaladdress"
id="personaladdress" size="30"></td>
</tr>
<tr>
<td>Sex</td>
<td><input type="radio" name="sex" value="male" size="10">Male
<input type="radio" name="sex" value="Female" size="10">Female</td>
</tr>
<tr>
<td>Stream</td>
<td><select name="Stream">
<option value="-1" selected>Select..</option>
<option value="ARTS">ARTS</option>
<option value="COMMERCE">COMMERCE</option>
<option value="SCIENCE">SCIENCE</option>
</select></td>
</tr>
<tr>
<td>Core-1</td>
<td><select name="Core-1">
<option value="-1" selected>Select..</option>
<option value="English">English</option>
</select></td>
</tr>
<tr>
<td>Core-2</td>
<td><select name="Core-2">
<option value="-1" selected>Select..</option>
<option value="Alternative English">Alternative English</option>
</select></td>
</tr>
<tr>
<td>Elective-1</td>
<td><select name="Elective-1">
<option value="-1" selected>Select..</option>
<option value="MIL (Hindi)">MIL (Hindi)</option>
<option value="MIL (Bengali)">MIL (Bengali)</option>
<option value="MIL (Nepali)">MIL (Nepali)</option>
<option value="Political Science">Political Science</option>
<option value="Education">Education</option>
<option value="Economics">Economics</option>
<option value="History">History</option>
<option value="Geography">Geography</option>
<option value="Sociology">Sociology</option>
<option value="Logic & Philosophy">Logic & Philosophy</option>
<option value="Advance Assamese">Advance Assamese</option>
<option value="Advance Bengali">Advance Bengali</option>
<option value="Physics">Physics</option>
<option value="Chemistry">Chemistry</option>
<option value="Biology">Biology</option>
<option value="Mathematics">Mathematics</option>
<option value="Computer Science & Applications">Computer Science & Applications</option>
<option value="Accountancy">Accountancy</option>
<option value="Business Studies">Business Studies</option>
<option value="Banking">Banking</option>
<option value="Statistics">Statistics</option>
</select></td>
</tr>
<tr>
<td>Elective-2</td>
<td><select name="Elective-2">
<option value="-1" selected>Select..</option>
<option value="MIL (Hindi)">MIL (Hindi)</option>
<option value="MIL (Bengali)">MIL (Bengali)</option>
<option value="MIL (Nepali)">MIL (Nepali)</option>
<option value="Political Science">Political Science</option>
<option value="Education">Education</option>
<option value="Economics">Economics</option>
<option value="History">History</option>
<option value="Geography">Geography</option>
<option value="Sociology">Sociology</option>
<option value="Logic & Philosophy">Logic & Philosophy</option>
<option value="Advance Assamese">Advance Assamese</option>
<option value="Advance Bengali">Advance Bengali</option>
<option value="Physics">Physics</option>
<option value="Chemistry">Chemistry</option>
<option value="Biology">Biology</option>
<option value="Mathematics">Mathematics</option>
<option value="Computer Science & Applications">Computer Science & Applications</option>
<option value="Accountancy">Accountancy</option>
<option value="Business Studies">Business Studies</option>
<option value="Banking">Banking</option>
<option value="Statistics">Statistics</option>
</select></td>
</tr>
<tr>
<td>Elective-3</td>
<td><select name="Elective-3">
<option value="-1" selected>Select..</option>
<option value="MIL (Hindi)">MIL (Hindi)</option>
<option value="MIL (Bengali)">MIL (Bengali)</option>
<option value="MIL (Nepali)">MIL (Nepali)</option>
<option value="Political Science">Political Science</option>
<option value="Education">Education</option>
<option value="Economics">Economics</option>
<option value="History">History</option>
<option value="Geography">Geography</option>
<option value="Sociology">Sociology</option>
<option value="Logic & Philosophy">Logic & Philosophy</option>
<option value="Advance Assamese">Advance Assamese</option>
<option value="Advance Bengali">Advance Bengali</option>
<option value="Physics">Physics</option>
<option value="Chemistry">Chemistry</option>
<option value="Biology">Biology</option>
<option value="Mathematics">Mathematics</option>
<option value="Computer Science & Applications">Computer Science & Applications</option>
<option value="Accountancy">Accountancy</option>
<option value="Business Studies">Business Studies</option>
<option value="Banking">Banking</option>
<option value="Statistics">Statistics</option>
</select></td>
</tr>
<tr>
<td>Elective-4</td>
<td><select name="Elective-4">
<option value="-1" selected>Select..</option>
<option value="MIL (Hindi)">MIL (Hindi)</option>
<option value="MIL (Bengali)">MIL (Bengali)</option>
<option value="MIL (Nepali)">MIL (Nepali)</option>
<option value="Political Science">Political Science</option>
<option value="Education">Education</option>
<option value="Economics">Economics</option>
<option value="History">History</option>
<option value="Geography">Geography</option>
<option value="Sociology">Sociology</option>
<option value="Logic & Philosophy">Logic & Philosophy</option>
<option value="Advance Assamese">Advance Assamese</option>
<option value="Advance Bengali">Advance Bengali</option>
<option value="Physics">Physics</option>
<option value="Chemistry">Chemistry</option>
<option value="Biology">Biology</option>
<option value="Mathematics">Mathematics</option>
<option value="Computer Science & Applications">Computer Science & Applications</option>
<option value="Accountancy">Accountancy</option>
<option value="Business Studies">Business Studies</option>
<option value="Banking">Banking</option>
<option value="Statistics">Statistics</option>
</select></td>
</tr>
<tr>
<td>Compulsory</td>
<td><select name="Compulsory">
<option value="-1" selected>Select..</option>
<option value="Environmental Education">Environmental Education</option>
</select></td>
</tr>
<tr>
<td>Institute</td>
<td><select name="Institute">
<option value="-1" selected>Select..</option>
<option value="Institute-1">Institute-1</option>
<option value="Institute-2">Institute-2</option>
<option value="Institute-3">Institute-3</option>
</select></td>
</tr>
<tr>
<td>State</td>
<td><select Name="State">
<option value="-1" selected>select..</option>
<option value="New Delhi">NEW DELHI</option>
<option value="Mumbai">MUMBAI</option>
<option value="Goa">GOA</option>
<option value="Bihar">BIHAR</option>
</select></td>
</tr>
<tr>
<td>PinCode</td>
<td><input type="text" name="pincode" id="pincode" size="30"></td>
</tr>
<tr>
<td>EmailId</td>
<td><input type="text" name="emailid" id="emailid" size="30"></td>
</tr>
<tr>
<td>DOB</td>
<td><input type="text" name="dob" id="dob" size="30"></td>
</tr>
<tr>
<td>MobileNo</td>
<td><input type="text" name="mobileno" id="mobileno" size="30"></td>
</tr>
<tr>
<td><input type="reset"></td>
<td colspan="2"><input type="submit" value="Submit Form" /></td>
</tr>
</table>
</form>
</body>
</html>
Here is the output of the above html codes
I have created a .php as proces.php file according to Bill suggestion but content not writing but giving only ,,,,,,, here is my php script
<?php
$fieldA = $_POST["textnames"];
$fieldB = $_POST["fathername"];
$fieldC = $_POST["paddress"];
$fieldD = $_POST["personaladdress"];
$fieldE = $_POST["sex"];
$fieldF = $_POST["Stream"];
$fieldG = $_POST["Core-1"];
$fieldH = $_POST["Core-2"];
$fieldI = $_POST["Elective-1"];
$fieldJ = $_POST["Elective-2"];
$fieldK = $_POST["Elective-3"];
$fieldL = $_POST["Elective-4"];
$fieldM = $_POST["Compulsory"];
$keys = array($fieldA,$fieldB,$fieldC,$fieldD,$fieldE,$fieldF,$fieldG,$fieldH,$fieldI,$fieldJ,$fieldK,$fieldL,$fieldM); //THIS IS WHERE YOU PUT THE FORM ELEMENTS ex: array('$fieldA','$fieldB',etc)
$csv_line = array();
foreach($keys as $key){
array_push($csv_line,'' . $_GET[$key]);
}
$fname = 'data.csv'; //NAME OF THE FILE
$csv_line = implode(',',$csv_line);
if(!file_exists($fname)){$csv_line = "\r\n" . $csv_line;}
$fcon = fopen($fname,'a');
$fcontent = $csv_line;
fwrite($fcon,$fcontent);
fclose($fcon);
?>
and edited my original html codes from <form action="#" name="StudentRegistration" onSubmit="return(validate());"> to <form name="StudentRegistration" action="proces1.php" method="post"> so here is my new final html coding
<html>
<head>
<script type="text/javascript" src="validate.js"></script>
</head>
<body>
<form name="StudentRegistration" action="proces.php" method="post">
<table cellpadding="2" width="20%" bgcolor="99FFFF" align="center"
cellspacing="2">
<tr>
<td colspan=2>
<center><font size=4><b>Student Registration Form</b></font></center>
</td>
</tr>
<tr>
<td>Name</td>
<td><input type=text name=textnames id="textname" size="30"></td>
</tr>
<tr>
<td>Father Name</td>
<td><input type="text" name="fathername" id="fathername"
size="30"></td>
</tr>
<tr>
<td>Postal Address</td>
<td><input type="text" name="paddress" id="paddress" size="30"></td>
</tr>
<tr>
<td>Personal Address</td>
<td><input type="text" name="personaladdress"
id="personaladdress" size="30"></td>
</tr>
<tr>
<td>Sex</td>
<td><input type="radio" name="sex" value="male" size="10">Male
<input type="radio" name="sex" value="Female" size="10">Female</td>
</tr>
<tr>
<td>Stream</td>
<td><select name="Stream">
<option value="-1" selected>Select..</option>
<option value="ARTS">ARTS</option>
<option value="COMMERCE">COMMERCE</option>
<option value="SCIENCE">SCIENCE</option>
</select></td>
</tr>
<tr>
<td>Core-1</td>
<td><select name="Core-1">
<option value="-1" selected>Select..</option>
<option value="English">English</option>
</select></td>
</tr>
<tr>
<td>Core-2</td>
<td><select name="Core-2">
<option value="-1" selected>Select..</option>
<option value="Alternative English">Alternative English</option>
</select></td>
</tr>
<tr>
<td>Elective-1</td>
<td><select name="Elective-1">
<option value="-1" selected>Select..</option>
<option value="MIL (Hindi)">MIL (Hindi)</option>
<option value="MIL (Bengali)">MIL (Bengali)</option>
<option value="MIL (Nepali)">MIL (Nepali)</option>
<option value="Political Science">Political Science</option>
<option value="Education">Education</option>
<option value="Economics">Economics</option>
<option value="History">History</option>
<option value="Geography">Geography</option>
<option value="Sociology">Sociology</option>
<option value="Logic & Philosophy">Logic & Philosophy</option>
<option value="Advance Assamese">Advance Assamese</option>
<option value="Advance Bengali">Advance Bengali</option>
<option value="Physics">Physics</option>
<option value="Chemistry">Chemistry</option>
<option value="Biology">Biology</option>
<option value="Mathematics">Mathematics</option>
<option value="Computer Science & Applications">Computer Science & Applications</option>
<option value="Accountancy">Accountancy</option>
<option value="Business Studies">Business Studies</option>
<option value="Banking">Banking</option>
<option value="Statistics">Statistics</option>
</select></td>
</tr>
<tr>
<td>Elective-2</td>
<td><select name="Elective-2">
<option value="-1" selected>Select..</option>
<option value="MIL (Hindi)">MIL (Hindi)</option>
<option value="MIL (Bengali)">MIL (Bengali)</option>
<option value="MIL (Nepali)">MIL (Nepali)</option>
<option value="Political Science">Political Science</option>
<option value="Education">Education</option>
<option value="Economics">Economics</option>
<option value="History">History</option>
<option value="Geography">Geography</option>
<option value="Sociology">Sociology</option>
<option value="Logic & Philosophy">Logic & Philosophy</option>
<option value="Advance Assamese">Advance Assamese</option>
<option value="Advance Bengali">Advance Bengali</option>
<option value="Physics">Physics</option>
<option value="Chemistry">Chemistry</option>
<option value="Biology">Biology</option>
<option value="Mathematics">Mathematics</option>
<option value="Computer Science & Applications">Computer Science & Applications</option>
<option value="Accountancy">Accountancy</option>
<option value="Business Studies">Business Studies</option>
<option value="Banking">Banking</option>
<option value="Statistics">Statistics</option>
</select></td>
</tr>
<tr>
<td>Elective-3</td>
<td><select name="Elective-3">
<option value="-1" selected>Select..</option>
<option value="MIL (Hindi)">MIL (Hindi)</option>
<option value="MIL (Bengali)">MIL (Bengali)</option>
<option value="MIL (Nepali)">MIL (Nepali)</option>
<option value="Political Science">Political Science</option>
<option value="Education">Education</option>
<option value="Economics">Economics</option>
<option value="History">History</option>
<option value="Geography">Geography</option>
<option value="Sociology">Sociology</option>
<option value="Logic & Philosophy">Logic & Philosophy</option>
<option value="Advance Assamese">Advance Assamese</option>
<option value="Advance Bengali">Advance Bengali</option>
<option value="Physics">Physics</option>
<option value="Chemistry">Chemistry</option>
<option value="Biology">Biology</option>
<option value="Mathematics">Mathematics</option>
<option value="Computer Science & Applications">Computer Science & Applications</option>
<option value="Accountancy">Accountancy</option>
<option value="Business Studies">Business Studies</option>
<option value="Banking">Banking</option>
<option value="Statistics">Statistics</option>
</select></td>
</tr>
<tr>
<td>Elective-4</td>
<td><select name="Elective-4">
<option value="-1" selected>Select..</option>
<option value="MIL (Hindi)">MIL (Hindi)</option>
<option value="MIL (Bengali)">MIL (Bengali)</option>
<option value="MIL (Nepali)">MIL (Nepali)</option>
<option value="Political Science">Political Science</option>
<option value="Education">Education</option>
<option value="Economics">Economics</option>
<option value="History">History</option>
<option value="Geography">Geography</option>
<option value="Sociology">Sociology</option>
<option value="Logic & Philosophy">Logic & Philosophy</option>
<option value="Advance Assamese">Advance Assamese</option>
<option value="Advance Bengali">Advance Bengali</option>
<option value="Physics">Physics</option>
<option value="Chemistry">Chemistry</option>
<option value="Biology">Biology</option>
<option value="Mathematics">Mathematics</option>
<option value="Computer Science & Applications">Computer Science & Applications</option>
<option value="Accountancy">Accountancy</option>
<option value="Business Studies">Business Studies</option>
<option value="Banking">Banking</option>
<option value="Statistics">Statistics</option>
</select></td>
</tr>
<tr>
<td>Compulsory</td>
<td><select name="Compulsory">
<option value="-1" selected>Select..</option>
<option value="Environmental Education">Environmental Education</option>
</select></td>
</tr>
<tr>
<td>Institute</td>
<td><select name="Institute">
<option value="-1" selected>Select..</option>
<option value="Institute-1">Institute-1</option>
<option value="Institute-2">Institute-2</option>
<option value="Institute-3">Institute-3</option>
</select></td>
</tr>
<tr>
<td>State</td>
<td><select Name="State">
<option value="-1" selected>select..</option>
<option value="New Delhi">NEW DELHI</option>
<option value="Mumbai">MUMBAI</option>
<option value="Goa">GOA</option>
<option value="Bihar">BIHAR</option>
</select></td>
</tr>
<tr>
<td>PinCode</td>
<td><input type="text" name="pincode" id="pincode" size="30"></td>
</tr>
<tr>
<td>EmailId</td>
<td><input type="text" name="emailid" id="emailid" size="30"></td>
</tr>
<tr>
<td>DOB</td>
<td><input type="text" name="dob" id="dob" size="30"></td>
</tr>
<tr>
<td>MobileNo</td>
<td><input type="text" name="mobileno" id="mobileno" size="30"></td>
</tr>
<tr>
<td><input type="reset"></td>
<td colspan="2"><input type="submit" value="Submit Form" /></td>
</tr>
</table>
</form>
</body>
</html>
This post should get you where you need to go...
How to export html form to csv file
The answer there gives a good explanation on how the script works.
edit:
You're going to need to create a PHP file and pass the data when you hit submit FORM should look like this notice the POST and .php file.
<form action="NAMEOFFILE.php" method="post">
NAMEOFFILE.PHP will contain the form data and the export to CSV script in the link attached. If are not sure how to pass the data this is a straightforward explanation. https://www.tutorialrepublic.com/php-tutorial/php-get-and-post.php
<?php
$fieldA = $_POST["textnames"];
$keys = array('id_number','first_name'); //THIS IS WHERE YOU PUT THE FORM ELEMENTS ex: array('$fieldA','$fieldB',etc)
$csv_line = array();
foreach($keys as $key){
array_push($csv_line,'' . $_GET[$key]);
}
$fname = 'file_to_write_to.csv'; //NAME OF THE FILE
$csv_line = implode(',',$csv_line);
if(!file_exists($fname)){$csv_line = "\r\n" . $csv_line;}
$fcon = fopen($fname,'a');
$fcontent = $csv_line;
fwrite($fcon,$csv_line);
fclose($fcon);
?>
The file will be saved on your server with the name "file_to_write_to.csv"
Thanks to everyone Now I finally got the output after editing the proces.php script by changing the line from $csv_line = array(); to $csv_line = $keys; and from if(!file_exists($fname)){$csv_line = "\r\n" . $csv_line;} to if(!file_exists($fname)){$csv_line = $csv_line."\r\n" ;} here is my final .php file
<?php
$fieldA = $_POST["textnames"];
$fieldB = $_POST["fathername"];
$fieldC = $_POST["paddress"];
$fieldD = $_POST["personaladdress"];
$fieldE = $_POST["sex"];
$fieldF = $_POST["Stream"];
$fieldG = $_POST["Core-1"];
$fieldH = $_POST["Core-2"];
$fieldI = $_POST["Elective-1"];
$fieldJ = $_POST["Elective-2"];
$fieldK = $_POST["Elective-3"];
$fieldL = $_POST["Elective-4"];
$fieldM = $_POST["Compulsory"];
$keys = array($fieldA,$fieldB,$fieldC,$fieldD,$fieldE,$fieldF,$fieldG,$fieldH,$fieldI,$fieldJ,$fieldK,$fieldL,$fieldM); //THIS IS WHERE YOU PUT THE FORM ELEMENTS ex: array('$fieldA','$fieldB',etc)
$csv_line = $keys;
foreach( $keys as $key ){
array_push($csv_line,'' . $_GET[$key]);
}
$fname = 'data.csv'; //NAME OF THE FILE
$csv_line = implode(',',$csv_line);
if(!file_exists($fname)){$csv_line = $csv_line."\r\n" ;}
$fcon = fopen($fname,'a');
$fcontent = $csv_line;
fwrite($fcon,$csv_line);
fclose($fcon);
?>
Right now i am developing a booking vehicle system using html,php,sql. I dont know how to describe my question but let me give a situation example.
user 1: want to book vehicle on 11 may 2017 # 0930 and the admin already approved this user form.
user 2: want to book vehicle at the same date & time as user 1 and here is the problem. How to block others user from proceed the booking if that date & time already have a user?
Hope you guys can help me, thank you!
this is my coding for date & time. it is in form for user to book and i want to make it once they click submit if that date & time already booked will pop up msg like 'already booked'.
<link rel="stylesheet" type="text/css" href="tcal.css" />
<script type="text/javascript" src="tcal.js"></script>
<script>
function myFunction() {
alert("Permohonan anda akan diproses. Sila jangan tutup paparan sehingga selesai.");
}
</script>
<form action="processform.php" method="post" enctype="multipart/form-data">
<table width="100%" align="center" cellpadding="2" cellspacing="4" bgcolor="#FFFFFF">
<br>
<br>
<tr bgcolor="#e2e8ef">
<td colspan="3" class="font12bold"> BUTIRAN PERJALANAN</td>
</tr>
<tr class="font12">
<td> Date to Depart <b class="icon_required" style="color:#FF0000">*</b></td>
<td align="center">:</td>
<td>
<input type="text" name="departDate" class="tcal" value="" />
<font class="font12gray">[dd-mm-yyyy]</font></td>
</tr>
<tr class="font12">
<td> Time to Depart <b class="icon_required" style="color:#FF0000">*</b></td>
<td align="center">:</td>
<td>
<select name="timeDepart">
<option value="-">-Sila Pilih-</option>
<option value="01:00" >1:00</option>
<option value="01:30" >1:30</option>
<option value="02:00" >2:00</option>
<option value="02:30" >2:30</option>
<option value="03:00" >3:00</option>
<option value="03:30" >3:30</option>
<option value="04:00" >4:00</option>
<option value="04:30" >4:30</option>
<option value="05:00" >5:00</option>
<option value="05:30" >5:30</option>
<option value="06:00" >6:00</option>
<option value="06:30" >6:30</option>
<option value="07:00" >7:00</option>
<option value="07:30" >7:30</option>
<option value="08:00" >8:00</option>
<option value="08:30" >8:30</option>
<option value="09:00" >9:00</option>
<option value="09:30" >9:30</option>
<option value="10:00" >10:00</option>
<option value="10:30" >10:30</option>
<option value="11:00" >11:00</option>
<option value="11:30" >11:30</option>
<option value="12:00" >12:00</option>
<option value="12:30" >12:30</option>
</select>
<select name="waktuDepart">
<option value="" > - </option>
<option value="Pagi" > Pagi</option>
<option value="Tengahari" >Tengahari</option>
<option value="Petang" >Petang</option>
<option value="Malam" >Malam</option>
</select>
</td>
</tr>
<tr class="font12">
<td> Date to Return <b class="icon_required" style="color:#FF0000">*</b></td>
<td align="center">:</td>
<td><input type="text" name="returnDate" class="tcal" value="" />
<font class="font12gray">[dd-mm-yyyy]</font></td>
</tr>
<tr class="font12">
<td> Time to Return <b class="icon_required" style="color:#FF0000">*</b></td>
<td align="center">:</td>
<td><select name="returnTime">
<option value="-">-Sila Pilih-</option>
<option value="01:00" >1:00</option>
<option value="01:30" >1:30</option>
<option value="02:00" >2:00</option>
<option value="02:30" >2:30</option>
<option value="03:00" >3:00</option>
<option value="03:30" >3:30</option>
<option value="04:00" >4:00</option>
<option value="04:30" >4:30</option>
<option value="05:00" >5:00</option>
<option value="05:30" >5:30</option>
<option value="06:00" >6:00</option>
<option value="06:30" >6:30</option>
<option value="07:00" >7:00</option>
<option value="07:30" >7:30</option>
<option value="08:00" >8:00</option>
<option value="08:30" >8:30</option>
<option value="09:00" >9:00</option>
<option value="09:30" >9:30</option>
<option value="10:00" >10:00</option>
<option value="10:30" >10:30</option>
<option value="11:00" >11:00</option>
<option value="11:30" >11:30</option>
<option value="12:00" >12:00</option>
<option value="12:30" >12:30</option>
</select>
<select name="waktuReturn">
<option value="" >- </option>
<option value="Pagi" >Pagi</option>
<option value="Tengahari" >Tengahari</option>
<option value="Petang" >Petang</option>
<option value="Malam" >Malam</option>
</select>
</td>
</tr>
</table>
<center><input type="submit" name="submit" value="Hantar" style="cursor:pointer" onclick="myFunction()"> [ kembali ]<br></center>
</td></tr></table>
</form>
I am trying to get the value from a selectbox. The form is placed multiple times on my page with a php loop (that's why I use classes instead of id's).
<html>
<body>
<table>
<form class="lesmaker">
<tr>
<td colspan="5">
<select name="type" class="type">
<option value="open">Open vraag</option>
<option value="info">Informatie</option>
<option value="discussie">Klassikaal</option>
<option value="meerkeuze" selected="selected">Meerkeuze</option>
</select>
</td>
</tr>
<tr>
<td colspan="5">
<select name="media" class="media">
<?php foreach($images as $image){if(substr($image,0,1) != '.'){ ?>
<option style="background-image:url(<?=$d_images.$image?>)" value="<?=$image?>" <?php if($r_media== $image) echo 'selected="selected"'; ?>><?=$image?></option>
<?php }} ?>
</select>
</td>
</tr>
</form>
</table>
<table>
<form class="lesmaker">
<tr>
<td colspan="5">
<select name="type" class="type">
<option value="open">Open vraag</option>
<option value="info">Informatie</option>
<option value="discussie">Klassikaal</option>
<option value="meerkeuze" selected="selected">Meerkeuze</option>
</select>
</td>
</tr>
<tr>
<td colspan="5">
<select name="media" class="media">
<?php foreach($images as $image){if(substr($image,0,1) != '.'){ ?>
<option style="background-image:url(<?=$d_images.$image?>)" value="<?=$image?>" <?php if($r_media== $image) echo 'selected="selected"'; ?>><?=$image?></option>
<?php }} ?>
</select>
</td>
</tr>
</form>
</table>
</body>
</html>
With jQuery I am trying to get the selected option.
$(function(){
$('.lesmaker').each(function() {
console.log($(this).find('.type').val());
});
});
The code above is not working. How do I need to do this?
$(function() {
$('.lesmaker').each(function() {
console.log($(this).find('table tr td').find('.type').val());
});
});
You need to change your HTML to following:
<form class="lesmaker">
<table>
<tr>
<td colspan="5">
<select name="type" class="type">
<option value="open">Open vraag</option>
<option value="info">Informatie</option>
<option value="discussie">Klassikaal</option>
<option value="meerkeuze" selected="selected">Meerkeuze</option>
</select>
</td>
</tr>
</table>
</form>
form needs to be either outside of table or inside of td :)
$(function() {
$('.type').each(function() {
console.log($('option:selected', this).val());
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table>
<form class="lesmaker">
<tr>
<td colspan="5">
<select name="type" class="type">
<option value="open">Open vraag</option>
<option value="info">Informatie</option>
<option value="discussie">Klassikaal</option>
<option value="meerkeuze" selected="selected">Meerkeuze</option>
</select>
</td>
</tr>
<tr>
<td colspan="5">
<select name="type" class="type">
<option value="open">Open vraag</option>
<option value="info">Informatie</option>
<option value="discussie" selected="selected">Klassikaal</option>
<option value="meerkeuze" >Meerkeuze</option>
</select>
</td>
</tr>
<tr>
<td colspan="5">
<select name="type" class="type">
<option value="open">Open vraag</option>
<option value="info" selected="selected">Informatie</option>
<option value="discussie" >Klassikaal</option>
<option value="meerkeuze" >Meerkeuze</option>
</select>
</td>
</tr>
</form>
</table>
Just use the class of select and use $('option:selected', this).val()
I'm trying to figure out how to make a query that sets the rows (number of weeks) depending on the number of weeks the instructor wants the clinical to go, this value is stored in a Mysql table called clinical with a column name weeks (int). Right now in my HTML I have just pasted 4 rows to get the look down. I realize I will need to make a connection to the db before this code
<table width="1000" border="1">
<tr>
<td colspan="8" style="background-color:#1589FF;text-align:center;">
<h1>Rating for the Week</h1>
</td>
<tr>
<th>Week</th>
<th>Faculty Signature</th>
<th>Rating for the Week <br>
S+/S/NI/U</th>
<th>Student Signature</th>
<th>Rating for the Week <br>
S+/S/NI/U</th>
</tr>
<tr>
<tr ALIGN="CENTER">
<td>1</td>
<td><form><input type = "submit" /></form></td>
<td><select>
<option value="S+">S+</option>
<option value="S">S</option>
<option value="NI">NI</option>
<option value="U">U</option>
</select></td>
<td><form><input type = "submit" /></form></td>
<td><select>
<option value="S+">S+</option>
<option value="S">S</option>
<option value="NI">NI</option>
<option value="U">U</option>
</select></td>
</tr>
<tr>
<tr ALIGN="CENTER">
<td>2</td>
<td><form><input type = "submit" /></form></td>
<td><select>
<option value="S+">S+</option>
<option value="S">S</option>
<option value="NI">NI</option>
<option value="U">U</option>
</select></td>
<td><form><input type = "submit" /></form></td>
<td><select>
<option value="S+">S+</option>
<option value="S">S</option>
<option value="NI">NI</option>
<option value="U">U</option>
</select></td>
</tr>
<tr>
<tr ALIGN="CENTER">
<td>3</td>
<td><form><input type = "submit" /></form></td>
<td><select>
<option value="S+">S+</option>
<option value="S">S</option>
<option value="NI">NI</option>
<option value="U">U</option>
</select></td>
<td><form><input type = "submit" /></form></td>
<td><select>
<option value="S+">S+</option>
<option value="S">S</option>
<option value="NI">NI</option>
<option value="U">U</option>
</select></td>
</tr>
<tr>
<tr ALIGN="CENTER">
<td>4</td>
<td><form><input type = "submit" /></form></td>
<td><select>
<option value="S+">S+</option>
<option value="S">S</option>
<option value="NI">NI</option>
<option value="U">U</option>
</select></td>
<td><form><input type = "submit" /></form></td>
<td><select>
<option value="S+">S+</option>
<option value="S">S</option>
<option value="NI">NI</option>
<option value="U">U</option>
</select></td>
</tr>
<tr>
<td colspan="8" style="background-color:#1589FF;text-align:center;">
<b> The student must pass the clinical component of the course which is ted on a pass/fail basis.<br>
A clinical failure results in a grade of F for the course.<b>
</td>
</tr>
</table>
</body>
</html>
The query would look like this:
SELECT weeks FROM `clinical` WHERE clinicname = $clinicname
The query will select the column weeks from the table clinical
I added the WHERE statement because if there are multiple clinics it would choose the appropriate one, as long as you have the column clinicname included in your table.
To make a row for each week you would create a while loop like so:
<?php
$number_of_weeks_from_query = $query_result;
$i = 0;
while($i < $number_of_weeks_from_query){
INSERT EACH ROW TEMPLATE HERE AND CHANGE THE WEEK NUMBER TO $i
$i++;
}
?>
I would suggest using Mysql PDO as the old MySql functions will be deprecated very soon. I would also suggest to use AJAX so you can keep the page loaded when someone hits the submit button. Please tell me if I did anything wrong, my PHP is still rusty.