PHP doesn't read from MySQL database with POST or GET queries.(blank output)


I am trying to make a basic login system with PHP and MySQL, and it
is not working from my login form. Here is the code for the login
form.:



<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>

<body>
<form method="POST" action="verify.php">
<br/>Username:<input type="text" name="username"/>
<br/>Password:<input type="password" name="password"/>
<br/><button type="submit">Submit</button>
</form>
</body>

</html>


Here is the code for verify.php:



<?php
$username = $_POST["username"];
$password = $_POST["password"]; //Not Doing anything with the
pass yet
$con=mysqli_connect("","root","mypassword","logins");
//now mySQL is connected, lets extract stuff from the database
$que = mysqli_query($con,"SELECT Pass FROM login WHERE User='"
. $username . "'");
$row = mysqli_fetch_array($que);
$myvar = $row[0];
//should echo Test
echo $myvar;
echo "If it returned Test, the mySQL works.";
mysqli_close($con);
?>


When I run this, the output is completly blank.
However, I can get the query directly from the MySQL console:



    mysql> SELECT Pass from login WHERE User='Logern';
+------+
| Pass |
+------+
| Test |
+------+
1 row in set (0.01 sec)
mysql>


I can also acsess it from PHP, with a hardcoded SQL Query:



$que = mysqli_query($con,"SELECT Pass FROM login WHERE
User='Logern'");


So why is this failing to work? My webserver is a Raspberry Pi with
Debian and lighttpd.

First and foremost, I do not, and do not plan on using the mySQL db,
due to the fact that it just doesn't work out. Second.
Ubuntu
Server Edition 9.04
PHP-5
Anope 1.8.0
UnrealIRCD
3.2.x
I run an irc network at irc.I-Have-No.info (
http://i-have-no.info ) and I am trying to build a PHP script that
will read the NickServ and Chanserv databases for our website, I want
to have a page that lists all the channels that are available on my
network, and second of all, I want to read the nickserv DB so that
users can log in to the website and post to the forums (that I will be
designing later on) without having to register for anything more than
nicks
Ubuntu

I am trying to do two things here, the first is working correctly
(it is copying data from one form to another). The second part however
is not... This part should add the value 1 to the column "scores" but
only to the latest result (which is defined by sorting "date_played"),
at the moment all i am doing is adding a new result to the table..



many thanks.



<?php
header("Cache-Control: no-cache");
date_default_timezone_set('Europe/London');

// open DB connection
require_once("DbConnect.php");

// fetch now playing song and copy ratings table
$result = $db->query(
"INSERT INTO rating(`artist`, `title`, `label`, `albumyear`,
`date_played`, `duration`, `picture`,
`filename`,
`songid`)" .
"SELECT `artist`, `title`, `label`, `albumyear`, `date_played`,
`duration`, `picture`, `filename`, `songid` " .
"FROM historylist
ORDER BY `date_played` DESC
LIMIT 1 ");


// add a value to the most recent "date_played" result
$score = $db->query(
"INSERT INTO rating (`score`)".
"VALUES ('1')". "ORDER BY `date_played` DESC LIMIT 1 ");

?>
Web Development

I am facing Fatal error: Call to a member function bind_param()
on a non-object in
when i am updating epin table. This query is
executing perfectly in phpmyadmin but through php i am facing problem.
Its took my 3 days, no chance to get right answer, kindly help me to
get out from this problem.



public function createUser($email, $password
,$mobileNo,$referenceId,$position,$epin,$view)
{

require_once '../../../Api/includes/passHash.php';
$response = array();

// First check if user already existed in db
if (!$this->isUserExists($email))
{
// Generating password hash
$password_hash = PassHash::hash($password);

// Generating API key
$api_key = $this->generateApiKey();

// insert query
if($view=="User")
{
$stmt = $this->conn->prepare("INSERT INTO
users(email, password_hash, api_key,created_at,status ) values(?, ?,
?, ?, 1)");
$stmt->bind_param("ssss", $email, $password_hash,
$api_key,date("Y-m-d"));
}
else
{
$stmt = $this->conn->prepare("INSERT INTO
users(email, password_hash, api_key,created_at,status,view ) values(?,
?, ?, ?, 1,?)");
$stmt->bind_param("ssss", $email, $password_hash,
$api_key,date("Y-m-d"),$view);
}
$result = $stmt->execute();

$stmt->close();

// Check for successful insertion
if ($result)
{
$result2=$this->conn->query("SELECT max(Id) FROM
users");
$row=$result2->fetch_row();
$UId=$row[0];
$result1=$this->conn->prepare("INSERT INTO
user_personal_info (userid,mobileno,createddate) values(?,?,?)");

$result1->bind_param('iss',$UId,$mobileNo,date("Y-m-d"));
$result1->execute();
$result1->close();
if($result1 && $view=="User")
{
$result4=$this->conn->query("SELECT userId FROM
bintree where nodeid='".$referenceId."'");
$row2=$result4->fetch_row();
$SId=$row2[0];
$result4->close();
//echo $SId;
$addTree="CALL `addTreeNode1`('".$referenceId."','".
$position."', '".$UId."','". $SId."')";
$result3 = $this->conn->query($addTree);
$row1=$result3->fetch_row();
$result3->close();
//echo $row1[0];
if ($row1[0] == 0)
{
//echo mysql_errno().': '.mysql_error();

return USER_CREATE_FAILED;

}
else
{
echo $UId." " .date("Y-m-d")." " .date("Y-m-d")."
" .$epin;
$updateEpin="UPDATE `e_pin` SET
`usedid`=?,`modifieddate`=now(),`useddate`=now() ,`status`=1 WHERE
`pin`=?";
$result5=$this->conn->prepare($updateEpin);
$result5->bind_param("is",$UId,$epin);

$result5->execute();
$result5->close();
}
}
// User successfully inserted
return USER_CREATED_SUCCESSFULLY;
}
else
{
// Failed to create user
return USER_CREATE_FAILED;
}
} else
{
// User with same email already existed in the db
return USER_ALREADY_EXISTED;
}

return $response;
}


Query detail is bellow:



echo $UId." " .date("Y-m-d")." " .date("Y-m-d")." " .$epin;

$updateEpin="UPDATE `e_pin` SET
`usedid`=?,`modifieddate`=now(),`useddate`=now() ,`status`=1 WHERE
`pin`=?";

$result5=$this->conn->prepare($updateEpin);

$result5->bind_param("is",$UId,$epin);

$result5->execute();
$result5->close();


Even i am not able to pass insert query at this line for any table
present at Database.

Web Development

I am trying to make a basic login system with PHP and MySQL, and it
is not working from my login form. Here is the code for the login
form.:



<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>

<body>
<form method="POST" action="verify.php">
<br/>Username:<input type="text" name="username"/>
<br/>Password:<input type="password" name="password"/>
<br/><button type="submit">Submit</button>
</form>
</body>

</html>


Here is the code for verify.php:



<?php
$username = $_POST["username"];
$password = $_POST["password"]; //Not Doing anything with the
pass yet
$con=mysqli_connect("","root","mypassword","logins");
//now mySQL is connected, lets extract stuff from the database
$que = mysqli_query($con,"SELECT Pass FROM login WHERE User='"
. $username . "'");
$row = mysqli_fetch_array($que);
$myvar = $row[0];
//should echo Test
echo $myvar;
echo "If it returned Test, the mySQL works.";
mysqli_close($con);
?>


When I run this, the output is completly blank.
However, I can get the query directly from the MySQL console:



    mysql> SELECT Pass from login WHERE User='Logern';
+------+
| Pass |
+------+
| Test |
+------+
1 row in set (0.01 sec)
mysql>


I can also acsess it from PHP, with a hardcoded SQL Query:



$que = mysqli_query($con,"SELECT Pass FROM login WHERE
User='Logern'");


So why is this failing to work? My webserver is a Raspberry Pi with
Debian and lighttpd.

Web Development

HERE is my sql file



-- phpMyAdmin SQL Dump
-- version 3.4.7.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jan 23, 2012 at 09:26 AM
-- Server version: 5.1.56
-- PHP Version: 5.2.9

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `danielle_youtube`
--

-- --------------------------------------------------------

--
-- Table structure for table `items`
--

CREATE TABLE IF NOT EXISTS `items` (
`id` int(11) NOT NULL,
`name` varchar(65) COLLATE utf8_unicode_ci NOT NULL,
`cost` float NOT NULL,
`seller_id` int(11) NOT NULL,
`bids` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Dumping data for table `items`
--

INSERT INTO `items` (`id`, `name`, `cost`, `seller_id`, `bids`) VALUES
(1, 'Brand New iMac Computer', 149.99, 32, 3),
(2, 'used diaper from my sister', 2.04, 1, 0),
(3, 'Fresh apple pie', 14.99, 54, 32),
(4, 'New gym socks', 2.34, 90, 566),
(5, 'Weedwacker only slightly used', 4.56, 84, 2),
(6, 'New ipad stolen from best buy', 399, 32, 23),
(7, 'Book about having babies', 21.34, 44, 21),
(8, 'Woman Jeans', 49.5, 56, 123),
(9, 'traditional carpet', 25.45, 14, 75),
(10, '3 boxes of frogs', 30.49, 68, 145),
(11, '48 boxes of frogs', 74.29, 6, 99),
(12, '7 boxes of frogs', 857.75, 18, 88),
(13, 'laptop', 743.3, 89, 158),
(14, 'thumbelina', 228.05, 15, 49),
(15, 'bed', 127.15, 65, 189),
(16, 'shampoing', 12.8, 6, 105),
(17, 'stove', 37.66, 68, 111),
(18, 'cushion', 7.15, 97, 157),
(19, 'refrigerator', 657.49, 61, 129),
(20, 'gold necklace', 853.07, 10, 101),
(21, 'pan', 33.7, 7, 184),
(22, 'awesome alien computer game', 10.75, 18, 29),
(23, 'baby coat', 89.99, 14, 47),
(24, 'baby seat', 145.78, 2, 199),
(25, 'satchel', 44.71, 15, 66),
(26, 'women perfum', 110.9, 48, 84),
(27, 'conveyor belt', 1120.75, 11, 4),
(28, 'used car', 5700.5, 12, 135),
(29, 'supercomputer', 49.75, 50, 176),
(30, 'mirror', 26.8, 19, 56),
(31, 'piano', 1800.4, 13, 147),
(32, 'quitar', 88.4, 25, 164),
(33, 'trumpet', 255.15, 36, 23),
(34, 'machintosh', 3845, 20, 107),
(35, 'earphone', 10.5, 17, 110),
(36, 'computer', 418, 11, 152),
(37, 'night light', 13.87, 97, 198),
(38, 'pc bag', 50.99, 48, 65),
(39, 'babyfoot', 376.7, 2, 121),
(40, 'hairdryer', 88.9, 12, 177),
(41, 'babyliss', 130.75, 68, 79),
(42, 'door', 150.5, 98, 13),
(43, 'baby soap', 12.7, 4, 198),
(44, 'used phone', 43.75, 9, 69),
(45, 'bath', 757.15, 96, 55),
(46, 'flower', 10.75, 16, 89),
(47, 'battery charger', 48.75, 25, 87),
(48, 'air conditioner', 975, 12, 151),
(49, 'casserole', 115.75, 46, 35),
(50, 'used toilet', 180.7, 64, 11),
(51, 'teashirt', 14.98, 65, 114),
(52, 'moto', 920, 22, 174),
(53, 'saxophone', 220.9, 60, 140),
(54, 'bicycle', 180.55, 97, 35),
(55, 'man perfum', 95, 75, 199),
(56, 'table', 157.25, 91, 48),
(57, 'boat', 4890.5, 17, 177),
(58, 'iphone', 547, 8, 28),
(59, 'body milk', 50.5, 16, 90),
(60, 'new curtain for bedroom', 278.4, 92, 11),
(61, 'diamond ring', 1900, 15, 45),
(62, 'swept', 4.5, 9, 99),
(63, 'women hat', 17.55, 39, 60),
(64, 'washing machine', 680.9, 42, 125),
(65, 'baby bottle', 27.98, 91, 117),
(66, 'women sun glasses', 66.7, 18, 174),
(67, 'person weighs', 65.25, 10, 100),
(68, 'photo frame', 18, 85, 170),
(69, 'key board', 16.7, 90, 101),
(70, 'screen', 250, 81, 188),
(71, 'bucket', 2.5, 1, 19),
(72, 'lipstick', 24.75, 3, 44),
(73, 'wardrobe', 120.75, 9, 71),
(74, 'blue dress size 40', 88.9, 7, 113),
(75, 'newspaper', 1.5, 95, 172),
(76, 'scanner', 350, 14, 62),
(77, 'camera', 550.7, 17, 95),
(78, 'camcorder', 788.99, 25, 127),
(79, 'gun', 420.1, 81, 107),
(80, 'domestic dog', 200, 19, 129),
(81, 'horse', 759.5, 30, 115),
(82, 'truck', 7800.5, 32, 123),
(83, 'soccer ball', 95.49, 54, 155),
(84, 'gold earring', 385, 75, 92),
(85, 'basket', 250.45, 46, 142),
(86, 'bikini', 85.2, 12, 57),
(87, 'red skirt', 15.9, 18, 188),
(88, 'copier machine', 800.7, 50, 160),
(89, 'handbag', 35.9, 8, 108),
(90, 'bath towel', 25.1, 11, 186),
(91, 'coffee machine', 210.89, 15, 170),
(92, 'wedding dress', 690, 26, 48),
(93, 'man sun glasses', 80.7, 19, 174),
(94, 'candle', 7.5, 22, 102),
(95, 'scarf', 11.9, 7, 143),
(96, 'microwave', 150.29, 6, 11),
(97, 'electric oven', 645, 62, 171),
(98, 'play station', 256.75, 12, 188),
(99, 'dvd', 126.84, 14, 113),
(100, 'magazine', 3.5, 8, 152);

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;`


Now when i run this query



SELECT name , MIN(cost) FROM items WHERE name LIKE '% boxes
of frogs' AND seller_id IN (
SELECT seller_id FROM items WHERE name LIKE '% boxes of frogs'
)


I get



name
MIN(cost)
3 boxes of frogs
30.489999771118164



But when i use



SELECT name , MIN(cost) FROM items WHERE seller_id IN(
SELECT seller_id FROM items WHERE name LIKE '% boxes of frogs'
)


i get this result



name
MIN(cost)
3 boxes of frogs
10.75



I want to know why the results are different?

Web Development

I'm working on a project using php Mysql and jQuery and I want
after a click event on a button to insert many rows into the database
(values of inputs inside a table containing many rows).



I thought of - because Im using AJAX in this case - keeping the
values of input fields in a session variable called
$_SESSION['unit'][], which is an array, for each row it
take the value of the input field iterating the table rows. What I
want to do is when I click on the button to insert each
$_SESSION['unit'][$i] in individual row, kind of for each
$_SESSION['unit'][$i], do an insert into the database
with AJAX!



Thanks in advance!

Web Development

- Technology - Languages
+ Webmasters
+ Development
+ Development Tools
+ Internet
+ Mobile Programming
+ Linux
+ Unix
+ Apple
+ Ubuntu
+ Mobile & Tablets
+ Databases
+ Android
+ Network & Servers
+ Operating Systems
+ Coding
+ Design Software
+ Web Development
+ Game Development
+ Access
+ Excel
+ Web Design
+ Web Hosting
+ Web Site Reviews
+ Domain Name
+ Information Security
+ Software
+ Computers
+ Electronics
+ Hardware
+ Windows
+ PHP
+ ASP/ASP.Net
+ C/C++/C#
+ VB/VB.Net
+ JAVA
+ Javascript
+ Programming
Privacy Policy - Copyrights Notice - Feedback - Report Violation 2018 © BigHow