I have simple msql based glossary - which stop working after upgrade from php5.4 to php 5.6.28
In form i send a variable to address like page.php?word=xxx
in page.php it should get $word from table.word with table.definition
Connection with database is working.
Error log looks
array(1) { ["word"]=string(5) "xxx" } bool(true)
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, string given
my code is
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$configfile = "config.php";
require $configfile;
$db = mysqli_connect("$host", "$username", "$password") or die ("could not connect to mysql");
mysqli_select_db($db, "$databasename") or die ("no database");
mysqli_query($db, "SET NAMES 'utf8' COLLATE 'utf8_polish_ci'");
function mysqli_result($db,$row=0,$col=0){
$numrows = mysqli_num_rows($db);
if ($numrows && $row <= ($numrows-1) && $row >=0){
mysqli_data_seek($db,$row);
$resrow = (is_numeric($col)) ? mysqli_fetch_row($db) : mysqli_fetch_assoc($db);
if (isset($resrow[$col])){
return $resrow[$col];
}
}
return false;
}
$word = "";
var_dump($_GET);
var_dump(isset($word));
if($word)
{
$getWord=mysqli_query($db, "SELECT word,definition FROM mdglossary WHERE word LIKE '$word' ORDER BY word");
}
else {....}
if($getWordArray=mysqli_fetch_array($getWord, MYSQLI_BOTH))
{
do
{
echo "....";
}
while($getWordArray=mysqli_fetch_array($getWord));
}
else {....}
I try to find solution "hundret" times by Internet and this page, but I just can't understand what happened and why it doesn't work at all.
You have set word to equal nothing.
$word = "";
then your sql will look like this
SELECT word,definition FROM mdglossary WHERE word LIKE '' ORDER BY word
So your looking for a word column with nothing in it. Is that your intention?
Related
We are trying to complete / fix the below code, We cant seem to do the following.
Check if 'Check_Activation' is set to 'NULL' within the Database
IF value is NULL direct the user to one of the forms (1,2,3)
And finally if the 'Check_Activation' has already been activated and isn't 'NULL' prevent user from accessing one of the 3 forms.
I know its basicly there but we can't seem to figure out the final bug.
Please have a quick look at the code below and if anyone notices anything that isn't right please advice us.
Paste Bucket / Version
Website URL
<?php
$username = $_POST['username'];
$activation_code = $_POST['activation_code'];
$activation_codeurl = $activation_code;
$usernameurl = $username;
$db_host = "localhost";
$db_name = "aardvark";
$db_use = "aardvark";
$db_pass = "aardvark";
$con = mysql_connect("localhost", $db_use, $db_pass);
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db_name, $con);
$checkcustomer = mysql_query("SELECT `Check_Activation` FROM `members` WHERE `Username` = '".$username."' & `Activation` = '".$activation_code."'; ");
$array = mysql_fetch_array($checkcustomer);
if (is_null($array['Check_Activation'])) {
$username = substr($username, 0, 1);
if($username == '1') {
$redirect_url='form-one.php?membernumber='.$usernameurl.'&activation_code='.$activation_codeurl;
} elseif($username == '2') {
$redirect_url='form-two.php?membernumber='.$usernameurl.'&activation_code='.$activation_codeurl;
} elseif($username == '3') {
$redirect_url='form-three.php?membernumber='.$usernameurl.'&activation_code='.$activation_codeurl;
}
header("Location:". $redirect_url);
}
else
{
?>
Try this, You need to fetch the row from table and then you can check the values,
$val = mysql_fetch_array($checkcustomer);
if (is_null($val['Check_Activation']))
instead of
$val = mysql_query($checkcustomer);
if ($val == 'NULL')
NOTE: Use mysqli_* functions or PDO instead of using mysql_* functions(deprecated)
before I get into the technicality of what your are trying to accomplish, I have some advice for your code in general. You should avoid using the mysql api as it is deprecated, and use the mysqli api instead. I think you will also find that it is easier to use.
Now for the code:
You have this line in your code which seems to be incorrect, $checkcustomer is a result set from your previous query, so why are you running it as a query again?
$val = mysql_query($checkcustomer);
You already have the result set so do this:
$array = mysql_fetch_array($checkcustomer);
And then take the value of Check_Aviation;
if (is_null($array['Check_Aviation'])) {
//Do Something
}
Should solve your issue
I'm writing a web application and now I have a problem
This is my database_connect.php:
<?php
$host = 'xy';
$user = 'xy';
$pass = 'xy';
$db = 'xy';
$dbconnect = mysql_connect($host, $user, $pass) or die("error");
mysql_select_db($db) or die("error");
?>
I am trying to establish connection to the database and insert some data with the following code:
<?
function addChapter(){
?>
<form method="post" action="">
<br>
<input name="chapter" type="text" value="Naslov">
<br><br>
<input type="submit" name="submit" value="Potrdi">
</form>
<?php
if( isset($_POST['submit']) ){
$chapter = mysql_real_escape_string($_POST['chapter']);
if( $_GET['stran'] == 'fizika' ){
$table = 'tblphysics';
}else if( $_GET['stran'] == 'kemija' ){
$table = 'tblchemistry';
}
$chapter_id_query = mysql_fetch_assoc( mysql_query("SELECT chapter_id FROM ".$table." ORDER BY chapter_id DESC LIMIT 1") );
$chapter_id = $chapter_id_query['chapter_id'] + 1;
if( ($chapter != "") && ($chapter_id != "") ){
$sql = "INSERT INTO ".$table." (chapter, version, chapter_id) VALUES ('$chapter', '1', '$chapter_id')";
$neki = mysql_query($sql, $dbconnect) or die("<p class=\"msg warning\">Napaka pri ustvarjanju poglavja.</p>");
echo '<p class=\"msg done\">Poglavje uspešno dodano.</p>';
//mysql_close($dbconnect);
}
}
}
?>
I am getting the following error:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/a4896862/public_html/functions.php on line 81
Line 81 is
$neki = mysql_query($sql, $dbconnect) or die("<p class=\"msg warning\">Napaka pri ustvarjanju poglavja.</p>");
I know I should be using PDO or mysqli, but this will be just temporary, but it needs to work so i can continue
Anyone has any idea what is going wrong? It is causing no problem when reading from the database.
Try removing the $dbconnect argument, since the first query works as intended without it (did it ?).
$neki = mysql_query($sql) or die('...');
But, seriously, I doubt that solving issues in some outdated mess will be faster than starting database_connect.php all over. You will get much more quality answers if you use technologies that are still supported.
It seems that you don't include your database_connect.php in your second file (that contains the function). Try adding the following line before function addChapter() :
include 'database_connect.php'; // This is correct if the files are in the same directory...
Try removing the second paramater $dbconnect as it may not be in scope.
Does it work without it?
I am trying to do a query in which i can see if username and password can match. If it matches, then I will go to the administrator pages. The problem Im having is that i think that the query is not giving me the right results. The database table is called admin, and it has adminame and passadmin. The user im entering IS in the database. The password is encrypted.
<?php
$f_user = $_POST['f_user'];
$f_pass = $_POST['f_pass'];
$status = authenticate($f_user, $f_pass);
if ($status == 1)
{
include("../connections/config.php");
session_start();
//session_register("SESSION_UNAME");
$_SESSION['SESSION_UNAME'] = $f_user;
$SESSION_UNAME = $f_user;
header("Location: unoadmin.php");
exit();
}
else
{
$mensa= "Información Incorrecta...Inténtelo de Nuevo";
header("Location: register.php?mensa=$mensa");
exit();
}
function authenticate($user, $pass)
{
include("../connections/config.php");
$connection = mysql_connect($mach,$userna,$paso) or die ("Unable to connect!");
$query = "SELECT * from admin WHERE adminame = '$f_user'";
mysql_select_db($db);
$result = mysql_query($query, $connection) or die ("Error in query: $query. " . mysql_error());
$num_results = mysql_num_rows($result);
if ($num_results == 1)
{
for($i=0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
$pas = $row["passadmin"];
}
if(crypt($pass,$pas) == $pas)
{
return 1;
}
else
{
return 0;
}
}
else
{
return 0;
}
}
?>
Can someone tell me what is the error? It is leading me to "Información incorrecta. Intentelo de nuevo" or in english "Wrong information. Try again"
It is a bit of a guess, but your authenticate function returns false (error message)
I am not sure what happens in the include, it suggests inclusion of database settings.
You are using 2 different vars for the username: is:
function authenticate($user, $pass) // <-- you pass $user
{
include("../connections/config.php");
$connection = mysql_connect($mach,$userna,$paso) or die ("Unable to connect!");
$query =
"SELECT * from admin WHERE adminame = '$f_user'"; // <-- you use $f_user
Perhaps not a real answer, but it was to long for a comment.
A simple solution of this question is to put your user name and password in variables and match it with database, If result have greater than 1 value than it will go to admin page. For example
$myusername=addslashes($_POST['username']);
$mypassword=addslashes($_POST['password']);
$sql="SELECT * FROM admin WHERE username='$myusername' and password=md5('$mypassword')";
$query = mysql_query($sql);
$row = mysql_num_rows($query);
if($row>0) {
header("location:administrator.php");
}
else {
echo"Please check username and password";
}
From your code you have either:
no such entry in your DB with the username you provided
the password is wrong
Furthermore you should check your code for SQL injections!
Please take time to read article below,
Best Way to prevent SQL Injection in PHP
can some one point out the problem with this code? It supposed to fetch data from mysql but it returns blank. Here is the full code.
<ul class="list">
<?php
require("object/db.class.php");
error_reporting(0);
function entry_tickets() {
if($_SESSION['dojopress_global:root'] == false) {
$entry_ticket .= <<<ENTRY_TICKET
<li><p><img src="http://cdn1.iconfinder.com/data/icons/humano2/32x32/apps/gnome-keyring-manager.png" />Access denied</p></li>
ENTRY_TICKET;
} elseif($_SESSION['dojopress_global:root'] == true) {
$q = "SELECT * FROM `notice` ORDER BY nid LIMIT 12 DESC";
$r = mysql_query($q);
if ( mysql_num_rows($r) == 0 ) {
$entry_ticket .= <<<ENTRY_TICKET
<li><p><img src="http://cdn1.iconfinder.com/data/icons/humano2/32x32/status/dialog-information.png" /> Nothing to display</p></li>
ENTRY_TICKET;
} elseif ( $r !== false && mysql_num_rows($r) > 0 ) {
while ( $a = mysql_fetch_array($r) ) {
$nid = stripslashes($a['nid']);
$note = stripslashes($a['note']);
$type = stripslashes($a['type']);
$private = stripslashes($a['private']);
$date = stripslashes($a['date']);
$author = stripslashes($a['author']);
function note_type($type) {
if($type == 1) { $type = "posted a comment!"; } elseif($type == 2) { $type = "raised a support ticket!"; } else { }
return ($type);
}
$entry_ticket .= <<<ENTRY_TICKET
<li><p> $athor, note_type($type)</p></li>
ENTRY_TICKET;
return $entry_ticket;
}
}
}
}
echo entry_tickets();
?>
</ul>
<div style="clear:both;height:10px;"></div>
sorry forgot db.class.php
<?php
session_start();
//connect.php
$host = "localhost";
$db_user = "root";
$db_pass = "";
$db_name = "au";
$connectClass = mysql_connect("$host", "$db_user", "$db_pass") or die ("Couldn't establish connection to database server.");
$dbObject = mysql_select_db("$db_name", $connectClass) or die ("Couldn't select database.");
?>
error reporting disabled error code
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\wamp\www\ageis\note.php on line 22
Your mysql syntax looks bad. You have:
SELECT * FROM `notice` ORDER BY nid LIMIT 12 DESC
try
SELECT * FROM `notice` ORDER BY nid DESC LIMIT 12
Erik's comments should have pointed you in the right direction, however:
Figure out where PHP logs errors. Either turn up php's error reporting level so you see more errors, or start tailing your apache error_log
You should always check for errors after running mysql_query and do some sort of logging on failure. This is probably best accomplished by writing a wrapper function for mysql_query that does this, or using a 3rd party db wrapper that has already solved this problem.
You're redefining function note_type every time through your while loop. You have a return call outside the function, below it. Really I can't see how this is even syntactically correct. It looks like you have a large problem with mismatched brackets.
As for an actual database issue, you should check mysql_error() if no rows return from the call because it's likely something went wrong.
Also I recommend using PDO which is a true database class instead of the native function based ones.
I am trying to implement a live search on my site.
I am using a script somebody has already created. http://www.reynoldsftw.com/2009/03/live-mysql-database-search-with-jquery/
I have got the Jquery, css, html working correctly but am having troubles with the php.
I need to change it to contain my database information but everytime I do I recieve an error:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\search.php on line 33
These are the details of my database:
database name: development
table name: links
Columns: id, sitename, siteurl, description, category
This is the php script
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "password";
$dbname = "links";
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
if(isset($_GET['query'])) { $query = $_GET['query']; } else { $query = ""; }
if(isset($_GET['type'])) { $type = $_GET['type']; } else { $query = "count"; }
if($type == "count")
{
$sql = mysql_query("SELECT count(url_id)
FROM urls
WHERE MATCH(url_url, url_title, url_desc)
AGAINST('$query' IN BOOLEAN MODE)");
$total = mysql_fetch_array($sql);
$num = $total[0];
echo $num;
}
if($type == "results")
{
$sql = mysql_query("SELECT url_url, url_title, url_desc
FROM urls
WHERE MATCH(url_url, url_title, url_desc)
AGAINST('$query' IN BOOLEAN MODE)");
while($array = mysql_fetch_array($sql)) {
$url_url = $array['url_url'];
$url_title = $array['url_title'];
$url_desc = $array['url_desc'];
echo "<div class=\"url-holder\">" . $url_title . "
<div class=\"url-desc\">" . $url_desc . "</div></div>";
}
}
mysql_close($conn);
?>
Can anybody help me input this database info correctly? I have tried many times but keep getting an error. Thanks in advance.
EDIT: IT IS CONNECTING TO THE DATABASE WITHOUT AN ERROR. CHECK HERE http://movieo.no-ip.org/
the mysql_query() call is failing an returning false instead of a resource. My bet is that mysql_select_db() is failing. This should show the error:
mysql_select_db($dbname) or die('Couldn\'t select DB: '.mysql_error());
Compare: database name: development to $dbname = "links";
I think you should change it to the right name.
As well as changing the $dbname to development, check your two SQL statements. They are selecting from the table urls instead of links.