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
I have database named as 'ecc' with table named as 'client'
table client has many fields, consider one of them named as ProjectManager
I want to display data of ProjectManager in select drop down list.
More data can be added to ProjectManager so loop is necessary.
please can some one help by writing the code for the same...
thanks for help in advance..
Below is a sample code for mysqli:
I did not given that a try but should be working. You need to replace values for username, password for db and what value you need in your select options
<?php
// Connect db
$mysqli = new mysqli('localhost','username','password','ecc');
// check if error
if ($mysqli->connect_error) {
die('Can not connect to DB error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}
// MySqli Select Query
$results = $mysqli->query("SELECT ProjectManager FROM client");
echo '<select name="project_manager">';
echo '<option value="">-select project manager-</option>';
while($row = $results->fetch_assoc()) {
echo '<option value="'.$row['ProjectManager'].'">'.$row['ProjectManager'].'</option>';
}
echo '</select>';
// Frees memory
$results->free();
// close connection
$mysqli->close();
?>
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 4 years ago.
Improve this question
How can I insert data from a table to another table after the clicking of a button using PHP and MySQL?
Following php script can be used to fetch values from one Table and insert data into another table:
<?php
$servername = "localhost"; //if running on localhost
$username = "root"; // if running on localhost
$password = ""; // empty for mysql default password
$dbname = "database name";
$conn = mysqli_connect($servername, $username, $password,$dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
if (isset($_POST['name of button'])) { // if button is clicked the following code will be executed
$sql_db1 = "SELECT * FROM `table_name_1` WHERE condition"; // if you want to select data based on some constraint.
$sql_db1_query = mysqli_query($conn,$sql_db1); // mysqli_query takes 2 parameters -> connection to database and sql query.
while($row = mysqli_fetch_array($sql_db1_query)){
$sql_db2 = "INSERT INTO `table_name_2`(`column1`,`column2`,`column3`,`column4`) VALUES($row['column1'],$row['column2'],$row['column3'],$row['column4'])"; //'column1' inside $row[] and so on should be replace by the column names of the table in which you want to insert the data
$sql_query_db2 = mysqli_query($conn,$sql_db2);
}
}
?>
I think this takes a little more than a simple answer, try reading a php-mysql tutorial:
https://www.w3schools.com/Php/php_mysql_intro.asp
In plain Mysql you just need a "insert into" statement with a select, as explained here. Then you'll just need to create a php statement to execute this SQL.
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 want to edit the data which is already in the databse.
Suppose I have updated my database, but after an year the user who has updated that database want to edit something like his address which is changed now through the form, then how can we do that. I am posting
<?php
// Create Local variable
$taken = "false";
$database = "railway";
$password = "";
$username = "root";
// Main if statement
//if($userreg && $passreg){
// Connect to database
$con = mysqli_connect('localhost', $username, $password,$database);
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}
---------
WHAT TO WRITE IN BETWEEN
----------------
mysqli_close($con);
Suppose my table name is Railway and the attributes are time, name, station_to and station_from. I want to change the name.
Please write both the form as well as php and mysql query.
It would be something like this:
$sql = "UPDATE Railway SET name='Joe' WHERE id=5";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
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 8 years ago.
Improve this question
I am wondering how I would render a HTML page with MySQL.
I want to render a page that has different lines, for different rows in the table.
The table is:
I want the web page to render like this:
Obviously, if there are less rows I don't want as many rows to display, and same if there are more.
Purely because it's late at night here's some free code.
Please notice two things.
1. I'm using mysqli not mysql.
2. I wrote this from memory, I researched on the web how to write this. I have no degree, no professional job as a programmer but I all found this out by myself by researching and browsing SO. Please next time research and try out different things for yourself.
<?php
$host = 'localhost';
$password = '';
$user = '';
$database = '';
// Link for the connection to MySQL
$link = mysqli_connect($host,$user,$pass);
// If statement to check if the link has been succesful if not, give error. If it is succesful select database.
if(!$link)
{
if (mysqli_connect_errno())
{
echo "Connection unsuccessful<br/>";
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
}else
{
mysqli_select_db($link, $database);
}
$query = "SELECT * FROM [table]";
$result = mysqli_query($link, $query);
echo '<table>';
while($row = mysqli_fetch_assoc($result))
{
echo '<tr>';
echo '<td>'. $row['CSTEAMID'] .'</td>'
echo '<td>'. $row['OSTEAMID'] .'</td>'
echo '<td>'. $row['TIMEJOINED'] .'</td>'
echo '</tr>';
}
echo '</table>';
?>
Do you have any code already?
Pseudo code for what you want:
Write html for a standard page
In the body somewhere, use PHP (or other scripting language) to connect to your mysql db and retrieve the needed data.
Output with the PHP in an HTML tabular format
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 want to set the value of a column in my database by the link a user clicks.
<body>
Choose the position you would like your duo to primarily play:
<a href="/ADC%20Seek/ADC-Support.html">
Support
</a>
<a href="/ADC-Seek/ADC-Mid.html">
Mid Lane
</a>
<a href="/ADC-Seek/ADC-Top.html">
Top Lane
</a>
<a href="/ADC-Seek/ADC-Jungle.html">
Jungle
</a>
</body>
<?php
$seek= value set from link clicked
$query= "INSERT INTO mytable (seek) VALUES ('$seek')";
?>
There are many ways you can do this, you can pass a variable into the URL using a GET but that would require you to change your page structure.
Simply add the insert on each page:
ADC-Jungle.php
$db = new mysqli('localhost', 'user', 'pass', 'demo');
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
$sql = "INSERT INTO db (column_name) VALUES ('Jungle');
if(!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']');
}
For your purpose this is the simplest solution, but not necessarily the way I would do it.
EDIT
As Marc said, these need to be PHP files.
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
hey i just want a query which will be printing only the result of count query . put in the else part
<?php
$con = mysql_connect('localhost', 'root', '') or die(mysql_error());
$db = mysql_select_db('quiz', $con) or die(mysql_error());
$q="count(*) from question where ans=uanswer";
$rq=mysql_query($q,$con);
if(!$rq)
{
echo " the sql query faiiled to work ";
}
else
{
}
?>
You would use the function mysql_fetch_row() to return a row from your database query as an array. You can then access the result for the count(*) as the first element in the returned array.
<?php
$con = mysql_connect('localhost', 'root', '') or die(mysql_error());
$db = mysql_select_db('quiz', $con) or die(mysql_error());
$q="count(*) from question where ans=uanswer";
$rq=mysql_query($q,$con);
if(!$rq)
{
echo " the sql query faiiled to work ";
}
else
{
$row = mysql_fetch_row($rq);
echo $row[0];
}
?>