I have one number in a mysql database
This is my code:
$servername = "xxxxx";
$username = "xxxxxx";
$password = "xxxxxx";
$dbname = "xxxxxx";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql1 = "SELECT date FROM test";
$result1 = $conn->query($sql1);
$res1 = mysqli_fetch_assoc($result1);
echo $res1['date'];
I want to load that number into variable and count with that variable. After that i will store in same the db and table on the same place
$numvar = $res1['date'];
There yah go.
Related
<?php
$uname = $_POST["username"]$uname =
stripslashes(trim($uname));
$pward = $_POST["password"];
$pward = stripcslashes(trim($pward));
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "index_data";
$conn = new mysqli($servername, $username,
$password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM 00_user_details WHERE
username = '$uname' ";
$result = mysqli_query($conn, $sql);
$rows = mysqli_fetch_row($result);
echo "_".$rows["first_name"]."_";
?>
I am a bigger.
It's my code but it outputs nothing .
Any if you respected sir/ma'm help me kindly...
Please put semicolon after $_POST["username"] and use mysqli_fetch_assoc in place of mysqli_fetch_row.
mysqli_fetch_assoc return a row as an associative array where the column names will be the keys storing corresponding value.
Please find actual code as below:
$uname = $_POST["username"];
$uname = stripslashes(trim($uname));
$pward = $_POST["password"];
$pward = stripcslashes(trim($pward));
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "index_data";
$conn = new mysqli($servername, $username,$password, $dbname);
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM 00_user_details WHERE username = '$uname'";
$result = mysqli_query($conn, $sql);
$rows = mysqli_fetch_assoc($result);
echo "_".$rows["first_name"]."_";
I want to fetch time column from mysql database and to compare with current time.
It should execute only if it matches with the current time.
Please tell me a MySql query or php code to do this.
I am new to php.
Try This:
<?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);
}
$today = date("h:i a")
$sql = "SELECT * FROM Table_name WHERE SUBSTRING_INDEX(time, ' ', 2) = '".$today."'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// execute you code
} else {
}
$conn->close();
?>
Try this: Updated Code
<?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);
}
$today = date("h:i a")
$sql = "SELECT * FROM Table_name WHERE time = $today";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// execute you code
} else {
}
$conn->close();
?>
I have a such select:
$sql = "SELECT milestone_id, project_id, sum(estimated_hours) as value_sum
FROM project_has_tasks GROUP BY milestone_id";
Getting a multiple results.
Is this possible to create a query to INSERT these results to multiple rows in DB?
Thanks to myself :) Is so simple as ....
<?php
$servername = "localhost";
$username = "db";
$password = "password";
$dbname = "db";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO `burndown_snap` (`project_id`,`milestone_id`,`estimated_sum`)
SELECT `project_id`, `milestone_id`, sum(estimated_hours) as value_sum FROM project_has_tasks WHERE status !='done' GROUP BY milestone_id";
$result = $conn->query($sql);
$conn->close();
?>
I've been a few days working on my project, but just stay stuck a specific part.
My problem is that i like to get a value from the database (mysqli)
But i always receive a 0. So, no value.
This is my code:
$servername = "localhost";
$username = "user";
$password = "pass";
$dbname = "dbname";
$serialkey = $_GET['hardwareSerial'];
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$user_idSQL = "SELECT user_id FROM ss_devices WHERE serialkey = '$serialkey'";
$user_idResult = $conn->query($user_idSQL);
$user_id = $user_idResult;
The script should see what the userid, it is in equality with the specified serial number.
But when i take a serial number like: FJRI433. I always get a 0. But in the database has this serial number user_id: 3.
I hope someone can help me out whith this problem.
Thanks.
You are executing the query but not fetching any results.
The manual has plenty of examples of using mysqli :
if ($result = $conn->query($query)) {
while ($row = $result->fetch_assoc()) {
//Do stuff with the next row.
}
}
Try this perhaps...
$servername = "localhost";
$username = "user";
$password = "pass";
$dbname = "dbname";
$serialkey = $_GET['hardwareSerial'];
$conn=mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if ( mysqli_connect_errno() ) {
die("Connection failed: " . mysqli_connect_error() );
}
$user_idSQL = "SELECT `user_id` FROM `ss_devices` WHERE `serialkey` = '$serialkey'";
if( $user_idResult = mysqli_query( $conn, $user_idSQL ) ) {
while ($row = mysqli_fetch_assoc($user_idResult)) {
echo $row['user_id'].'<br />';
}
}
mysqli_close( $conn );
Hi guys im trying to check if a value(token) inside my MYSQL DB exists.
Main informations:
Table: Tokens
Column: Token
My latest try:
<?php
// DATABASE STUFF
$servername = "localhost";
$username = "userhere";
$password = "passhere";
$dbname = "zwinky";
$token = $_GET['a'];
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$result = mysql_query("SELECT * FROM Tokens WHERE Token = '$token'");
$matchFound = mysql_num_rows($result) > 0 ? 'yes' : 'no';
echo $matchFound;
?>
Does anyone have a idea?
If you are using mysqli_* then you can't use mysql_*
Try this one
<?php
// DATABASE STUFF
$servername = "localhost";
$username = "userhere";
$password = "passhere";
$dbname = "zwinky";
$token = $_GET['a'];
$con=mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Perform queries
$result = mysqli_query($con,"SELECT * FROM Tokens WHERE Token = '$token'");
$matchFound = mysqli_num_rows($result) > 0 ? 'yes' : 'no';
echo $matchFound;
?>