i need to break the line after a reach of 10 buttons - php

I need to break the line after a reach of 10 buttons.
Please be specific what are the code to be used for breaking the line.
Here is the code:
<?php
session_start();
require('connection.php');
$result = mysql_query("SELECT * FROM tbCandidates ");
if($result){
}
echo "select Project to Reward for";
$_SESSION['a']="project name-->";
echo "<body><form method='post' action='part1.php' ><input type='hidden' value='abhishek' name='aa'/>";
echo "<table><tr>";
while ($row=mysql_fetch_array($result)){
echo "<td>";
echo $row["project_id"];
echo '<input type="radio" name="n1" value="';echo $row["project_id"]; echo '">'; echo"</input>";
$_SESSION['b']=$row['candidate_name'];
$_SESSION['c']=$row['candidate_position'];
$_SESSION['c']=$row['candidate_nominee'];
echo "</td>";
}
echo "</tr></table><input type='submit'/></form></body>";

If you mean by BREAKING the line is creating another row for your table then try to use the following codes:
<?php
session_start();
require('connection.php');
$result = mysql_query("SELECT * FROM tbCandidates ");
if($result){
}
echo "select Project to Reward for";
$_SESSION['a']="project name-->";
echo "<body><form method='post' action='part1.php' ><input type='hidden' value='abhishek' name='aa'/>";
echo "<table>";
$counter = 0;
while ($row=mysql_fetch_array($result)){
$counter++;
if($counter==1){
echo "<tr>";
}
echo "<td>";
echo $row["project_id"];
echo '<input type="radio" name="n1" value="';echo $row["project_id"]; echo '">'; echo"</input>";
$_SESSION['b']=$row['candidate_name'];
$_SESSION['c']=$row['candidate_position'];
$_SESSION['c']=$row['candidate_nominee'];
echo "</td>";
if($counter==10){
echo "</tr>";
$counter = 0;
}
}
echo "</table><input type='submit'/></form></body>";
Let me know if it works.

Related

how to display auto increment data form mysql in php

In my university database project I have an auto increment field roll number in my SQL. What I want is that when new admission take place and a student record is inserted it displays all finds on same page including roll number. However despite my best efforts all it returns 0 in roll number.
Here is the code:
<?php
$con = mysqli_connect("localhost", "root", "") or die("conection error");
mysqli_select_db($con, "hamdard university") or die("dbase error");
if (isset($_POST['subbtn'])) {
$r = "SELECT RollNo FROM admission_form";
$result = mysqli_query($con, $r);
if (mysqli_query($con, $r)) {
$last_id = mysqli_insert_id($con);
}
$n = $_POST['txtname'];
$f = $_POST['txtfac'];
$s = $_POST['txtsem'];
$sql = "insert into admission_form(name,faculty,semester)values ('$n','$f','$s')";
mysqli_query($con, $sql);
echo "<table border=1>
<th>RollNo</th>
<th>Name</th>
<th>Faculty</th>
<th>Semester</th>";
echo "<tr>";
echo "<td>";
echo $last_id;
echo "</td>";
echo "<td>";
echo $n;
echo "</td>";
echo "<td>";
echo $f;
echo "</td>";
echo "<td>";
echo $s;
echo "</td>";
echo "<br>";
}
?>
<html>
<head></head>
<body>
<form name="f1" action="" method="POST">
RollNo:
<input type="text" name="txtroll" readonly> Name:
<input type="text" name="txtname"> Faculty:
<input type="text" name="txtfac"> Semester:
<input type="text" name="txtsem">
<input type="submit" value="done" name="subbtn">
</form>
</body>
</html>
You need get $last_id after INSERT query
$sql="insert into admission_form(name,faculty,semester)values ...
mysqli_query($con,$sql);
$last_id = mysqli_insert_id($con);
You have misplaced insert query. Change it as:
<?php
$con=mysqli_connect("localhost","root","")or die("conection error");
mysqli_select_db($con,"hamdard university")or die("dbase error");
if(isset($_POST['subbtn']))
{
$sql="insert into admission_form(name,faculty,semester)values ('$n','$f','$s')";
if (mysqli_query($con, $sql))
{
$last_id = mysqli_insert_id($con);
}
$n=$_POST['txtname'];
$f=$_POST['txtfac'];
$s=$_POST['txtsem'];
$r="SELECT RollNo FROM admission_form";
$result=mysqli_query($con, $r);
echo "<table border=1>
<th>RollNo</th>
<th>Name</th>
<th>Faculty</th>
<th>Semester</th>";
echo "<tr>";
echo "<td>";
echo $last_id;
echo "</td>";
echo "<td>";
echo $n;
echo "</td>";
echo "<td>";
echo $f;
echo "</td>";
echo "<td>";
echo $s;
echo "</td>";
echo "<br>";
}
?>
<html>
<head></head>
<body>
<form name="f1" action="" method="POST">
RollNo:<input type="text" name="txtroll" readonly>
Name:<input type="text" name="txtname">
Faculty:<input type="text" name="txtfac">
Semester:<input type="text" name="txtsem">
<input type="submit" value="done" name="subbtn">
</form>
</body>
</html>
You have some problems in this page.
As stated before, the INSER query must be before the select.
If you do "SELECT RollNo FROM admission_form" you will get ALL existing RollNo in admission_form and not the lastest one. If this is an int with auto increment (that seams to be) you should do "SELECT max(RollNo) FROM admission_form".
You don't need to do the above select, as mysqli_insert_id get the ID inserted in the last query.
You might not see the result in your table because it is on HTML head, but it should be in the body of the page.
The table you create is not "closed".
You should be good to go with the code bellow.
<HTML>
<HEAD></HEAD>
<BODY>
<?php
$con=mysqli_connect("localhost","root","")or die("conection error");
mysqli_select_db($con,"hamdard university")or die("dbase error");
if(isset($_POST['subbtn']))
{
$n=$_POST['txtname'];
$f=$_POST['txtfac'];
$s=$_POST['txtsem'];
$sql="insert into admission_form(name,faculty,semester) values ('$n','$f','$s')";
if (mysqli_query($con, $r))
{
$last_id = mysqli_insert_id($con);
}
echo "<table border=\"1\"><th>RollNo</th> <th>Name</th> <th>Faculty</th> <th>Semester</th>";
echo "<tr>";
echo "<td>";
echo $last_id;
echo "</td>";
echo "<td>";
echo $n;
echo "</td>";
echo "<td>";
echo $f;
echo "</td>";
echo "<td>";
echo $s;
echo "</td>";
echo "</tr></table>";
}
?>
<form name="f1" action="" method="POST">
RollNo:<input type="text" name="txtroll" readonly>
Name:<input type="text" name="txtname">
Faculty:<input type="text" name="txtfac">
Semester:<input type="text" name="txtsem">
<input type="submit" value="done" name="subbtn">
</form>
</body>
</html>
Try this:
$mysqli = new mysqli(SQLI_SERVER, MYSQLI_USER, MYSQLI_PWD, MYSQLI_DBNAME);
if ($result = $mysqli->query("INSERT INTO admission_form(name, facility,semester) VALUES..) {
echo 'The ID is: '.$mysqli->insert_id;
}

php multiple search textbox with one submit button

i would like to know how can i make a multiple search criteria with 2 or more textboxes and only one submit button.
my script is:
$sql = "select * from wp_studenti ";
if (isset($_POST['search'])) {
$search_term = mysql_real_escape_string($_POST['search_box']);
$sql .= " WHERE nume= '{$search_term}' ";
}
$query = mysql_query($sql) or die (mysql_error());
echo "<form name ='search_form' method='POST' action='search.php'>";
echo "<center><h3>Cauta:</h3> <input type='text' name='search_box' />";
echo "<input type='submit' name='search' value='Cauta' /></center>";
echo "</form>";
and my results page that shows after search page:
$sql = "select * from wp_studenti ";
if (isset($_POST['search'])) {
$search_term = mysql_real_escape_string($_POST['search_box']);
$sql .= "WHERE nume= '{$search_term}'";
}
echo "<center>\n";
echo "<table border='1'>";
echo "<thead>";
echo "<tr><th>Id</th>";
echo "<th>Nume</th>";
echo "<th>Localitate</th>";
echo "<th>Judet</th>";
echo "<th>Sector Financiar</th>";
echo "<th>Link</th></tr>";
echo "</thead>";
$rst = mysql_query($sql);
while($a_row = mysql_fetch_assoc($rst)) {
echo "<tr>";
echo "<td>"; echo $a_row['id']; echo "</td>";
echo "<td>"; echo $a_row['nume']; echo "</td>";
echo "<td>"; echo $a_row['localitate']; echo "</td>";
echo "<td>"; echo $a_row['judet']; echo "</td>";
echo "<td>"; echo $a_row['sector_financiar']; echo "</td>";
echo "<td>"; echo "<a href='results.php?id={$a_row['id']}'>{$a_row['link']}</a>" ; echo "</td>";echo "</tr>";
echo "</table>";
$sql = "select * from wp_studenti ";
if (isset($_POST['search'])) {
$search_term_by_Cauta = mysql_real_escape_string($_POST['search_box_1']);
$search_term_by_localitate = mysql_real_escape_string($_POST['search_box_2']);
//If you want both search mandatory, use "AND" Operator otherwise use "OR". If you want approximate search use "LIKE" Operator in bellow SQL
$sql .= " WHERE nume= '{$search_term_by_Cauta }' OR localitate = '{$search_term_by_localitate }' ";
}
$query = mysql_query($sql) or die (mysql_error());
echo "<form name ='search_form' method='POST' action='search.php'>";
echo "<center><h3>Cauta:</h3> <input type='text' name='search_box_1' />";
echo "<h3>localitate:</h3> <input type='text' name='search_box_2' />";
echo "<input type='submit' name='search' value='Cauta' /></center>";
echo "</form>";
Well you need another search box:
echo "<center><h3>Cauta:</h3> <input type='text' name='search_box1' /><input type='text' name='search_box2' />";
And you need to use that value in your SQL:
if (isset($_POST['search'])) {
$search_term1 = mysql_real_escape_string($_POST['search_box1']);
$search_term2 = mysql_real_escape_string($_POST['search_box2']);
$sql .= " WHERE nume= '{$search_term1}' OR nume= '{$search_term2}'";
}
But you will have to do some thinking about how the search should work, is it supposed to match exactly one OR the other? If you want the text to contain instead of exactly match, you can use the syntax nume LIKE '%searchword%'
Use mysqli instead of mysql, which is depreciated. By PHP, something like this;
<form method='post'>
<input type='hidden' name='srch' val='1'>
Search Type1: <input type='text' name='s1'>
<br>
Search Type2: <input type='text' name='s2'>
<button>Submit</button>
</form>
<?php
if(isset($_POST['srch']))
{
if(!empty($_POST['s1']))$search = $_POST['s1'];
else if(!empty($_POST['s2']))$search = $_POST['s2'];
else die ('No criteria entered');
rest of your code...
}
?>
Also see functions like mysqli_real_escape for security reasons.

how to save selected value from drop down list to mysql in php

<?php
$status=&$_POST['status'];
$from=&$_POST['date_from'];
$to=&$_POST['date_to'];
$conn=mysqli_connect('localhost','root','','punbus') or die("Database not connected".mysqli_error());
if(isset($_POST['sub'])){
$ins="insert into driver_status(driver_name,status,date_from,date_to)
select Driver_name,'$status','$from','$to' from driver_master";
if(mysqli_query($conn,$ins)){
echo "added";
}
else{
echo "NOT".mysqli_error($conn);
}
}
$sel='select Driver_name from driver_master';
$query=mysqli_query($conn,$sel);
echo "<form action='driver_status.php' method='post'>";
echo "<table cellpadding=5>";
echo "<tr>";
echo "<th>Driver Name</th>";
echo "<th>Status</th>";
echo "<th>From</th>";
echo "<th>To</th>";
echo "</tr>";
while($row=mysqli_fetch_assoc($query)){
echo "<tr>";
echo "<td>".$row['Driver_name']."</td>";
$sel1='select d_status from status';
$query1=mysqli_query($conn,$sel1);
?>
<td>
<select name="status">
<?php
while($row1=mysqli_fetch_assoc($query1)){
$st=$row1['d_status'];
echo "<option value='$st'>$st</option>";
}
?>
</select>
</td>
<?php
echo "</tr>";
}
echo "</table>";
echo '<input type="submit" name="sub" value="Update"/>';
echo "</form>";
?>
That is my code. I want to save option selected from 4 drop down list to mysql. When I submit the form, the value selected from last box are getting saved in all rows of mysql table. Now, please tell me what should I do?
I am getting drop down box values from database table properly so what is the problem?
this is your code.
<?php
$status = $_POST['status'];
$driver_name= $_POST['driver_name'];
$from = $_POST['date_from'];
$to = $_POST['date_to'];
$conn = mysqli_connect('localhost', 'root', '', 'punbus') or
die("Database not connected" . mysqli_error());
if(isset($_POST['sub'])) {
foreach($status as $k=>$s){
$ins = "insert into driver_status(driver_name,status,date_from,date_to) VALUES
('".$driver_name[$k]."','$s','$from','$to')";
if (mysqli_query($conn, $ins)) {
echo "added";
} else {
echo "NOT" . mysqli_error($conn);
}
}
}
$sel = 'select Driver_name from driver_master';
$query = mysqli_query($conn, $sel);
echo "<form action='driver_status.php' method='post'>";
echo "<table cellpadding=5>";
echo "<tr>";
echo "<th>Driver Name</th>";
echo "<th>Status</th>";
echo "<th>From</th>";
echo "<th>To</th>";
echo "</tr>";
while($row=mysqli_fetch_assoc($query)){
echo "<tr><td>".$row['Driver_name']
."<input type=\"hidden\" name=\"driver_name[]\" value=\"".$row['Driver_name']."\"/></td>";
$sel1='select d_status from status';
$query1=mysqli_query($conn,$sel1);
echo "<td><select name=\"status[]\">";
while($row1=mysqli_fetch_assoc($query1)){
echo "<option value=\"".$row1['d_status']."\">".$row1['d_status']."</option>";
}
echo "</select></td></tr>";
}
echo "</table>";
echo '<input type="submit" name="sub" value="Update"/>';
echo "</form>";
?>
this is similar to other textbox
$op="select * from client where active=0";
$op1=mysql_query($op);
echo '<select name="c" id="c" style="width:160px;" required>';
while ($row = mysql_fetch_array($op1))
{
echo $s=$row["c_name"];
if($company!=$s)
{
echo '<option value="'.$row["c_name"].'">'.$row["c_name"].'</option>';
}
}
$c=$_REQUEST['c'];
$sql="insert into project c_name) values('$c')";
$sql1=mysql_query($sql);

Pass multiple values selectedincheckboxto anotherpage to Delete

I want to store the multiple values selected in checkbox from one page to another in which another page will perform the delete operation.I want to pass the value and receive the value in another page.Here is my code:
<?php include 'menu.php';?>
<?php include 'menu_admin.php';?>
<link rel = "stylesheet" type="text/css" href="Form.css">
<?php include 'connect.php';?>
<?php
$sql = "SELECT * FROM ads";
$result = $db->query($sql);
//the function num_rows() checks if there are more than zero rows returned
if ($result->num_rows > 0) {
echo "<table><tr><th>SELECT</th><th>ADID</th><th>ADName</th><th>ADCATEGORY</th><th>CONTACTNUMBER</th><th>EXPIRATIONDATE</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>
<input type='checkbox' id = 'checkbox' name='checkbox[]' value=".$row['ADID']." > ".$row['ADID']."
</td>";
echo "<td>" .$row["ADID"]. "</td>";
echo "<td><a href=#>" .$row["ADNAME"]. "</a></td>";
echo "<td>" .$row["ADCATEGORY"]. "</td>";
echo "<td>" .$row["CONTACTNUMBER"]. "</td>";
echo "<td>" .$row["EXPIRATIONDATE"]. "</td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$result->free();
?>
<?php
$myCheckVar = $_POST['checkbox'];
?>
<input type="submit" value='Delete' name="Delete" onClick="window.location='deletead.php?myvalue=$myCheckVar';"/>
<input type="submit" value='Update' name="update"/>
<input type="submit" value="New" name="new" onClick="window.location='post_ad.php?user=$username';"/>
Please Help
Encapsulate your table in a form tag and set the action to your control file. You can access the POST variable as an array.
Try something like the code below. Todo: change YOUR_URL_TO_CATCH_THE_FORM to the URL which needs to catch the form.
<?php include 'menu.php';?>
<?php include 'menu_admin.php';?>
<link rel = "stylesheet" type="text/css" href="Form.css">
<?php include 'connect.php';?>
<?php
$sql = "SELECT * FROM ads";
$result = $db->query($sql);
//the function num_rows() checks if there are more than zero rows returned
if ($result->num_rows > 0) {
echo "<form action=\"YOUR_URL_TO_CATCH_THE_FORM\" method=\"POST\">";
echo "<table><tr><th>SELECT</th><th>ADID</th><th>ADName</th><th>ADCATEGORY</th><th>CONTACTNUMBER</th><th>EXPIRATIONDATE</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>
<input type='checkbox' id = 'checkbox' name='checkbox[]' value=".$row['ADID']." > ".$row['ADID']."
</td>";
echo "<td>" .$row["ADID"]. "</td>";
echo "<td><a href=#>" .$row["ADNAME"]. "</a></td>";
echo "<td>" .$row["ADCATEGORY"]. "</td>";
echo "<td>" .$row["CONTACTNUMBER"]. "</td>";
echo "<td>" .$row["EXPIRATIONDATE"]. "</td>";
echo "</tr>";
}
echo "</table>";
echo "</form>";
} else {
echo "0 results";
}
Then catch the form POST in your "YOUR_URL_TO_CATCH_THE_FORM" php with something like this:
if(isset($_POST) && !empty($_POST))
{
if(isset($_POST['checkbox']) && !empty($_POST['checkbox']))
{
foreach($_POST['checkbox'] as $key => $value)
{
echo 'This is checkbox value '.$key.': '.$value;
}
}
}

PHP/MySQL Row Buttons

<?php
$query = "SELECT * FROM table1";
$result = mysql_query($query)
or die ("Query Failed: " . mysql_error());
echo "<TABLE BORDER = '1'>";
echo "<TR>";
echo "<TH>Unique ID</TH><TH>URL</TH><TH>First Name</TH><TH>Last Name</TH><TH>Mail</TH><TH>Time Entered</TH>";
echo "</TR>";
while ($row = mysql_fetch_array($result))
{
echo "<TR>";
echo "<TD>",
$row['Unique_ID'], "</TD><TD>",
$row['url'], "</TD><TD>",
$row['fname'], "</TD><TD>",
$row['lname'], "</TD><TD>",
$row['mail'], "</TD><TD>",
$row['time'], "</TD>";
echo "</TR>";
}
echo "</TABLE>";
echo "<br>";
?>
I have the above piece of code, and I would like to automatically insert buttons at the end of each row: edit & delete. Please help?
Also, in the same piece of code-these buttons-I would like to create them as simple MySQL quereid, but then ho will the script know for which row to apply the queries?
echo '<td><form action="/delete.php" method="POST">';
echo '<input type="hidden" name="id" value="'.$row['Unique_ID'].'">';
echo '<input type="submit" value="Delete"></form>';
echo '<form action="/edit.php" method="GET">';
echo '<input type="hidden" name="id" value="'.$row['Unique_ID'].'">';
echo '<input type="submit" value="Edit"></form></td>';
Something like that?
EDIT: cleaned up a bit for clarity

Categories