HTML Button doesn't work in IE, but other browsers fine - php

I am writing a small database viewer.. I have a link at the bottom as you can see sending an id to another page. This button works on every other browser except IE.
Any ideas?
If I click on it on IE, it does nothing.
<?php
include_once('include/opendb.php');
$query = "SELECT id, rep, date, account, areacode, number, address1, address2, city, state, zip, fax, descmaker1, descmaker2, title, email, cvendor, cequipment, leaseexp1, leaseexp2, leaseexp3, leaseexp4, leaseexp5, leaseexp6, volume, notes FROM accounts";
$result = mysql_query($query);
$entrytotal = mysql_num_rows($result);
echo '<div id="entrytotal">' . $entrytotal . ' Total Accounts</div>';
while($row = mysql_fetch_row($result)){
$id = $row[0];
$rep = $row[1];
$date = $row[2];
$account = $row[3];
$areacode = $row[4];
$number = $row[5];
$address1 = $row[6];
$address2 = $row[7];
$city = $row[8];
$descmaker1 = $row[12];
$descmaker2 = $row[13];
$title = $row[14];
$email = $row[15];
$cvendor = $row[16];
$cequipment = $row[17];
$leaseexp1 = $row[18];
$leaseexp3 = $row[20];
$volume = $row[24];
echo '<tr>';
echo '<td width="120" align="middle"><font color="black"><b>' . $rep . '</b></font></td>';
echo '<td width="120" align="middle"><font color="black"><b>' . $date . '</b></font></td>';
echo '<td width="120" align="middle"><font color="black"><b>' . $account . '</b></font></td>';
echo '<td width="120" align="middle"><font color="black"><b>' . $address1 . '</b></font></td>';
echo '<td width="120" align="middle"><font color="black"><b>' . $city . '</b></font></td>';
echo '<td width="120" align="middle"><font color="black"><b>' . $descmaker1 . '</b></font></td>';
echo '<td width="120" align="middle"><font color="black"><b>' . $descmaker2 . '</b></font></td>';
echo '<td width="120" align="middle"><font color="black"><b>' . $title . '</b></font></td>';
echo '<td width="120" align="middle"><font color="black"><b>' . $cvendor . '</b></font></td>';
echo '<td width="120" align="middle"><font color="black"><b>' . $leaseexp1 . '</b></font></td>';
echo '<td width="120" align="middle"><font color="black"><b>' . $leaseexp3 . '</b></font></td>';
echo "<td width='120' align='middle'><a href='info.php?id=" . $id . "'><input style='font-family:Helvetica; width: 50px;' type='submit' value='Info'></a></td>";
echo '</tr>';
}
?>

Just a few quick notes without testing it but:
You can just style an anchor link to look like a button, no need to put a button inside an anchor tag.
As to the previous point, if you are just trying to link to another page you don't need an input element. Just the link.
If you indeed are trying to submit a form I don't see any <form> tags in your example.

I suggest you do this instead:
<input style='font-family:Helvetica; width: 50px;' type='button' value='Info' onclick="location.href='info.php?id=<?php echo $id; ?>'">
EDIT
Note: you need to remove the link tag surrounding the button.

You don't really need a button without a form. you could just use a link.
echo "<td width='120' align='middle'>
<a href='info.php?id=" . $id . "'>Info</a>
</td>";
and if you'd like to style it, just use a span like so
<td width='120' align='middle'>
<a href='info.php?id=" . $id . "'>
<span style='font-family:Helvetica; width: 50px; border:1px solid #000; padding:5px; background-color:#ccc;'>Info</span>
</a>
</td>

The other answers are correct.
Here's some HTML to help:
<form method="post"><!-- or method="get" if you're not changing anything -->
<!-- other hidden input data here -->
<input type="hidden" name="id" value="<?php echo $id; ?>">
<input type="submit" value="Info">
</form>

Related

HTML Problem in displaying the items in different lines

I am trying to show three copies of the image in each line dynamically when I read it from the database, but it shows all the images next to each other. I tried to edit the code so it copies it but didn't work
How to make show three images in each line regardless of the number of items in the database?
Here is my code:
<?php
session_start();
require "init.php";
login();
?>
<html>
<head>
<title> Expert System </title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<table border='1' align='center' >
<?php
// LOGIN USER
function login(){
global $con;
global $counter;
//$email = $mysqli->escape_string('');
$query="SELECT * FROM users ";
$result=mysqli_query($con,$query);
if ( $result->num_rows == 0 ) // User doesn't exist
echo "User with that ID doesn't exist!";
else { // User exists
$counter=0;
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo '<td>
<img src="images/' . $row["category"]. '" width="250px" height= "150px" alt="Avatar" >
</td>';
echo '<td>
<img src="images/' . $row["category"]. '" width="250px" height= "150px" alt="Avatar" >
</td>';
echo '<td>
<img src="images/' . $row["category"]. '" width="250px" height= "150px" alt="Avatar" >
</td>';
echo "</tr>";
}
}
}
mysqli_close($con);
?>
</table>
</body>
</html>
According to a long discussion with the owner of this question, I'm posting my solution.
In your code you have to just move the table tag inside function.
<?php
// LOGIN USER
function login(){
// write remaining code.... and then use this while loop
echo '<table border="1" align="center">';
while($row = $result->fetch_assoc())
{ echo '<tr>';
// If you want 2 images in a row than use $i<= 2
for($i= 1; $i<= 3; $i++)
{
echo '<td><img src="images/' . $row["category"]. '" width="250px" height= "150px" alt="Avatar" ></td>';
}
echo '</tr>';
} // while
} // login()
Just use <tr> <img...> <tr> and remove <td> tag. <tr> represents row and <td> represents column. So because your <img> is inside <td> tags in <tr>, it is appearing in one row.
Here echo will not work, first made complete HTML then echo it once at the end. let see the example below.
Let see below, first what I am observing is that you are adding the same image thrice while it looks like you want to append the next image in the next row not the same image in each row.
Below I am just changing your code to show images in separate rows
$imagetags = "";
while($row = $result->fetch_assoc()) {
$imagetags .= "<tr><td>";
$imagetags .= '<img src="images/' . $row["category"]. '" width="250px" height= "150px" alt="Avatar" >'
$imagetags .= "</td></tr>";
$imagetags .= "<tr><td>";
$imagetags .= '<img src="images/' . $row["category"]. '" width="250px" height= "150px" alt="Avatar" >'
$imagetags .= "</td></tr>";
$imagetags .= "<tr><td>";
$imagetags .= '<img src="images/' . $row["category"]. '" width="250px" height= "150px" alt="Avatar" >'
$imagetags .= "</td></tr>";
}
But to show next image from DB row, in next row on HTML, you have to made changes in your code like below
$imagetags = "";
while($row = $result->fetch_assoc()) {
$imagetags .= "<tr><td>";
$imagetags .= '<img src="images/' . $row["category"]. '" width="250px" height= "150px" alt="Avatar" >'
$imagetags .= "</td></tr>";
}
that what shows with your code:
and that with my code:
You declared function inside of table but you called it before any html,that is why your images are not inside a table and not styled correctly, try this
<?php
session_start();
require "init.php";
// LOGIN USER
function login(){
global $con;
global $counter;
//$email = $mysqli->escape_string('');
$query="SELECT * FROM users ";
$result=mysqli_query($con,$query);
if ( $result->num_rows == 0 ) // User doesn't exist
echo "User with that ID doesn't exist!";
else { // User exists
$counter=0;
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo '<td>
<img src="images/' . $row["category"]. '" width="250px" height= "150px" alt="Avatar" >
</td>';
echo '<td>
<img src="images/' . $row["category"]. '" width="250px" height= "150px" alt="Avatar" >
</td>';
echo '<td>
<img src="images/' . $row["category"]. '" width="250px" height= "150px" alt="Avatar" >
</td>';
echo "</tr>";
}
}
}
mysqli_close($con);
?>
<html>
<head>
<title> Expert System </title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<table border='1' align='center' >
<?php login(); ?>
</table>
</body>
</html>

PHP display images dynamically in grid pattern

I'm new to php and I'm working with a tutorial about showing images dynamically on the page, it works fine but it shows them vertically and I would like them to be horizontal. I created a page with code to do that but I can't seem to figure out where to insert the code to get the images to show.
Thanks for any help.
Vertical output looks like this
$dynamicList = "";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added ASC LIMIT 6");
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$product_name = $row["product_name"];
$price = $row["price"];
$details = $row["details"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .= '<table width="1000px" border="0" cellspacing="0" cellpadding="6" align="center">
<tr>
<td width="1000px" align="center"><img style="border:#666 0px solid;" src="images/' . $id . '.jpg" width="50%" height="50%" alt="' . $product_name . '" width="77" height="102" border="1" /></td>
<td width="83%" valign="top">' . $product_name . '<br />
$' . $price . '<br /> $' . $details . '<br />
order</td>
</tr>
</table>';
}
mysql_close();
?>
Grid Output
$sql = mysql_query("SELECT * FROM products ORDER BY id ASC LIMIT 15");
$i = 0;
// Establish the output variable
$dynamiclist = '<table width="1000px" border="1" cellspacing="2" cellpadding="10" align="center">';
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$product_name = $row["product_name"];
$details = $row["details"];
$price = $row["price"];
if ($i % 3 == 0) { // if $i is divisible by our target number (in this case "3")
$dynamiclist .= '<tr><td>' . $product_name . '</br>' . $details . '</br>' . $price . '</td>';
} else {
$dynamiclist .= '<td>' . $product_name . '</td>';
}
$i++;
}
$dynamiclist .= '</tr></table>';
?>
I got it figured out, Thanks for the help.
$sql = mysql_query("SELECT * FROM products ORDER BY id ASC LIMIT 15");
$i = 0;
// Establish the output variable
$dynamiclist = "";
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$product_name = $row["product_name"];
$details = $row["details"];
$price = $row["price"];
if ($i % 4 == 0) { // if $i is divisible by our target number (in this case "3")
$dynamiclist .= '<tr><td width="250px" align="center"><img src="images/' . $id . '.jpg"><br/>' . $product_name . '<br />
' . $details . '<br /> $' . $price . '<br />
order</td>';
} else {
$dynamiclist .= '<td width="250px" align="center"><img src="images/' . $id . '.jpg"><br/>' . $product_name . '<br />
' . $details . '<br /> $' . $price . '<br />
order</td>';
}
$i++;
}
$dynamiclist .= '</tr></table>';
?>

SQL query doesn't give the right result

I have a form where people can search the database for four values:
Location, Period, Day and Service. I always do not get the results that I want.
If I use AND, people need to fill in everything. If I use OR I get the complete database. I want to be able to search the database for those one to 4 things. Is there a way how I can do this?
Is there maybe a way to check which fields are filled in, and that the query is automatically changed with the filled in fields?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Zoeken</title>
</head>
<body>
<p><img src="add.png" width="20px" height="20px"/> | <img src="search.png" width="20px" height="20px"/> | <img src="number.png" width="20px" height="20px"/> </p>
<form action="" method="post">
<div>
<table>
<tr><td><strong>Locatie: </strong></td><td><input type="text" name="Locatie" value="" /></td> </tr>
<tr><td><strong>Periode: </strong></td><td><input type="text" name="Periode" value="" /></td> </tr>
<tr><td><strong>Dag: </strong></td><td><input type="text" name="Dag" value="" /></td> </tr>
<tr><td><strong>Dienst: </strong></td> <td><input type="text" name="Dienst" value="" /></td></tr>
<tr><td></td><td><input type="submit" name="zoeken" value="Zoeken"></td></tr>
</table>
</div>
</form>
<p><img src="add.png" width="20px" height="20px"/> | <img src="search.png" width="20px" height="20px"/> | <img src="number.png" width="20px" height="20px"/> </p>
</body>
</html>
<?php
if (isset($_POST['zoeken']))
{
include('connect-db.php');
$Locatie = $_POST['Locatie'];
$Periode = $_POST['Periode'];
$Dag = $_POST['Dag'];
$Dienst = $_POST['Dienst'];
// get results from database
$result = mysql_query("SELECT * FROM WMC_DeLijn WHERE Locatie='$Locatie' ANY Periode='$Periode' ANY Dag='$Dag'ANY Dienst='$Dienst' ")
or die(mysql_error());
// display data in table
echo "<h2>Resultaten:</h2><p>";
echo "<table border='1' cellpadding='10'>";
echo "<table><tr><th>ID</th><th>Locatie</th><th>Periode</th><th>Dag</th><th>Dienst</th><th>Delen</th><th>Geleed</th><th>Start 1</th><th>Eind 1</th><th>Start 2</th><th>Eind 2</th><th>Lijnen</th></tr>";
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $result )) {
// echo out the contents of each row into a table
echo "<tr>";
echo '<td align="center">' . $row['id'] . '</td>';
echo '<td align="center">' . $row['Locatie'] . '</td>';
echo '<td align="center">' . $row['Periode'] . '</td>';
echo '<td align="center">' . $row['Dag'] . '</td>';
echo '<td align="center">' . $row['Dienst'] . '</td>';
echo '<td align="center">' . $row['Delen'] . '</td>';
echo '<td align="center">' . $row['Geleed'] . '</td>';
echo '<td align="center">' . $row['Start1'] . '</td>';
echo '<td align="center">' . $row['Eind1'] . '</td>';
echo '<td align="center">' . $row['Start2'] . '</td>';
echo '<td align="center">' . $row['Eind2'] . '</td>';
echo '<td align="center">' . $row['Lijnen'] . '</td>';
//Link to edit record
echo '<td align="center"><img src="edit.png" width="20px" height="20px"/></td>';
// Link to delete record
echo '<td align="center"><img src="delete.png" width="20px" height="20px"/></td>';
//Link to Add Event to Google Calendar
echo '<td align="center"><img src="proceed.png" width="20px" height="20px"/></td>';
echo "</tr>";
}}
// close table>
echo "</table>";
?>
You can either build the query string dynamically, only adding WHERE clause statements if the parameter is not falsy, or add conditions in the SQL itself like so: WHERE (col = ? OR '' = ?) AND (col2 = ? OR '' = ?).
Change your query to have either a AND condition or a OR condition like
SELECT * FROM WMC_DeLijn
WHERE Locatie='$Locatie'
AND Periode='$Periode'
AND Dag='$Dag'
AND ienst='$Dienst';
(OR)
SELECT * FROM WMC_DeLijn
WHERE Locatie='$Locatie'
OR Periode='$Periode'
OR Dag='$Dag'
OR ienst='$Dienst';

Use PHP variable in href inside of html inside of php?

So I'm trying to make a cart for my website (nothing too special, uni project).
Currently I have
$product_id = $row["ID"];
$product_name = $row['name'];
$product_price = $row['price'];
$product_image = $row['img'];
$imgurl = ".\img\\".$product_image;
if ($i % 3 == 0) { // if $i is divisible by our target number (in this case "3")
$dyn_table .= '<tr><td align="center" valign="middle" width="350">'. "<img src=$imgurl width='100' hieght='100'> <br />" . $product_name . '<br /> &pound'.$product_price . '<br /><a href="./cart.php?product="$product_id"&action=add" />Add to Card</a></td>';
} else {
$dyn_table .= '<td align="center" valign="middle" width="350">'. "<img src=$imgurl width='100' hieght='100'> <br />" . $product_name . '<br /> &pound'.$product_price . '<a href="./cart.php?product=$product_id&action=add" />Add to Card</a></td>';
I need to have the product ID inserted in href where I have $product_id
<a href="./cart.php?product=$product_id&action=add" />Add to Card</a>
Currenly, it loads the links as domain.com/cart.php?product=$product_id&action=add
you can use variable name between quotes
provided if it is a single quoted you have to put {} around variable
else if it is a double quotes you can directly use the varibale
if ($i % 3 == 0) {
$dyn_table .= "<tr><td align='center' valign='middle' width='350'>". "<img src=$imgurl width='100' hieght='100'> <br />" . $product_name . "<br /> &pound".$product_price . "<br />
<a href='./cart.php?product={$product_id}&action=add' />Add to Card</a></td>";
} else {
$dyn_table .= "<td align='center' valign='middle' width='350'>". "<img src=$imgurl width='100' hieght='100'> <br />" . $product_name . "<br /> &pound".$product_price . "<a href='./cart.php?product={$product_id}&action=add' />Add to Card</a></td>";
}
The variable has to be extracted from the string, in PHP, so:
<a href="./cart.php?product='.$product_id.'&action=add" />Add to Card</a>
Like you did for your other variables.
this:
$dyn_table .= '<tr><td align="center" valign="middle" width="350">'."<img src=$imgurl width='100' hieght='100'><br />" . $product_name.'<br /> &pound'.$product_price .'<br /><a href="./cart.php?product=" .$product_id. "&action=add." />Add to Card</a></td>';
Your original problem was that you didn't jump out of single quotes properly to add $product_id in, however there's another instrumental problem in your code.
You should either use all '' single quotes or all "" double quotes, not a combination of both. It makes it hard to read and is unnecessary regardless.
Therefore, it should be either
$dyn_table .= '<tr><td align="center" valign="middle" width="350"><img src="' . $imgurl . '" width="100" hieght="100"> <br />' . $product_name . '<br /> £' . $product_price . '<br /><a href="./cart.php?product=' . $product_id . '&action=add" />Add to Card</a></td>';
or
$dyn_table .= "<tr><td align=\"center\" valign=\"middle\" width=\"350\"><img src=\"$imgurl\" width=\"100\" hieght=\"100\"> <br />$product_name<br /> £$product_price<br /><a href=\"./cart.php?product=$product_id&action=add\" />Add to Card</a></td>";
In this case, I'd probably use single quotes so I don't have to escape all the double quotes in the HTML, or perhaps even a heredoc, but I won't get into those for now.
Your code for single quotes would be
if ($i % 3 == 0) { // if $i is divisible by our target number (in this case "3")
$dyn_table .= '<tr><td align="center" valign="middle" width="350"><img src="' . $imgurl . '" width="100" height="100"> <br />' . $product_name . '<br /> £' . $product_price . '<br /><a href="./cart.php?product=' . $product_id . '&action=add" />Add to Card</a></td>';
} else {
$dyn_table .= '<td align="center" valign="middle" width="350"><img src="' . $imgurl . '" width="100" hieght="100"> <br />' . $product_name . '<br /> £' . $product_price . '<a href="./cart.php?product=' . $product_id . '&action=add" />Add to Card</a></td>';
I'd suggest you look up heredocs though, you may find those easier.

how to display an image in pagination?

How will i Display a picture with the same id here in my pagination.php?
i tried doing this
<td width="20%" valign="top"><a href="product.php?id=' . $id . '">
<img style="border:#666 2px solid;" src="inventory_images/' . $id . '.jpg" width="150" height="102" border="1" /></a>
</td>
but it wont work.. any possible way to display the image using pagination?
for ($i = $start; $i < $end; $i++)
{
// make sure that PHP doesn't try to show results that don't exist
if ($i == $total_results) { break; }
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . mysql_result($result, $i, 'product_name') . '</td>';
echo '<td>' . mysql_result($result, $i, 'price') . '</td>';
echo '<td>' . mysql_result($result, $i, 'details') . '</td>';
echo '<td>' . mysql_result($result, $i, 'category') . '</td>';
echo '<td>' . mysql_result($result, $i, 'subcategory') . '</td>';
echo '<td>Click To View</td>';
echo "</tr>";
}
Probably you have to put in your code something like that :
<td width="20%" valign="top">
<a href="product.php?id=<?php echo $id; ?>">
<img style="border:#666 2px solid;" src="inventory_images/<?php echo $id; ?>.jpg" width="150" height="102" border="1" />
</a>
</td>
Check the generated source and adjust the code above. Please keep in mind that in HTML you cannot put php variables directly. You have to output them with php echo statement like that :
<html>
SOME HTML
<div class="valueFromPhp"><?php echo $value; ?></div>
</html>
Also remebmer to escape output using htmlentities() to prevent XSS attacks.
echo '
<td>
<img width=100 src="../PHP/saved_images/'.mysql_result($result, $i, "bkimg").'">
</td>
';

Categories