I have the following code to display posts in a forum discussion.
I would like the person who posted a reaction to see two buttons:
A delete button
An edit button
I can't seem to find a way to connect the user session to the userid in the forumberichten table. Is there anyone who can help me with this? I've tried a lot of things, but I keep getting the buttons on all the posts.
<?php
if (isset($_REQUEST['id'])){
$id = preg_replace('#[^a-z0-9]#i', '', $_GET['id']);
}
$user = $_SESSION['SESS_USERID'];
if (isset($_REQUEST['user'])){
$user = preg_replace('#[^a-z0-9]#i', '', $_GET['user']);
}
$sql="SELECT forumberichten.bericht_id,forumberichten.discussieid,forumberichten.userid,forumberichten.omschrijving,forumberichten.datum, forumberichten.active,users.userid,users.username,users.userimage FROM forumberichten,users WHERE forumberichten.userid=users.userid AND forumberichten.active='yes' AND forumberichten.discussieid='".$id."' ORDER BY discussieid DESC";
$result = $conn->query($sql);
if ($result->num_rows >=1) {
while($row = $result->fetch_assoc()) {
echo "
<br><table width='450' border='0'>
<tr><td bgcolor='#1E1E1E'> </td>
<td colspan='5' bgcolor='#1E1E1E'><a href='user.php? id=" . $row['userid'] . "'</a> ".$row["username"]."</td>
<td> </td></tr>
<tr><td bgcolor='#1E1E1E'> </td>
<td colspan='5' bgcolor='#1E1E1E'>
";
if ($row["userimage"] == '') {
echo "
<a href='user.php? id=" . $row['userid'] . "'</a>
<img src='Images/users/nopicture.png' alt='nopicture' class='user-imagelarge' title='".$row['username']."''>
</a>
";
} else {
echo "
<a href='user.php? id=" . $row['userid'] . "'</a>
<img src='Images/users/".$row['userimage']."' class='user-imagelarge' title='".$row['username']."''>
</a>
";
}
echo "
</td>
<td> </td></tr>
<tr><td bgcolor='#1E1E1E'> </td>
<td colspan='5' bgcolor='#1E1E1E'>".$row['omschrijving']."</td>
<td> </td></tr>
<tr><td bgcolor='#1E1E1E'> </td>
<td bgcolor='#1E1E1E'>
";
echo date("d-m-y H:i",strtotime($row["datum"]));"</td>";
// HERE I DON'T KNOW WHAT TO DO SO ONLY THE POSTER OF THIS MESSAGE CAN SEE THE FOLLOWING BUTTONS:
echo "
<td bgcolor='#1E1E1E'><a href='forumberichtbewerk.php? id=" . $row['bericht_id'] . "' target='_blank'>
<input type='image' src='Images/Icons/penorange.png' width='15' height='15'></a></td>
<td bgcolor='#1E1E1E'><a href='forumberichtdelete.php? id=" . $row['bericht_id'] . "'><input type='image' class='backgroundgreyfotoos' src='Images/Icons/crossorangebutton.png' width='15' height='15' border='0' ></a></td>
<td bgcolor='#1E1E1E'></td>
<td bgcolor='#1E1E1E'></td>
<td> </td></tr>
<tr><td bgcolor='#1E1E1E'> </td>
<td colspan='5' bgcolor='#1E1E1E'><img src='Images/lijntransparant.png' width='570' height='2'></td>
<td><img src='Images/lijntransparant.png' width='35' height='2'></td></tr>
</table>
";
}
}
?>
Related
I neeed some help with the next and preview buttons, i want to make a button show me the next or preview information of my data but I donĀ“t know how, also it have to stay in the same webpage. What i mean is that i have thousands of data and im showing only 10, so the next botton is to refresh and show the next 10 rows of information. Here is my code:
<td><table border="2" cellpadding="0">
<tr>
<th colspan='9'>Ejemplares</th>
<tr>
<td width="150">
Titular
</td>
<td width="150">
Criador
</td>
<td width="125">
Nombre
</td>
<td width="80">
Chip
</td>
<td width="80">
Estado
</td>
<td width="60">
Capa LG
</td>
<td width="50">
Sexo
</td>
<td width="125">
Grado Generacional
</td>
</tr>
<?php
$database="caballos"; //database name
$con = mysqli_connect("127.0.0.1","root" ,"",$database)
or die('Could not connect to database server ');
$query = "SELECT * FROM caballo";
$result = mysqli_query($con,$query);
$nfilas = mysqli_num_rows ($result);
for ($i=0; $i<$nfilas; $i++)
{
$resultado = mysqli_fetch_array ($result);
print ("<TR>\n");
print ("<TD width='150px'>" . $resultado['titular'] . "</TD>\n");
print ("<TD width='150px'>" . $resultado['criador'] . "</TD>\n");
print ("<TD width='125px'>" . $resultado['nombre'] . "</TD>\n");
print ("<TD width='75px'>" . $resultado['chip'] . "</TD>\n");
print ("<TD width='75px'>" . $resultado['estado'] . "</TD>\n");
print ("<TD width='150px'>" . $resultado['capalg'] . "</TD>\n");
print ("<TD width='50px'>" . $resultado['sex'] . "</TD>\n");
print ("<TD width='150px'>" . $resultado['grado_gen'] . "</TD>\n");
print ("</TR>\n");
}
mysqli_close($con);
?>
</tr>
</td>
<tr>
<td colspan="2">
<input type="button" value="INGRESAR" onclick= "self.location.href = 'ing_caballos.php'" /></td>
<td colspan="2">
<input type="button" value="GENEALOGIA" onclick= "self.location.href = 'genealogia.php'" /></td>
<td>
<!--hear goes the next and preview buttons-->
</td>
<td colspan="2">
<input type="button" value="ELIMINAR" onclick= "self.location.href = 'del_caballo.php'" />
</td>
</tr>
</tr>
You are looking for a pagination script , try this tutorial
I'm trying to create echo image in while loops with table, but I'm getting the error . please see part of the code
$image = $rows['image'];
$sql = "SELECT * FROM boxes ";
$result = $db->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
if ($row['status'] == 1)
$visible = "visible";
else
$visible = "hidden";
if ($row['side'] == 1)
$side = "right";
else if ($row['side'] == 2)
$side = "left";
else $side = "not set yet";
echo "
<tr>
<td width=\"15%\" rowspan=\"3\"><img src="data:image' image \. ($row['image']).'" />';</td>
<td width=\"85%\" colspan=\"5\">".$row['title_boxe'] . "</td>
</tr>
<tr>
<td colspan=\"5\">desc</td>
</tr>
<tr>
<td>Visible</td>
<td>sss</td>
<td><form method='post'><input type='hidden' name='id' value='" . $row['id_boxe'] . "'/>
<input type='submit' name='update' value='Update' class=\"btn btn-primary\"/></form></td>
<td> </td>
</tr>
<tr>
<td colspan=\"6\">hr</td>
</tr>
<tr>
<td colspan=\"6\"> </td>
</tr>
";
}
}
?>
</tbody>
</table>
what wrong with this line of code inside of php that i can figure out how to solve this...
<td width=\"15%\" rowspan=\"3\"><img src="data:image' image \. ($row['image']).'" />';</td>
many thanks for your help.
Seems that you echo is wrong ( and to me is not clear what you are doing with <src='data:image image .. if you need a \ but this interfer
with quote escape it using \
echo "
<tr>
<td width='15%' rowspan='3'><img src='../image/box-manage/" . $row['image'] ."' />;</td>
<td width='85%' colspan='5'>". $row['title_boxe'] . "</td>
</tr>
<tr>
<td colspan='5'>desc</td>
</tr>
<tr>
<td>Visible</td>
<td>sss</td>
<td><form method='post'><input type='hidden' name='id' value='" . $row['id_boxe'] . "'/>
<input type='submit' name='update' value='Update' class='btn btn-primary'/></form></td>
<td> </td>
</tr>
<tr>
<td colspan='6'>hr</td>
</tr>
<tr>
<td colspan='6'> </td>
</tr>";
I have a PHP based website for jobs. I echo all the jobs from database in a table below. When i click on a job in table row it shows the job details in an iframe beside the table.
This is the code of the table and iframe index.php
<table class="table1">
<tr>
<td colspan="3">
<?php
include "job.header.php";
?>
</td>
</tr>
<tr>
<td width="30%">
<div>
<?php
require "module/job.call.php";
?>
</div>
</td>
<td width="60%">
<iframe name="content" src="../module/job.unclicked.php">
</iframe>
</td>
<td width="20%"> </td>
</tr>
</table>
This is the code that i call jobs from the database job.call.php
<?php
$result = mysqli_query($conn,"SELECT * FROM job where approved='1' ORDER BY `CreatedTime` DESC");
echo "<table id='maintable' class='table-fill' border='0' cellpadding='0' cellspacing='0'>
<tr>
<th position='fixed' overflow='hidden' width='10%'>Job Title</th>
<th position='fixed' width='5%'>Company Name</th>
<th width='5%'>Closing Date</th>
</tr>";
while($row = mysqli_fetch_array($result) ) {
if (strlen($row['positiontitle']) > 20)
$row['positiontitle'] = substr($row['positiontitle'], 0, 60) . "...";
echo "<tr ref='job.details.php?id=".$row['id']."' target='content' class='positiontitle-link'>";
echo "<td><font style='text-shadow: none;'>" . $row['positiontitle'] . "</font></a></td>";
echo "<td>" . $row['companyname'] . "</td>";
echo "<td>" . $row['closingdate'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($conn);
?>
I want that when i click on the job in the table row then the address bar should take the id of the job. because if someone wants to share the job then they should just send that address for specific job.
Now it show like this
I want that it should look like this
Here is my php code to select and delete rows form table:
<h1>Deleting Multiple Records using PHP & MySQL</h1>
<p> </p>
<?php
These are my db connection:
$host = "localhost"; // Host name
$username = "root"; // Mysql username
$password = ""; // Mysql password
$db_name = "project"; // Changed database name
$tbl_name = "users";
mysql_connect($host, $username, $password) or die("cannot connect");
mysql_select_db($db_name) or die("cannot select DB");
$sql = "SELECT * FROM $tbl_name";
$result = mysql_query($sql);
$count = mysql_num_rows($result);
?>
Here is my html code to retrieve data from database:
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr><td><form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"><tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mysql</strong> </td> </tr>
<tr><td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>First Name</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Last Name</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Gender</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Phone Number</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Experiance</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>User Name</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Password</strong></td>
</tr>
<?php while ($rows = mysql_fetch_array($result, MYSQL_ASSOC)) { ?>
<tr>
<td align="center" bgcolor="#FFFFFF">
<input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td>
<td bgcolor="#FFFFFF"><?php echo $rows['id']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['fname']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['lname']; ?> </td>
<td bgcolor="#FFFFFF"><?php echo $rows['gend']; ?> </td>
<td bgcolor="#FFFFFF"><?php echo $rows['phone']; ?> </td>
<td bgcolor="#FFFFFF"><?php echo $rows['exp']; ?> </td>
<td bgcolor="#FFFFFF"><?php echo $rows['uname']; ?> </td>
<td bgcolor="#FFFFFF"><?php echo $rows['pwd']; ?> </td>
</tr>
<?php } ?>
<tr><td colspan="5" align="center" bgcolor="#FFFFFF">
<input name="delete" type="submit" id="delete" value="Delete" onclick="javascript:confirm('Are you sure to delete')"></td></tr>
<?php
if(isset($_POST['delete'])){
$checkbox = $_POST['checkbox'];
for($i=0;$i<count($_POST['checkbox']);$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM $tbl_name WHERE id='$del_id'";
print $sql;
$result = mysql_query($sql);}
if($result){echo "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">";}}
mysql_close();
?>
</table></form></td></tr></table>
<p>Record count: <?php echo number_format($count) ?></p>*/
I tried many times but it not deleting a single row from table.
just now i changed the code of executing query....please check it and inform me...
What is this query
$sql = "DEFRE FROM users WHERE id in (" . implode(",", $deleteIds) . ") ";
??
For deleting you should do something like this
$sql = "DELETE FROM users WHERE id IN (" . implode(",", $deleteIds) . ") ";
In the code
if (isset($_POST['checkbox']) && count($_POST['checkbox']) > 0)
{
$deleteIds = $_POST['checkbox']; // it will be an array
$sql = "DELETE FROM users WHERE id in (" . implode(",", $deleteIds) . ") ";
// run the query
}
We need to see the actual code trying to "delete". The usual mysql_query($sql) won't work. You have to use mysql_exec() instead of mysql_query().
Update: Sorry, I was confusing another form of query. mysql_query("delete from table where (whatever)") should work, though it returns true on success or false on failure, not a rowset.
I deleted one line ID from my program and i got the answer and it's working fine.
<tr>
<td align="center" bgcolor="#FFFFFF">
<input name="checkbox[]" type="checkbox" id="checkbox[]" value='<?php echo $row['id']; ?>'></td>
<td bgcolor="#FFFFFF"><?php echo $row['fname']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $row['lname']; ?> </td>
<td bgcolor="#FFFFFF"><?php echo $row['gend']; ?> </td>
<td bgcolor="#FFFFFF"><?php echo $row['phone']; ?> </td>
<td bgcolor="#FFFFFF"><?php echo $row['exp']; ?> </td>
<td bgcolor="#FFFFFF"><?php echo $row['uname']; ?> </td>
<td bgcolor="#FFFFFF"><?php echo $row['pwd']; ?> </td>
</tr>
<?php } ?>
<tr><td colspan="5" align="center" bgcolor="#FFFFFF">
<input name="delete" type="submit" id="delete" value="Delete" onclick="javascript:confirm('Are you sure to delete')"></td></tr>
<?php
if(isset($_POST['delete'])){
$checkbox = $_POST['checkbox'];
for($i=0;$i<count($_POST['checkbox']);$i++){
$del_id = $checkbox[$i];
//print '$del_id';
$sql = "DELETE FROM users WHERE id='$del_id'";
//print $sql;
$result = mysql_query($sql);}
}
if($result){
echo"successfully deleted";
}
mysql_close();
?>
</table></form></td></tr></table>
<p>Record count: <?php echo number_format($count) ?></p>
I just want to simplify what I am doing before, having multiple php files for all data to be listed.
Here is my html form:
<table border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#D3D3D3">
<tr>
<form name="formcheck" method="post" action="list.php" onsubmit="return formCheck(this);">
<td>
<table border="0" cellpadding="3" cellspacing="1" bgcolor="">
<tr>
<td colspan="16" height="25" style="background:#5C915C; color:white; border:white 1px solid; text-align: left"><strong><font size="3">List Students</td>
</tr>
<tr>
<td width="30" height="35"><font size="3">*List:</td>
<td width="30"><input name="specific" type="text" id="specific" maxlength="25" value="">
</td>
<td><font size="3">*By:</td>
<td>
<select name="general" id="general">
<font size="3">
<option>Year</option>
<option>Address</option>
</select></td></td>
</tr>
<tr>
<td width="10"><input align="right" type="submit" name="Submit" value="Submit" > </td>
</tr>
</form>
</table>
And here's the form action:
<?php
$con = mysql_connect("localhost","root","nitoryolai123$%^");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("school", $con);
$gyear= $_POST['general'];
if ("YEAR"==$_POST['general']) {
$result = mysql_query("SELECT * FROM student WHERE YEAR='{$_POST["specific"]}'");
echo "<table border='1'>
<tr>
<th>IDNO</th>
<th>YEAR</th>
<th>LASTNAME</th>
<th>FIRSTNAME</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['IDNO'] . "</td>";
echo "<td>" . $row['YEAR'] . "</td>";
echo "<td>" . $row['LASTNAME'] . "</td>";
echo "<td>" . $row['FIRSTNAME'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
mysql_close($con);
?>
Please help, how do I equate the YEAR(column in mysql database) and the option box(general).
if ("YEAR"==$_POST['general'])
please correct me if I'm wrong.
<option>Year</option>
you just need to change that to
<option value="YEAR">Year</option>
also definitely have a read of this page : http://en.wikipedia.org/wiki/SQL_injection because otherwise your code is wide open to nasty attacks.
[edit : also pay heed to the comments on your original question, posting your real root username/password on a website isn't a very good idea.]
if ("YEAR"==$_POST['general']) {
$result = mysql_query("SELECT * FROM student WHERE date_format(YEAR, '%Y')='{$_POST["specific"]}'");