Jump to content

Warning: mysql_fetch_row expects parameter 1 to be resource, boolean given in


blmv

Recommended Posts

Hi!

 

I always got that warning:

 

Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\regiszturlap.php on line 24

 

 

<?php

mysql_query("

CREATE DATABASE `adatok` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

");

mysql_select_db("adatok")

      or die ("<p>Nincs letrehozva az adatbazis!</p>");

mysql_query("

CREATE TABLE `felhasznalo` (

  `id` INT( 10 ) NOT NULL AUTO_INCREMENT ,

  `nev` VARCHAR( 10 ) NOT NULL ,

  `jelszo` VARCHAR( 10 ) NOT NULL ,

`szulev` YEAR NOT NULL ,

  `nem` CHAR( 1 ) NOT NULL ,

`hobbi` VARCHAR( 100 ) NOT NULL ,

  `szam` INT( 2 ) NOT NULL ,

`szoveg` VARCHAR( 100 ) NOT NULL ,

  PRIMARY KEY ( `id` )

)ENGINE=MyISAM DEFAULT CHARSET=utf8;

");

?>

 

$kapcsolat = mysql_connect("localhost", "root", "");

 

mysql_select_db("adatok")

      or require_once("install.php");

$felh=mysql_fetch_row(mysql_query("select nev from felhasznalo where nev='".$_POST['user1']."'", $kapcsolat));  // line 24

 

 

 

If I guess well, the problem is with the syntax , how should I fix it???

 

I would be really grateful for the help!

 

 

Link to comment
Share on other sites

I think its telling you that your query didn't produce any results. See the first example in the docs:

 

http://us3.php.net/mysql_fetch_row

 

It will show you how to test if there was a result or not.

 

 

You were right:

 

Could not run query: Table 'adatok.felhasznalo' doesn't exist

 

 

Now the question is: where did it go wrong??

 

 

 

 

<body>

<?php

if(isset($_POST['send']) && trim($_POST['user1']) != "" && trim($_POST['pwd1']) != "" && trim($_POST['pwd2']) != ""){

$kapcsolat = mysql_connect("localhost", "root", "");

if (!$kapcsolat) {

      die ("<p>Nem lehet csatlakozni a MySQL kiszolgalohoz!</p>");

}

mysql_select_db("adatok")

      or require_once("install.php");

$felh=mysql_fetch_row(mysql_query("select nev from felhasznalo where nev='".$_POST['user1']."'", $kapcsolat));

if (!$felh) {

    echo 'Could not run query: ' . mysql_error();

    exit;}

 

if($felh[0] == $_POST['user1']){

print "<div id=\"hibau\">Van ilyen felhasznalo!</div>";

$_POST['default']=true;

}else if(trim($_POST['pwd1']) != trim($_POST['pwd2'])){

print "<div id=\"hibau\">Jelszo kulonbozo!</div>";

$_POST['default']=true;

}else if(!is_numeric ($_POST['egyszam'])){

print "<div id=\"hibau\">Csak szamot irj!</div>";

$_POST['default']=true;

}else{

if($_POST['hobbi']!=NULL){

$i=0;

foreach($_POST['hobbi'] as $elem){

if ($i == 0 ) {

    $_POST['hobbik']=" $elem";

  } else {

    $_POST['hobbik']=$_POST['hobbik'].", $elem";

  }

  $i++;

}

}else{

$_POST['hobbik']="";

}

 

if ($kapcsolat) {

      mysql_query("insert into felhasznalo(nev,jelszo,szulev,nem,hobbi,szam,szoveg) values('".$_POST['user1']."','".$_POST['pwd1']."','".$_POST['szulev']."','".$_POST['neme']."','".$_POST['hobbik']."','".$_POST['egyszam']."','".$_POST['bszoveg']."')", $kapcsolat);

print "<div id=\"elfogadu\">Sikeres regisztracio!</div>";

}else{

die ("<p>Nem lehet csatlakozni a MySQL kiszolgalohoz!</p>");

}

}

mysql_close($kapcsolat);

}else if(isset($_POST['send'])){

$_POST['default']=true;

}

if(isset($_POST['delete'])){

$kapcsolat = mysql_connect("localhost", "root", "");

if (!$kapcsolat) {

      die ("<p>Nem lehet csatlakozni a MySQL kiszolgalohoz!</p>");

}

mysql_select_db("adatok")

      or require_once("install.php");

if ($kapcsolat) {

mysql_query("delete from felhasznalo where nev='".$_POST['tazonosito']."'", $kapcsolat);

print "<div id=\"elfogadu\">Torolve a(z) ".$_POST['tazonosito']." felhasznalo!</div>";

}else{

die ("<p>Nem lehet csatlakozni a MySQL kiszolgalohoz!</p>");

}

mysql_close($kapcsolat);

}

if(isset($_POST['default']) || isset($_POST['add']) && (trim($_POST['user']) == "" || trim($_POST['pwd']) == "")){

print "

<h1>Regisztracio</h1>

<div id=\"figyu\">A csillagozottak kotelezok!</div>

<form action=\"".$_SERVER["PHP_SELF"]."\" method=\"post\" id=\"reg\">

<p><label for=\"user1\">Azonosito *:<br /> <input type=\"text\" id=\"user1\" name=\"user1\" maxlength=\"10\" size=\"20\"/></label> </p>

<p><label for=\"pwd1\">Jelszo *:<br /> <input type=\"password\" id=\"pwd1\" name=\"pwd1\" maxlength=\"10\" size=\"20\"/></label> </p>

<p><label for=\"pwd2\">Jelszo ujra *:<br /> <input type=\"password\" id=\"pwd2\" name=\"pwd2\" maxlength=\"10\" size=\"20\"/></label> </p>

<p><label for=\"szulev\">Szuletesi ev: 

<select id=\"szulev\" name=\"szulev\">";

for ($evszam = 1900; $evszam <= 2003; $evszam++){

print "<option value=\"$evszam\">$evszam</option>";

}

print "

</select></label>

</p>

<p>

Nem:

<label for=\"ferfi\">Ferfi <input type = \"radio\" name = \"neme\" id = \"ferfi\" checked = \"checked\" value = \"f\" /></label>

<label for=\"no\">No <input type = \"radio\" name = \"neme\" id = \"no\" value = \"n\" /></label><br />

</p>

<p>

Hobbi:

<br /><label for=\"vitorl\">Vitorlazas<input type=\"checkbox\" value=\"vitorlazas\" id=\"vitorl\" name=\"hobbi[]\"/></label>

<br /><label for=\"sieles\">Sieles<input type=\"checkbox\" value=\"sieles\" id=\"sieles\" name=\"hobbi[]\"/></label>

<br /><label for=\"ejtoerny\">Ejtoernyozes<input type=\"checkbox\" value=\"ejtoernyozes\" id=\"ejtoerny\" name=\"hobbi[]\"/></label>

<br /><label for=\"salsa\">Salsa<input type=\"checkbox\" value=\"salsa\" id=\"salsa\" name=\"hobbi[]\"/></label>

<br /><label for=\"gorkori\">Gorkorizas<input type=\"checkbox\" value=\"gorkorizas\" id=\"gorkori\" name=\"hobbi[]\"/></label>

</p>

<p><label for=\"egyszam\">Hany oraja netezik? <input type=\"text\" id=\"egyszam\" name=\"egyszam\" maxlength=\"2\" size=\"2\"/> </label></p>

<p>

<label for=\"bszoveg\">

Bemutatkozas: <br />

<textarea name=\"bszoveg\" id = \"bszoveg\" rows = \"4\" cols = \"20\"></textarea>

</label>

</p>

<p> <input type=\"submit\" name=\"default\" value=\"Alapallapot\"/>

<input type=\"submit\" name=\"send\" id=\"send\"  value=\"Kuldes\"/>

<input type=\"submit\" name=\"logout\" id=\"logout\"  value=\"Vissza\" /></p>

</form>

";

}else if(isset($_POST['add'])){

$kapcsolat = mysql_connect("localhost", "root", "");

if (!$kapcsolat) {

      die ("<p>Nem lehet csatlakozni a MySQL kiszolgalohoz!</p>");

}

mysql_select_db("adatok")

      or require_once("install.php");

$felh=mysql_fetch_row(mysql_query("select nev from felhasznalo where nev='".$_POST['user']."'", $kapcsolat));

$jels=mysql_fetch_row(mysql_query("select jelszo from felhasznalo where jelszo='".$_POST['pwd']."'", $kapcsolat));

$ev=mysql_fetch_row(mysql_query("select szulev from felhasznalo where nev='".$_POST['user']."'", $kapcsolat));

$neme=mysql_fetch_row(mysql_query("select nem from felhasznalo where nev='".$_POST['user']."'", $kapcsolat));

$szorak=mysql_fetch_row(mysql_query("select hobbi from felhasznalo where nev='".$_POST['user']."'", $kapcsolat));

$tipp=mysql_fetch_row(mysql_query("select szam from felhasznalo where nev='".$_POST['user']."'", $kapcsolat));

$bemut=mysql_fetch_row(mysql_query("select szoveg from felhasznalo where nev='".$_POST['user']."'", $kapcsolat));

if($felh[0] == $_POST['user'] && $jels[0] == $_POST['pwd']){

print "

<h1>Szia </h1>

<div id=\"leiras\">

Felhasznalonev: \"$felh[0]\".<br />

Jelszo: \"$jels[0]\".<br />

Szuletesi ev:";

if($ev[0]=="0000")

print " 1900.<br />";

else

print " $ev[0].<br />";

print "

Nem: ";

if($neme[0]=="f")

print " ferfi.<br />";

else

print " no.<br />";

print "

Hobbi: ";

if($szorak[0]=="")

print " nincs.<br />";

else

print " $szorak[0].<br />";

print "

$tipp[0]-t irtad.<br />

A kovetkezot toltotted fel:<br /> $bemut[0] <br />

</div>

<form action=\"".$_SERVER["PHP_SELF"]."\" method=\"post\" id=\"kilep\">

<p><input type=\"submit\" name=\"delete\" value=\"Felhasznalo torlese\" />

<input type=\"hidden\" name=\"tazonosito\" value=\"".$_POST['user']."\" />

<input type=\"submit\" name=\"logout\" value=\"Kilepes\" /></p>

</form>

";

}else{

print "

<div id=\"hibau\">Nem sikerult belepni!<br /> </div>

<h1>Bejelentkezes</h1>

<form action=\"".$_SERVER["PHP_SELF"]."\" method=\"post\" id=\"bevitel\">

<p><label for=\"user\">Azonosito:<br /> <input type=\"text\" id=\"user\" name=\"user\" maxlength=\"10\" size=\"20\"/> </label></p>

<p><label for=\"pwd\">Jelszo:<br /> <input type=\"password\" id=\"pwd\" name=\"pwd\" maxlength=\"15\" size=\"20\"/> </label></p>

<p> <input type=\"submit\" name=\"add\" id=\"add\" value=\"Bejelentkezes/Regisztracio\"/> </p>

</form>

<form action=\"Fooldal.html\" method=\"post\" id=\"visszagomb\">

<p> <input type=\"submit\" name=\"back\" id=\"back\" value=\"Vissza a fooldalra\" /> </p>

</form>

";

}

mysql_close($kapcsolat);

}else{

print "

<h1>Bejelentkezes</h1>

<form action=\"".$_SERVER["PHP_SELF"]."\" method=\"post\" id=\"bevitel\">

<p><label for=\"user\">Azonosito:<br /> <input type=\"text\" id=\"user\" name=\"user\" maxlength=\"10\" size=\"20\"/> </label></p>

<p><label for=\"pwd\">Jelszo:<br /> <input type=\"password\" id=\"pwd\" name=\"pwd\" maxlength=\"15\" size=\"20\"/> </label></p>

<p> <input type=\"submit\" name=\"add\" id=\"add\" value=\"Bejelentkezes/Regisztracio\"/> </p>

</form>

<form action=\"Fooldal.html\" method=\"post\" id=\"visszagomb\">

<p> <input type=\"submit\" name=\"back\" id=\"back\" value=\"Vissza a fooldalra\" /> </p>

</form>

";

}

?>

Link to comment
Share on other sites

Do you have a database named adatok with a table named felhasznalo?

 

Yes, it looks like this:

 

<?php

  mysql_query("

      CREATE DATABASE `adatok` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

  ");

  mysql_select_db("adatok")

        or die ("<p>Nincs letrehozva az adatbazis!</p>");

  mysql_query("

      CREATE TABLE `felhasznalo` (

            `id` INT( 10 ) NOT NULL AUTO_INCREMENT ,

            `nev` VARCHAR( 10 ) NOT NULL ,

            `jelszo` VARCHAR( 10 ) NOT NULL ,

        `szulev` YEAR NOT NULL ,

            `nem` CHAR( 1 ) NOT NULL ,

        `hobbi` VARCHAR( 100 ) NOT NULL ,

            `szam` INT( 2 ) NOT NULL ,

        `szoveg` VARCHAR( 100 ) NOT NULL ,

            PRIMARY KEY ( `id` )

      )ENGINE=MyISAM DEFAULT CHARSET=utf8;

  ");

?>

Link to comment
Share on other sites

What exactly do you want the select to return on the line that you were getting the error on, because your WHERE statement has thew wrong syntax.

 

 

I would like to login with a name(=nev) and a password(=jelszo). I need to check: that the two passwords are equal.

 

 

Link to comment
Share on other sites

$felh=mysql_fetch_row(mysql_query("select nev from felhasznalo where nev='".$_POST['user1']."'", $kapcsolat));

should read:

$felh=mysql_fetch_row(mysql_query("SELECT nev FROM felhasznalo WHERE nev= '".$_POST['user1']."' AND password = '".$kapcsolat."'"));

 

 

It is still the same:

 

Could not run query: Table 'adatok.felhasznalo' doesn't exist

 

Something is wrong with the table and with the references..

Link to comment
Share on other sites

Check your table names by making a new php page and run this code on it.

<?php
mysql_connect("localhost", "root", "");
mysql_select_db("adatok") or die (mysql_error());
$qry = "show tables";
$result = mysql_query($qry) or die (mysql_error());
while ($row = mysql_fetch_array($result)){
echo $row[0];
}
?>

 

Link to comment
Share on other sites

Check your table names by making a new php page and run this code on it.

<?php
mysql_connect("localhost", "root", "");
mysql_select_db("adatok") or die (mysql_error());
$qry = "show tables";
$result = mysql_query($qry) or die (mysql_error());
while ($row = mysql_fetch_array($result)){
echo $row[0];
}
?>

 

 

 

It didn't give back any table names. :(

Link to comment
Share on other sites

That then seems to be the problem.

re-run your

   mysql_select_db("adatok")
         or die ("<p>Nincs letrehozva az adatbazis!</p>");
   mysql_query("
      CREATE TABLE `felhasznalo` (
            `id` INT( 10 ) NOT NULL AUTO_INCREMENT ,
            `nev` VARCHAR( 10 ) NOT NULL ,
            `jelszo` VARCHAR( 10 ) NOT NULL ,
         `szulev` YEAR NOT NULL ,
            `nem` CHAR( 1 ) NOT NULL ,
         `hobbi` VARCHAR( 100 ) NOT NULL ,
            `szam` INT( 2 ) NOT NULL ,
         `szoveg` VARCHAR( 100 ) NOT NULL ,
            PRIMARY KEY ( `id` )
      )ENGINE=MyISAM DEFAULT CHARSET=utf8;
   ");

with the addition of the

or die (mysql_error())

before the ; on the last line and see what happens.

Link to comment
Share on other sites

That then seems to be the problem.

re-run your

   mysql_select_db("adatok")
         or die ("<p>Nincs letrehozva az adatbazis!</p>");
   mysql_query("
      CREATE TABLE `felhasznalo` (
            `id` INT( 10 ) NOT NULL AUTO_INCREMENT ,
            `nev` VARCHAR( 10 ) NOT NULL ,
            `jelszo` VARCHAR( 10 ) NOT NULL ,
         `szulev` YEAR NOT NULL ,
            `nem` CHAR( 1 ) NOT NULL ,
         `hobbi` VARCHAR( 100 ) NOT NULL ,
            `szam` INT( 2 ) NOT NULL ,
         `szoveg` VARCHAR( 100 ) NOT NULL ,
            PRIMARY KEY ( `id` )
      )ENGINE=MyISAM DEFAULT CHARSET=utf8;
   ");

with the addition of the

or die (mysql_error())

before the ; on the last line and see what happens.

 

 

 

 

Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\install.php on line 5

 

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in C:\xampp\htdocs\install.php on line 5

 

Nincs lĂŠtrehozva az adatbĂĄzis!

Link to comment
Share on other sites

The code you are executing to create the table does not have any code in it to make a connection to the database server first.

 

I need something like that, don't I ???

 

 

...

or require_once("Install.php");

$ab = new Install();

$ab->connect();

$ab->choose_database("adatok");

 

 

 

<?php

class Install{

private $nev;

private $jelszo;

private $host;

public $kapcsolat;

 

public function Install($nev="root",$jelszo="",$host="localhost"){

$this->nev = $nev;

$this->jelszo = $jelszo;

$this->host = $host;

}

 

public function connect(){

$this->kapcsolat = mysql_connect($this->host,$this->nev,$this->jelszo) or

die("Error: ".mysql_error());

}

 

public function choose_database($abnev){

if(!(mysql_select_db($abnev,$this->kapcsolat))){

mysql_query("CREATE DATABASE `adatok` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;");

$this->tablakat_letrehoz();

mysql_select_db($abnev,$this->kapcsolat);

}

}

 

private function tablakat_letrehoz(){

mysql_query("CREATE TABLE `adatok`.`felhasznalo`(

`id` INT( 10 ) NOT NULL AUTO_INCREMENT ,

                        `nev` VARCHAR( 10 ) NOT NULL ,

                        `jelszo` VARCHAR( 10 ) NOT NULL ,

`szulev` YEAR NOT NULL ,

                        `nem` CHAR( 1 ) NOT NULL ,

`hobbi` VARCHAR( 100 ) NOT NULL ,

                        `szam` INT( 2 ) NOT NULL ,

`szoveg` VARCHAR( 100 ) NOT NULL ,

                          PRIMARY KEY ( `id` ))");

}

}

?>

 

Link to comment
Share on other sites

erm...not for testing you don't.  Just stick your connection string at the top of the code I gave you

mysql_connect("localhost", "root", "");

so it looks like this:

<?php
mysql_connect("localhost", "root", "");
mysql_select_db("adatok")
         or die ("<p>Nincs letrehozva az adatbazis!</p>");
   mysql_query("
      CREATE TABLE `felhasznalo` (
            `id` INT( 10 ) NOT NULL AUTO_INCREMENT ,
            `nev` VARCHAR( 10 ) NOT NULL ,
            `jelszo` VARCHAR( 10 ) NOT NULL ,
         `szulev` YEAR NOT NULL ,
            `nem` CHAR( 1 ) NOT NULL ,
         `hobbi` VARCHAR( 100 ) NOT NULL ,
            `szam` INT( 2 ) NOT NULL ,
         `szoveg` VARCHAR( 100 ) NOT NULL ,
            PRIMARY KEY ( `id` )
      )ENGINE=MyISAM DEFAULT CHARSET=utf8;
   ") or die (mysql_error());
?>

 

This way we should see if there is a problem with the create statement or if It makes the table.

Link to comment
Share on other sites

erm...not for testing you don't.  Just stick your connection string at the top of the code I gave you

mysql_connect("localhost", "root", "");

 

This way we should see if there is a problem with the create statement or if It makes the table.

 

 

 

It made the table :  Table 'felhasznalo' already exists

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.