Rob56 Posted November 17, 2012 Share Posted November 17, 2012 The following code works, but I get the the error 'undefined offset' on the items of the while list. All the items are in the database. What is the problem? <? include ("db_connect.php"); $query = "SELECT * FROM rooster ";; $resultaat = ""; $resultaat = mysql_query($query, $db); mysql_close($db); ?> <?php while(list($roosterid, $ma, $kls,$ge,$f101,$extra, $urid, $urma, $urclass, $urge, $urf101) = mysql_fetch_row($resultaat)){ echo "<P>$kls"; echo "<BR><a href=\"make.php?id=$roosterid\">Fill in</a><br>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/270830-undefined-offset/ Share on other sites More sharing options...
Pikachu2000 Posted November 17, 2012 Share Posted November 17, 2012 I've tried to replicate the error and I can't make it happen. Is that the actual code you're using? Have you included all the line(s) that any error messages point to? Quote Link to comment https://forums.phpfreaks.com/topic/270830-undefined-offset/#findComment-1393185 Share on other sites More sharing options...
PFMaBiSmAd Posted November 17, 2012 Share Posted November 17, 2012 You likely have more items in your list() statement than what there are columns in your query. Posting the actual error message(s) would help pin down what is occurring. Quote Link to comment https://forums.phpfreaks.com/topic/270830-undefined-offset/#findComment-1393187 Share on other sites More sharing options...
Pikachu2000 Posted November 17, 2012 Share Posted November 17, 2012 And naturally, that's about the only thing I didn't try, lol. But yeah, that seems to cause the same symptoms when I run it that way. Quote Link to comment https://forums.phpfreaks.com/topic/270830-undefined-offset/#findComment-1393188 Share on other sites More sharing options...
Rob56 Posted November 17, 2012 Author Share Posted November 17, 2012 (edited) Thank you for your help, This is the code. Nothing is missing, now <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[url="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd[/url]"> <html xmlns="[url="http://www.w3.org/1999/xhtml"]http://www.w3.org/1999/xhtml[/url]" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf8_unicode_ci" /> <title></title> <link rel= "stylesheet" href="menu_style.css" type="text/css" /> <link href="opmaak.css" rel="stylesheet" type="text/css"/> </head> <?php include 'navigatie/nav6.inc'; ?> <div id="container"> <div id="header3"> <html> <head> <? include ("db_connect.inc.php"); $query = "SELECT * FROM rooster ";; // de SQL-query die wordt uitgevoerd $resultaat = ""; // hierin wordt het resultaat van de query opgeslagen $resultaat = mysql_query($query, $db); mysql_close($db); ?> <h2>Rooster</h2> <hr> <?php while(list($roosterid, $ma, $kls,$ge,$f101,$extra, $urid, $urma, $urclass, $urge, $urf101) = mysql_fetch_row($resultaat)){ echo "<P>$kls"; echo "<BR><a href=\"make.php?id=$roosterid\"></a><br>Fill in"; } ?> </body> </html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[url="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"]http://www.w3.org/TR...tml1-strict.dtd[/url]"> <html xmlns="[url="http://www.w3.org/1999/xhtml"]http://www.w3.org/1999/xhtml[/url]" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf8_unicode_ci" /> <title></title> <link rel= "stylesheet" href="menu_style.css" type="text/css" /> <link href="opmaak.css" rel="stylesheet" type="text/css"/> </head> </head> <?php include 'navigatie/nav6.inc'; ?> <div id="container"> <div id="header3"> <html> <head> </head> <body> <?php include ("db_connect.inc.php"); // controleren of pagina zichzelf heeft aangeroepen // via hidden field " bevestiging" van formulier if (isset($_POST["bevestiging"])){ // query samenstellen // LET OP: in werkelijkheid nog validatie uitvoeren van de gegevens in $_POST $query = "UPDATE rooster SET ma = '". $_POST["ma"] ."', kls = '". $_POST["kls"] ."', goe = '". $_POST["ge"] ."', f101 = '". $_POST["f101"] ."' WHERE roosterid='" .$_POST["id"] ."'"; mysql_query($query); $query = "UPDATE tw SET urma = '". $_POST["urma"] ."', urclass = '". $_POST["urclass"] ."', urge = '". $_POST["urge"] ."', urf101 = '". $_POST["urf101"] ."' WHERE urid='" .$_POST["id"] ."'"; mysql_query($query); echo "<h2>Rooster</h2>De volgende opdracht is uitgevoerd: <b>$query</b><br><hr>\n"; echo "Record nummer " .$_POST["id"] . " is bijgewerkt<br>\n"; echo "<a href=\"wijzigen.php\">Terug naar wijzigen.</a>"; } else{ // pagina heeft zichzelf nog niet aangeroepen, gegevens inlezen $query="SELECT * FROM rooster INNER JOIN tw ON roosterid=urid WHERE roosterid='". $_GET["id"] ."'"; $resultaat = mysql_query($query); while (list($roosterid, $ma, $kls,$ge,$f101,$extra, $urid, $urma, $urclass, $urge, $urf101 ) = mysql_fetch_row($resultaat)){ $vn=$ma; $vm=$kls; $aa=$ge; $ab=$f101; $ac=$urge; $ad=$urf101; } ?> <form action="<?php echo($_SERVER["PHP_SELF"]);?>" method="post"> <input type="hidden" name="bevestiging" value="1"> <input type="hidden" name="id" value="<?php echo $_GET["id"];?>"> <h2>wijzigen</h2> Kls:<input type="text" name="kls" value="<?php echo$vm;?>" size="50""><br> Dag <input type="checkbox" name="ma" <?php if (!empty($vn)) {echo 'checked="checked"';} ?> value="ma""/>ma <br>Eerste <input type="checkbox" name="ge" <?php if (!empty($aa)) {echo 'checked="checked"';} ?> value="ge""/>ge <input type="checkbox" name="f101" <?php if (!empty($ab)) {echo 'checked="checked"';} ?> value="f101""/>101 <br>Tweede <input type="checkbox" name="urge" <?php if (!empty($ac)) {echo 'checked="checked"';} ?> value="ge""/>ge <input type="checkbox" name="urf101" <?php if (!empty($ad)) {echo 'checked="checked"';} ?> value="utf101""/>101 <hr> <input type="Submit" value="Registreer de gegevens."> </form> <?php }// else-blok afsluiten ?> </body> </html> </div> Edited November 17, 2012 by Rob56 Quote Link to comment https://forums.phpfreaks.com/topic/270830-undefined-offset/#findComment-1393192 Share on other sites More sharing options...
jcbones Posted November 17, 2012 Share Posted November 17, 2012 Post the structure of your database table you are extracting from. Quote Link to comment https://forums.phpfreaks.com/topic/270830-undefined-offset/#findComment-1393208 Share on other sites More sharing options...
Rob56 Posted November 17, 2012 Author Share Posted November 17, 2012 Here they are. -- phpMyAdmin SQL Dump -- version 3.3.0 -- http://www.phpmyadmin.net -- -- Machine: localhost -- Genereertijd: 17 Nov 2012 om 18:16 -- Serverversie: 5.1.44 -- PHP-Versie: 5.2.13 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; /*!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: `rooster` -- -- -------------------------------------------------------- -- -- Tabelstructuur voor tabel `rooster` -- CREATE TABLE IF NOT EXISTS `rooster` ( `roosterid` int(4) NOT NULL AUTO_INCREMENT, `ma` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `kls` text NOT NULL, `ge` text NOT NULL, `f101` text NOT NULL, `extra` text NOT NULL, PRIMARY KEY (`roosterid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; -- -- Gegevens worden uitgevoerd voor tabel `rooster` -- -- phpMyAdmin SQL Dump -- version 3.3.0 -- http://www.phpmyadmin.net -- -- Machine: localhost -- Genereertijd: 17 Nov 2012 om 18:17 -- Serverversie: 5.1.44 -- PHP-Versie: 5.2.13 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; /*!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: `rooster` -- -- -------------------------------------------------------- -- -- Tabelstructuur voor tabel `tw` -- CREATE TABLE IF NOT EXISTS `tw` ( `urid` int(4) NOT NULL AUTO_INCREMENT, `urma` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `urclass` text NOT NULL, `urge` text NOT NULL, `urf101` text NOT NULL, `extra` text NOT NULL, PRIMARY KEY (`urid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; -- -- Gegevens worden uitgevoerd voor tabel `tw` -- errors: first code Notice: Undefined offset: 10 in D:... on line 40 Notice: Undefined offset: 9 in D:.. on line 40 Notice: Undefined offset: 8 in D:... on line 40 Notice: Undefined offset: 7 in D:... on line 40 Notice: Undefined offset: 6 in D:... on line 40 second code Notice: Undefined index: f101 in D:... on line 47 Notice: Undefined index: urma in D:... on line 59 Notice: Undefined index: urclass in D:... on line 61 Notice: Undefined index: urf101 in D:... on line 65 Quote Link to comment https://forums.phpfreaks.com/topic/270830-undefined-offset/#findComment-1393217 Share on other sites More sharing options...
Pikachu2000 Posted November 17, 2012 Share Posted November 17, 2012 Your table only contains 6 fields. Your list() is looking for 11 fields. Anything beyond 6 will be undefined. Quote Link to comment https://forums.phpfreaks.com/topic/270830-undefined-offset/#findComment-1393218 Share on other sites More sharing options...
Rob56 Posted November 17, 2012 Author Share Posted November 17, 2012 Thank you very much, I forgot the INNER JOIN ON roosterid=twid. There are no errors Undefined offset anymore. But the Undefined index in the second code stays. Quote Link to comment https://forums.phpfreaks.com/topic/270830-undefined-offset/#findComment-1393238 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.