dividing the table for the result - html

I have a query that selects the names in the table.
and I wanted to divide the result into 15 names per table data.
is it possible that the next 15 names will display in the next table data? how?
<?php
extract($_POST);
if($_POST['filter1'] == "Individual"){
if(isset($submitsearch)){
//if(!empty($searchquery)){
$sql = "SELECT * FROM contact_individual WHERE name LIKE '%$searchquery%' ORDER BY name";
$query = mysql_query($sql);
$count = mysql_num_rows($query);
for($x=0;$x<$count;$x++){
$data = mysql_fetch_array($query);
?>
<table class="tsearch">
<tr>
<td>
<form method="GET" action="resultindividualprofile.php">
<input type="text" name="text" hidden="hide" value="<?echo $data['contactID_individual'];?>"/>
<input type="submit" class="rep" name="this" value="<?echo $data['name'];?>"/>
<!--<?php //echo $data['name']; ?>-->
</form>
</td>
</tr>
</table>
EDIT:

Do this :
<?php
if($_POST['filter1'] == "Individual"){
$sql = "SELECT * FROM contact_individual WHERE name LIKE '%".$searchquery."%' ORDER BY name";
$query = mysql_query($sql) or die(mysql_error());
$count = mysql_num_rows($query);
?>
<table class="tsearch">
<?php
$x=0;
while($data = mysql_fetch_array($query))
{
if($x > 0 && $x%15==0)
{
echo '</table><table class="tsearch">';
}
?>
<tr>
<td>
<form method="GET" action="resultindividualprofile.php">
<input type="text" name="text" hidden="hide" value="<?echo $data['contactID_individual'];?>"/>
<input type="submit" class="rep" name="this" value="<?echo $data['name'];?>"/>
<!--<?php //echo $data['name']; ?>-->
</form>
</td>
</tr>
<?php $x++; } ?>
</table>
<?php } ?>

Related

I am unable to find if the row already exists in mysql db using time function in php mysql query?

i am currently working on a module where faculty can post attendance to the students by selecting a dropdown(select box) which is generated dynamically by the information given by the faculty.When faculty selects a particular year and section respected student list is retrived and displayed in a table.But the requirement is once the attendance is posted to a particular class/section on a particular it cannot be opened again by the faculty
I have tried using mysql_num_rows() function to check if any rows are already present in the db or not on that particular date.But its not working the way i wanted
here is my entire code of the module excluding db file
<form action="take.php" method="Post">
<br>
<table class="table table-bordered table-hover ">
<tr>
<th>S.no</th>
<th>Student Name</th>
<th>Roll Number</th>
<th>Present</th>
<th>Absent</th>
</tr>
<?php
if (isset($_POST['search']))
{
$stu="Student";
$yr=$_POST['year'];
$se=$_POST['section'];
$subdr=mysql_query("SELECT subject FROM schedule WHERE id='$cuid' AND day='$d' AND class='$yr' AND section='$se'");
$subj=mysql_fetch_assoc($subdr);
$dis_date=date("Y-m-d H:i:s");
$subj_d=$subj['subject'];
$display=mysql_query("select * from attendance_records where id='$cuid' AND ondate='".$dis_date."' And subject='$subj_d'");
$rec=mysql_num_rows($display);
if($rec){
echo "Records posted";
}
else{
$display=mysql_query("select name,id from login where role='$stu' AND academic='$yr' AND section='$se'");
$sno=0;
$count=0;
while ($row=mysql_fetch_array($display)) {
$sno++;
?>
<tr>
<td><?php echo $sno ?></td>
<td>
<?php echo $row['name'] ?>
<input type="hidden" name="name[]" value="<?php echo $row['name'] ?>">
</td>
<td>
<?php echo $row['id'] ?>
<input type="hidden" name="id[]" value="<?php echo $row['id'] ?>">
</td>
<td>
<input type="radio" name="attendance_status[<?php echo $count ?>]" value="Present" required>
</td>
<td>
<input type="radio" name="attendance_status[<?php echo $count ?>]" value="Absent" required>
</td>
</tr>
<?php
$count++;
}
}
?>
<tr>
<td colspan=5>
<center><label><?php echo "Subject : ".$subj['subject']; ?></label></center>
</td>
</tr>
<input type="hidden" name="yr" value="<?php echo $_POST['year']; ?>">
<input type="hidden" name="set" value="<?php echo $_POST['section']; ?>">
<?php
} ?>
</table>
<center><input type="submit" name="submit" value="Submit" class="btn btn-primary" >
</center>
</div>
the expected output should display a message saying "Records posted" based on query like :
$dis_date=date("Y-m-d H:i:s");
$subj_d=$subj['subject'];
$display=mysql_query("select * from attendance_records where id='$cuid'
AND ondate='".$dis_date."' And subject='$subj_d'");
$rec=mysql_num_rows($display);
if($rec){
echo "Records posted";
}
else{
#display the student list
}
Your assignment is:
$dis_date=date("Y-m-d H:i:s");
so $dis_date contains both a date and a time of day. The query will only match if the records in the table have the exact same time of day, not just the same date.
You should leave the time out of the variable:
$dis_date=date("Y-m-d");
If the datatype of the column in the table is DATETIME, you also need to filter out the time from that, with:
AND DATE(ondate)='$dis_date' And subject='$subj_d'"
You don't need to do this if the datatype is DATE.

insert array in radiobutton. 0 for false answer and 1 for correct answer

Im having trouble with radio buttons, I dont have idea to insert the value which have correct answer. if selected the value must be 1 while the other is 0. this is my code :
<form method='post' action='exam.php?act=input' enctype='multipart/form-data'>
<table>
<tr></tr>
<tr>
<td>Nama Exam </td>
<td><input type='text' name='nama_exam'></td>
</tr>
<tr>
<td>Soal </td>
<td><textarea name='soal_exam'></textarea></td>
</tr>
<tr>
<td></td>
<td><input type='radio' name='answer'> <textarea name='option[]'></textarea></td>
</tr>
<tr>
<td></td>
<td><input type='radio' name='answer'> <textarea name='option[]'></textarea></td>
</tr>
<tr>
<td></td>
<td><input type='radio' name='answer'> <textarea name='option[]'></textarea></td>
</tr>
<tr>
<td></td>
<td><input type='radio' name='answer'> <textarea name='option[]'></textarea></td>
</tr>
</table>
<button type='submit'>Submit</button>
</form>
and this is the insert code :
<?php
$name = $_POST['nama_exam'];
$exam = $_POST['soal_exam'];
$op = $_POST['option'];
$answer = $_POST['answer'];
//if selected = 1 else = 0
$sql = mysql_query("INSERT INTO `exam`(`exam_name`, `exam`, `exam_entrydate`) VALUES ('$name','$exam',NOW())");
if ($sql){
$v_sql = mysql_query("SELECT * FROM exam order by exam_id DESC limit 1");
$id = mysql_fetch_array($v_soal);
$id_soal = $id['exam_id'];
$pil = count($op);
for($i=0; $i<$pil; $i++){
$sql_pil = mysql_query("INSERT INTO answer (`answer_examcode`,`answer`, `answer_code`,`answer_entrydate`) values ('$id_soal','$op[$i]','$answer',NOW())");
}
echo"
<script language='javascript'>
alert('Data ditambahkan')
document.location='exam.php?act=default'
</script>";
}
use looping at your post form to post array to insert code file :
<?php
for($i=1; $i<=4; $i++){
echo "<tr>
<td></td>
<td><input type='radio' value='$i' name='answer'> <textarea name='option[$i]'></textarea></td>
</tr>";
}
?>
then you get array in insert code file like this :
<?php
$name = $_POST['nama_exam'];
$exam = $_POST['soal_exam'];
$op = $_POST['option'];
$answer = $_POST['answer'];
foreach($op as $i=>$op){
if($answer==$i){
$ans=1;
}else{
$ans=0;
}
$sql_pil = mysql_query("INSERT INTO answer (`answer_examcode`,`answer`, `answer_code`,`answer_entrydate`) values ('$id_soal','$op','$ans',NOW())");
}
?>

$_POST array in wrong order?

like to submit the array via $_POST, it works only with one foreach, how can i combine two foreach-arrays without getting everything doubled?
i tried it with "keTitle" and and "keSoll", but only once at a time works..
html:
<div class="table-responsive">
<table class="table table-striped">
<thead>
<td>Kühlgerät</td>
<td>Soll</td>
<td>Ist</td>
</thead>
<tbody>
<?php
$todo_query = mysqli_query($db, "SELECT * FROM temp_ke WHERE ListID = '1'");
while($row2 = mysqli_fetch_object($todo_query))
{
?>
<tr>
<th scope="row">
<?php echo "$row2->keTitle"; ?>
<input name="Title[<? echo "$row2->keTitle";?>]" value="<? echo "$row2->keTitle";?>" type="hidden">
</th>
<td><?php echo "$row2->keSoll"; ?> °C<br>
<input name="SollWert[<? echo "$row2->keSoll";?>]" value="<? echo "$row2->keSoll";?>" type="hidden">
</td>
<td>
<input class="shortinput" name="IstWert[]" value="" type="text"> °C<br>
</td>
</tr>
<?php }} ?>
</tbody>
</table>
<div class="tablefooter">Ausgefüllt von: <input name="Mitarbeiter" value="" type="text"></div>
<br>
<input type="submit" class="btn btn-default" value="Temperaturen eintragen">
</form>
</div>
next page to $_POST to:
<?php
foreach ($_POST['Title'] as $keTitle) {
foreach ($_POST['SollWert'] as $keSoll) {
echo "$keSoll<br>";
echo "$keTitle<br><br>";
}
}
?>
form value
$_POST['Title'] = 'Mein Titel';
$_POST['SollWert'] = '123';
thats the array:
$ksTitle = $_POST['Title'];
$keSoll = $_POST['SollWert'];
echo "$keSoll<br/>";
echo "$keTitle<br/>";
or in foreach:
foreach( $_POST AS $value){
echo $value . "<br/>";
}
output:
Mein Titel
123

emailing the contents of a form

How would I create a form in HTML that would email the content of the form to an email? Here is what I have.
<form action="mailto:email#example.com" enctype="text/plain" method="post">
<input name = "subject" placeholder = "Your Name"></input>
<br>
<textarea name = "message" placeholder = "Email Us." style = "height:100px;"></textarea>
<input type="submit" value="Submit" placeholder = "Submit"></input>
</form>
could I do this solely in HTML with the mailto: action? or would i need some php like
mail('email#example.com', $_POST['subject'], $_POST['message']);
Any suggestions?
Please try to use header as well to sending a email.
<?php
$to = 'connormemail#gmail.com';
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = 'From: connormemail#gmail.com' . "\r\n";
$retval = mail($to, $subject, $message, $headers);
if( $retval == true )
{
echo "Message sent successfully...";
}
else
{
echo "Message could not be sent...";
}
?>
So there is all kind of wrong in what I'm about to post. Such as don't use tables to style your forms, etc. But I'm taking this off another site so it'll be simple. What you need is a mix of html for the form and php for the mailing.
<form name="contactform" method="post" action="send_form_email.php">
<table width="450px">
<tr>
<td valign="top">
<label for="first_name">First Name *</label>
</td>
<td valign="top">
<input type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top"">
<label for="last_name">Last Name *</label>
</td>
<td valign="top">
<input type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="email">Email Address *</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="telephone">Telephone Number</label>
</td>
<td valign="top">
<input type="text" name="telephone" maxlength="30" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="comments">Comments *</label>
</td>
<td valign="top">
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit">
Email Form
</td>
</tr>
</table>
So there is your basic form.
Here is your basic php. Place it in the same directory as your .html file: send_form_email.php (you must use this filename exactly)
Make sure to edit the parts indicated with your email and subject line.
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "you#yourdomain.com";
$email_subject = "Your email subject line";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
If you need to see this tutorial in it's entirety, it's located here:http://www.freecontactform.com/email_form.php
In order to make a custom form it is pretty easy to edit the html and related php elements, but if you don't know any php, etc. I'd just stick to the premade forms.

Can't Update My Database

I can't update my database.. I wonder why it's not working while it worked on my other pages. I'm receiving this error:
You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version
for the right syntax to use near 'WHERE id =1' at line 4
This is the code:
<?php require_once("include/connect.php"); ?>
<?php require("include/bp_function.php"); ?>
<?php url(); ?>
<?php
$title = mysql_prep($_POST['title']);
$content = mysql_prep($_POST['content']);
$id = mysql_prep($_GET['aboutusid']);
$query = "UPDATE aboutus SET
title='{$title}',
content='{$content}',
WHERE id ={$id}";
mysql_query($query);
if(mysql_affected_rows() == 1) {
echo "Succesfully Updated {$title}
<br/>Go back to Backpanel";
} else {
echo "failed {$id}<br />".mysql_error()."<p> </p>";
}
?>
<?php require_once("include/footer.php"); ?>`
This is the form:
<?php require("include/connect.php"); ?>
<?php require("include/bp_function.php"); ?>
<?php url(); ?>
<?php include("include/bp_header.php"); ?>
<div id="bgcontainer">
<!-- NEWS CONTAINER -->
<div id="bodycont">
<div id="left_page">
<h2>About Us Menu</h2>
<?php list_of_aboutus(); ?>
<br />+ Add Menu
<hr />
</div>
<div id="right_page">
<h2>Edit: <?php echo $s_aboutus['title']; ?> </h2>
<br /><br />
<form action="query_editaboutus.php?aboutusid=<?php echo urlencode($s_aboutus['id']); ?>" method="post" enctype="multipart/form-data">
<table>
<tr valign="top"><td width="100px">Title:</td> <td><input name="title" type="name" size="45" value="<?php echo $s_aboutus['title']; ?>" /></td></tr>
<tr valign="top"><td width="100px">Content:</td> <td>
<textarea name="content" cols="45" rows="20" value="" > <?php echo $s_aboutus['content']; ?> </textarea>
<tr valign="top"><td width="100px">Update:</td><td><input type="submit" id="submit" value="Update" /></td></tr>
</table>
</form>
</div>
<!-- MEDIA CONTAINER -->
<?php include("include/footer.php"); ?>
Remove the comma after setting the content field.
$query = "UPDATE aboutus SET title='{$title}', content='{$content}' WHERE id ={$id}";
Original for comparison
$query = "UPDATE aboutus SET title='{$title}', content='{$content}', WHERE id ={$id}";
Check your update statement
$query = "UPDATE aboutus SET
title='{$title}',
content='{$content}'
WHERE id ={$id}";