This is what my url is: north.php?slot=0
What I need to do is change the value of slot when I click on a div which I have it functioning as an arrow. In the div I am using:
onclick="location.assign('north.php?slot=1')".
The div is like this:
<a onclick="location.assign('north.php?slot=1')"><div class="arrow"></div></a>.
I am receiving the the value from url as:
<?php
$slot=$_GET['slot'];
?>
which is in head tag. Now I want to use this value to access content from my database and display it
I am doing it on xampp server. I have a column named id in my table.
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "tourism portal";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
$sql="SELECT * FROM north where id=$slot";
$result = $conn->query($sql);
while($row = $result->fetch_assoc())
{
echo $row['name'].'<br>'.'<br>'.$row['description'];
}
?>
Related
I have the following MySQL table and I would like to do that RVR11 (500) be equal with a php var $RVR11
I have this code but it doesnt work.
$servername = "localhost";
$username = "root";
$password = "";
$conn = new mysqli($servername, $username, $password);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$price = mysql_query("SELECT RVR11 FROM tablename");
$result = mysql_fetch_array($RVR11);
echo $result['RVR11'];
Sorry about this beginner question.
You should choose a database before any queries, you can pass the fourth arguments to new mysqli constructor.
After I add a column to my database, I want to retrieve it but not expected.
In PHP, I try reopening apache and mysql still not work.
Does anyone know how to resolve it? Thanks!
your question is not fully explanatory but with what I could try to understand you want to retrieve data or records from your database
you could try the code below and tweak it to work your way
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM databaseName";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data
while($row = $result->fetch_assoc()) {
print $row"<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
This question already has answers here:
Can I mix MySQL APIs in PHP?
(4 answers)
Closed 6 years ago.
i want to fetch a mysql table named "my_table" column named "Email" contents as an array by php , so this is my code :
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "my_table";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$result = mysql_query("SELECT * FROM my_table");
if ($result === FALSE) {
die(mysql_error()); // TODO: better error handling
}
$data = array();
while ($row = mysql_fetch_array($result)) {
$data[] = $row['Email'];
}
echo join($data, ',');
?>
but this code returns me this error :
No database selected
but i've selected my table and database ...
and i know this code have some problems as mixing mysql and mysqli content but i dont know how to fix it i just want that array echo , if this code need to be fixed just guid me ,
how to solve this problem ? thanks in advance
Thanks to #Martin
my problem has solved i just changed the code by this way :
<?php
$servername = "localhost"; $username = "root"; $password = ""; $dbname = "my_db";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname); // Check connection
if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error);}
$result = mysqli_query($conn, "SELECT * FROM my_table");
if($result === FALSE) {
die(mysql_error()); // TODO: better error handling
}
$data = array();
while ($row = mysqli_fetch_array($result))
{
$data[] = $row['Email'];
}
echo join($data, ',')
?>
You are conencting to a database here called "my_table":
$dbname = "my_table";
And then, in your SQL statement, you try connecting to a table called the same:
$result = mysql_query("SELECT * FROM my_table");
Are you sure this is the correct name for your database?
On PHPMyAdmin you can click "Databases" to view the Database names and then, when clicking on the db, it will give you a list of tables:
Image file of getting database views from tables in PHPMyAdmin
I am currently working with mySQL and php to create a web application.
In my main index.php file, I have
<?php
require_once('includes/config.php');
require_once('includes/functionName.php');
?>
My config.php is as below:
<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "DB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected Successfully!";
?>
When I call the actual function functionName("test");
it goes into the actual functionName.php and goes to
$sql = "UPDATE Table SET id = " . $test1 . " WHERE name = \"". $name . "\"";
echo $sql;
var_dump ($conn);
This returns UPDATE Table SET id = 09 WHERE name = "test" which is correct as an SQL query.
However, my $conn returns NULL, and as a result I get FATAL ERROR query on NULL.
Please tell me why my $conn is returning NULL, and failing my query?
Thank you it was solved after adding line global $conn
I have created a table of people within my database using the following code:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT clientname, clientsurname, address1, postcode, dob FROM clients";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table class='table table-bordered'><tr><th>Name</th> <th>Surname</th><th>Address</th><th>Postcode</th><th>Date of Birth</th><th>Select Client</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["clientname"]."</td><td>".$row["clientsurname"]."</td><td>".$row["address1"]."</td><td>".$row["postcode"]."</td><td>".$row["dob"]. "</td><td class='btn btn-block btn-info btn-flat'><a href=\"edit_form.php?id=$row[clientname]\" style='color:#fff;'>Select</a></td></tr>";
}
echo "</table>";
} else {
echo "There are 0 clients in the system matching your search criteria";
}
$conn->close();
?>
I want to know if it is possible that when a user clicks the Select Client button if that clients full data can populate a div to the side of the table?
If this is possible how would I do this?
Try using the .fadeToggle or .fadeTo in jquery to make it appear on the side of the screen. This can be used many different ways but for the most part this is what it looks like.
$(document).ready(function(){
$('button').click(function(){
$('h2').fadeTo('fast',1);
});
});
example: http://jsfiddle.net/JoshuaHurlburt/x5f3bz37/