Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have an HTML table populated from a mysql database table via PHP with 8 different values.
I need to open a second page and pass to it any one from the values I click on in order to query another from the database.
So far I can open the second page via href but I could solve the parameter issue.
Can anyone help me on this?
The code:
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
include "ligabd.php";//connects to the server
if(!$l)
{
die("Ligação sem sucesso: ".mysql_error());
}
else
{
$query="SELECT escalao FROM escaloes ORDER BY idescaloes ASC";
$result= mysqli_query($l, $query);
?>
<link href="style.css" rel="stylesheet" type="text/css" />
<table id="t01" align="center">
<br>
<br>
<br>
<br>
<tr>
<td align="center">Escalões</td>
</tr>
<?php
while ($record= mysqli_fetch_array($result))
{
$r=$record['escalao'];
?>
<tr>
<td>
<a href="pag_escalao_mensalidade.php?escalao=">
<?php
echo $record['escalao'];
?>
</a>
</td>
</tr>
<?php
}
}
?>
</table>
</body>
You should use id in your table and use this:
$query="SELECT id, escalao FROM escaloes ORDER BY idescaloes ASC";
...
while ($record=mysqli_fetch_assoc($result)) // Fetch assoc!
...
<?= $record['escalao'] ?>
....
On the second page, you fetch the record again
$query='SELECT * FROM escaloes WHERE id=' . intval( $_GET['id'] );
This is wrong:
<a href="pag_escalao_mensalidade.php?escalao=">
<?php
echo $record['escalao'];
?>
It should be
<a href="pag_escalao_mensalidade.php?escalao=<?php
^^---
echo $record['escalao'];
?>"><?php echo $record['escalao'] ?>
^^^^^^^---
Note the indicated changes
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
So I am trying to sort information based the selected item in the combo box. I am familiar with parts of PHP but still learning.
I was able to fill the combo box with the 'Brand_Name' Column information from my DB.
This is my current output:
It is not filtering though, it is just listing all items in the DB
See code below:
<?php
$hostname = "localhost";
$username = "root";
$password = "root";
$databaseName = "Clients";
$connect = mysqli_connect($hostname, $username, $password, $databaseName);
$queryDropdown = "SELECT * FROM `Brands` WHERE 1";
$result = mysqli_query($connect, $queryDropdown);
$queryGrid = "SELECT * FROM `Brands` ";
$SearchResult = mysqli_query($connect, $queryGrid);
?>
<html>
<head>
<title>PokerPass</title>
<link rel="stylesheet" type="text/css" href="styles/Main.css">
<link rel="stylesheet" type="text/css" href="styles/ComboBox.css">
<link rel="stylesheet" type="text/css" href="styles/TableGrid.css">
</head>
<body >
<div id="Container" class="Container">
<div id="Header" class="Header">
</div>
<div id="Body" class="Body">
<div name="start" id="Filter_Bar" class="Filter_Bar">
<select class="soflow" id="soflow" Size="1">
<?php while($row1 = mysqli_fetch_array($result)):; ?>
<option><?php echo $row1[1]; ?></option>
<?php endwhile; ?>
</select>
<button class="Submit" ><span><strong>Search<strong></span></button>
<!--<input class="Submit" type="submit" name="search" value="Search </span>">-->
</div>
<div id="Data_Grid" class="Data_Grid">
<table>
<tr>
<th>Server ID</th>
<th>Client</th>
<th>Operator</th>
<th>Username</th>
<th>Password</th>
</tr>
<?php while ($row = mysqli_fetch_array($SearchResult)):; ?>
<tr>
<td><?php echo $row['ServerID']; ?></td>
<td><?php echo $row['Brand_Name']; ?></td>
<td><?php echo $row['Operator_Name']; ?></td>
<td><?php echo $row['Username']; ?></td>
<td><?php echo $row['Password']; ?></td>
</tr>
<?php endwhile; ?>
</table>
</div>
</div>
<div id="Footer" class="Footer">
</div>
</div>
</body>
</html>
In your HTML code, your select element has no name attribute, so you won't be able to pick up its value when the form is submitted. Additionally, your option elements have no value attribute so even if the form was submitted and the select had a name, the value would be empty. See this guide.
Your select element isn't inside a form tag, which means that the page has no idea where to go when the button is pressed. You need a form that specifies the action (the URL you are going to) and the method (post/get). See this guide.
Finally, if you want PHP to know what your query was, you need to get it from the GET or POST parameters. Once you have the variable, you can make your SQL query dynamic - but be careful not to introduce an SQL injection vulnerability - validate the user input carefully (for instance, only allowing numbers as values in your select list) and/or use parameterized queries.
If you want the form to be submitted automatically when the dropdown list is changed, you can use a quick JS attribute to auto-submit the form.
You need to apply the filter value to your query, for your example
you need to construct a new query depending on your selection.
"SELECT * FROM Brands WHERE Client=" + $selectedClient;
Edit:
Here's a reference on how to pass a js variable to php:
How to pass JavaScript variables to PHP?
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
im working on an Discussion board in php and mysql, but my question is; How can i make it that more than 1 person can react on a discussion, like at the moment i have that only one can react because it goes into a field in the database named; reactions
But i want ofcourse to have more people answer it instead of one...
If anyone could tell me how to achieve this, that would be a mayor help!
The code i tried so far:
<?php
include('inc/conn.inc.php');
?>
<?php
if(isset($_POST['post'])){
$reactions= $_POST['msg'];
$sql = "INSERT INTO topics (reactions) VALUES reactions = :reactions";
$sql->bindParam(':reactions', $reactions);
$results = $conn->exec($sql);
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/styles.css">
<link rel="stylesheet" type="text/css" href="css/reset.css">
<title>Discussion Board</title>
</head>
<body>
<header>
<h1>Logo comes in here</h1>
</header>
<div id="t1">
<h1>Featured</h1>
</div>
<div id="t2">
<h1>Status</h1>
</div>
<div id="topic-items">
<?php
$id = htmlspecialchars($_GET["id"]);
/*
$sql = "SELECT creator FROM topics WHERE id = :id";
$sql->bindParam(':id', $id);
$results = $conn->query($sql);
*/
$statement = $conn->prepare("SELECT message FROM topics where id = :id");
$statement->execute(array(':id' => $id));
$row = $statement->fetch();
echo "Message: ".$row['message'];
?>
<h2>Featured items come here {discussions} deployed by php </h2>
</div>
<div id="board-status">
<h2>Board statuses come here {status} deployed by php </h2>
</div>
<div id="react-board">
<form>
Message:<br>
<textarea name="msg"></textarea><br>
<input type="submit" name="post" value="Post">
</form>
</div>
<footer>
<h1>Footer Content</h1>
</footer>
</body>
</html>
Isnt it going to replace the field everytime someone presses on the POST button?
You need to first separate your tables in this manner:
Once you do that you can start creating queries using JOINs to obtain your data. Do this, then tell us if you have further difficulties.
Hope this helps.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
my php code works fine on local server but does not execute on web server
some of the codes are working.
the code is given down and please tell me problem with the code.
<?php
include("/connect.php");
session_start();
$_SESSION['title']="Portfolio | Mactros Inc.";
include("header.php");
?>
<div>
<center>
<font size=7 class="top">
Portfolio<br />
</font>
<font style="color: #aeafb1;">Home -> Portfolio</font>
</center>
</div>
<div style="height: 650px; margin-top: 10px;">
<?php
$sql = "select * from project";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()){
?>
<div class="portfolio">
<center>
<img src="<?php echo $row["pic"]; ?>" class="port">
<font size=5><?php echo $row["name"];?></font><br>
<font><?php echo $row["type"];?></font>
</center>
</div>
<?php }?>
</div><?php include("footer.php");?>
in this code gets executed other gets ignored
<?php
include("/connect.php");
session_start();
$_SESSION['title']="Portfolio | Mactros Inc.";
include("header.php");
?> <div>
<center>
<font size=7 class="top">
Portfolio<br />
</font>
<font style="color: #aeafb1;">Home -> Portfolio</font>
include("/connect.php");
This is an absolute path, I don't think your script is at the root of your filesystem, use a relative path instead, and don't disable errors.
Write this line of code at top of you script file to show errors which are occurring into script.
ini_set('display_errors', 1);
error_reporting(E_ALL);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have following data in mysql, and I want to echo in this format:
Data:
Name,Image URL,Link
I want to print it dynamically like this : http://screensaver.cf/screensavers.php
I don't know user's screen width, still I want it to appear as much as possible in width.
How can I do this in html and PHP?
My code:
<?php
require("config.php");
?>
<div id="main-wrap">
<div class="container">
<div id="main">
<div id="content"><div id='wsite-content' class='wsite-elements wsite-not-footer'>
<div class="paragraph" style="text-align:left;">
<?php
$sql='SELECT * FROM `games` where 1=1';
$data = mysql_query($sql);
echo '<h4 class="result">Result:</h4>';
while($row = mysql_fetch_row($data)){
$table=WHAT TO DO HERE TO MAKE IT LOOK LIKE THAT???????
echo $table;
echo '<br><br>';
}
?>
</div>
</div>
</div>
</div>
</div>
<?php
include("footer.php");
?>
P.S I know mysql is depreciated and I am constantly working to learn Mysqli, as I am in 8th class, I don't have much time.
<style>.a{float:left;}
</style>
>
in while loop use this
<div class = "a">
<?php <img src='".$row['url']."' width='140' height='140'> ?>
</div>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need the data to have a different style if the sold = 0 in the mysql table
and when i use the code below the website shows a blank white page
(?=$vehicle-> this is the vehicle reference
and sold is the column withing the sql table
<?php
if (?=$vehicle->sold?!= 1)
{
<div class="foo">
<div class="fboverlay"></div>
<a>
<img src="/media.php?productId=<?=$vehicle->vehicle_id?>&file=<?=$vehicle->main_image?>" />
</a>
</div>
}
else {
<img src="/media.php?productId=<?=$vehicle->vehicle_id?>&file=<?=$vehicle->main_image?>" />
}
?>
You need to learn the PHP from the basics. Learn about operators, PHP and HTML secion, etc..
Anyway, i fixed your code. The condition is if $vehicle->sold is not equal to 1. But i think, (in your OP you mentioned it should be 0) you want this: $vehicle->sold == 0
//Use sytnax like this. See php opeartors.
if ($vehicle->sold != 1) {
?> <!-- Close the php -->
<div class = "foo">
<div class = "fboverlay"></div>
<img src = "/media.php?productId=<?= $vehicle->vehicle_id ?>&file=<?= $vehicle->main_image ?>" />
</div>
<?php
//Open the php again
} else {
?> <!-- close the php -->
<img src = "/media.php?productId=<?= $vehicle->vehicle_id ?>&file=<?= $vehicle->main_image ?>" />
<?php //Open again
}