Jump to content

php causing error no clue...


west4me

Recommended Posts

I am getting this error
[code]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/west4mec/public_html/multiplication/index.php on line 12

Warning: Cannot modify header information - headers already sent by (output started at /home/west4mec/public_html/multiplication/index.php:12) in /home/west4mec/public_html/multiplication/index.php on line 21[/code]

I had someone write this for me awhile ago and I must have messed somehting up. Anyone see an error in the code?
I borrowed the layout from WordPress so there is a bunch of extra stuff in there.

THis is the index page:
[code]
<?php
require_once("dbconnect.php");
session_start();

if ($_POST) {

    
    $user = $_POST["username"];
    $pass = md5($_POST["password"]);
    
    $query = mysql_query("SELECT * FROM login WHERE username = '$user' AND password = '$pass'");
    $row = mysql_fetch_array($query);
    
    
    if ($user == $row["username"] && $pass = $row["password"]) {
        session_register('username');
        $_SESSION['username'] = $user;
    
        header ("location: admin.php");
    } else {
        header ("location: index.php");
    }
    
}

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head profile="http://gmpg.org/xfn/11">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Multiplication Administration</title>
    <meta name="generator" content="WordPress 1.5.2" /> <!-- leave this for stats please -->
    <style type="text/css" media="screen">
    </style>    
    <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://west4me.com/wordpress/?feed=rss2" />
    <link rel="alternate" type="application/atom+xml" title="Atom 0.3" href="http://west4me.com/wordpress/?feed=atom" />
    <link rel="pingback" href="http://west4me.com/wordpress/xmlrpc.php" />

        <link rel='archives' title='October 2005' href='http://west4me.com/wordpress/?m=200510' />
    <link rel='archives' title='September 2005' href='http://west4me.com/wordpress/?m=200509' />
    <link href="style.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
<!--
.style2 {font-size: 16px; }
.style3 {font-size: 16px; color: #676E04; }
-->
    </style>
</head>

<body>
<div id="rap">
    <div id="header">
    <ul id="topnav">
        <li><a href="http://west4me.com/moodle" id="navHome" title="Posted Recently" accesskey="h">Home</a></li>
        <li><a href="http://west4me.com/cal" id="navHome" title="Posted Recently" accesskey="c">Calendar</a></li>
        <li><a href="http://west4me.com/story2" id="navHome" title="Posted Recently" accesskey="s">Stories</a></li>
        <li><a href="http://west4me.com/bookmarks" id="navHome" title="Posted Recently" accesskey="b">Bookmarks</a></li>
        <li><a href="http://west4me.com/wordpress" id="navHome" title="Posted Recently" accesskey="w">Blog</a></li>
        <li><a href="http://west4me.com/webcollab/index.php" id="navHome" title="Posted Recently" accesskey="p">Writing Progress</a></li>
         <li><a href="http://west4me.com/kidscms/index.php" id="navHome" title="Posted Recently" accesskey="f">Student Pages</a></li>
        <li><a href="http://west4me.com/daily/name.php" id="navHome" title="Posted Recently" accesskey="f">Name Draw</a></li>
    <li><a href="http://west4me.com/daily/job2.php" id="navHome" title="Posted Recently" accesskey="f">Jobs</a></li>
    <li><a href="http://west4me.com/daily/lunch.php" id="navHome" title="Posted Recently" accesskey="f">Lunch Choice</a></li>     
        <li><a href="http://west4me.com/daily/" id="navHome" title="Posted Recently" accesskey="f">Daily</a></li>
    </ul>

    <h1><a href="http://west4me.com/daily" title=""></a></h1>        
    <div id="desc">Classroom Schedule</div>
</div>
    <div id="main">
    <div id="content">
                        <div class="post">
                
<div class="post-info"><h2 class="post-title">Welcome to another wonderful day!</a></h2>
  <p>Make sure you take care of all your morning tasks before the bell rings.</p>
  </div>

<div class="post-content">
        <form name='login' method='POST'>
<table style='width:300px;'>
    <tr><td>Username</td><td><input type='text' name='username' /></td></tr>
    <tr><td>Password</td><td><input type='password' name='password' /></td></tr>
    <tr><td></td><td><input type='submit' value='Login' /></td></tr>
</table>
        
        
        <div id="content"></div>
        <p>&nbsp;</p>
</div>                            </div>
                                                
                    <p align="center"></p>        
    </div>
    
    
<p id="footer"><a href="http://www.west4me.com/moodle" title="Cunningham">Mr. Cunningham's Classroom</a></p></div>
</div>
</body>
</html>[/code]

and this is the admin page:
[code]<?php
/********************************************\
*                                            *
*          class test administation          *
*         copyright 2005 Phil Pedlar         *
*                                            *
\********************************************/
session_start();
if (!$_SESSION['username']) {
    header ("location: index.php");
}
include ("dbconnect.php");

require_once("dbconnect.php");

function print_footer() {
print  "<div class='page-content'>
         <div colspan='5' class='post-footer'>&nbsp;</div>
         </div>
         </div>
         </div>
         </div>
         <p align='center'></p>        
         </div>
         <p id='footer'><a href='http://www.west4me.com/moodle' title='Cunningham'>Mr. Cunninghams Classroom</a></p></div>
         </div>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head profile="http://gmpg.org/xfn/11">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Multiplication Administration</title>
    <meta name="generator" content="WordPress 1.5.2" /> <!-- leave this for stats please -->
    <style type="text/css" media="screen">
    </style>    
    <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://west4me.com/wordpress/?feed=rss2" />
    <link rel="alternate" type="application/atom+xml" title="Atom 0.3" href="http://west4me.com/wordpress/?feed=atom" />
    <link rel="pingback" href="http://west4me.com/wordpress/xmlrpc.php" />

        <link rel='archives' title='October 2005' href='http://west4me.com/wordpress/?m=200510' />
    <link rel='archives' title='September 2005' href='http://west4me.com/wordpress/?m=200509' />
    <link href="http://west4me.com/multiplication/style.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
<!--
.style2 {font-size: 16px; }
.style3 {font-size: 16px; color: #676E04; }
-->
#scores { border: 1px solid black; background:#ffffff; text-align:center; padding-left: 10px; padding-right: 10px;}
#scores td { border: 1px solid black; background:#F3F6ED; padding-left: 3px; padding-right: 3px; width: 725px;}
    </style>
</head>

<body>
<div id="rap">
    <div id="header">
    <ul id="topnav">
        <li><a href="http://west4me.com/moodle" id="navHome" title="Posted Recently" accesskey="h">Home</a></li>
        <li><a href="http://west4me.com/cal" id="navHome" title="Posted Recently" accesskey="c">Calendar</a></li>
        <li><a href="http://west4me.com/story2" id="navHome" title="Posted Recently" accesskey="s">Stories</a></li>
        <li><a href="http://west4me.com/bookmarks" id="navHome" title="Posted Recently" accesskey="b">Bookmarks</a></li>
        <li><a href="http://west4me.com/wordpress" id="navHome" title="Posted Recently" accesskey="w">Blog</a></li>
        <li><a href="http://west4me.com/webcollab/index.php" id="navHome" title="Posted Recently" accesskey="p">Writing Progress</a></li>
         <li><a href="http://west4me.com/kidscms/index.php" id="navHome" title="Posted Recently" accesskey="f">Student Pages</a></li>
        <li><a href="http://west4me.com/daily/name.php" id="navHome" title="Posted Recently" accesskey="f">Name Draw</a></li>
    <li><a href="http://west4me.com/daily/job2.php" id="navHome" title="Posted Recently" accesskey="f">Jobs</a></li>
    <li><a href="http://west4me.com/daily/lunch.php" id="navHome" title="Posted Recently" accesskey="f">Lunch Choice</a></li>     
        <li><a href="http://west4me.com/daily/" id="navHome" title="Posted Recently" accesskey="f">Daily</a></li>
    </ul>

    <h1><a href="http://west4me.com/daily" title=""></a></h1>        
    <div id="desc">Multiplication Tests</div>
</div>
    <div id="main">
    <div id="content">
                        <div class="post">
                
<div class="post-info"><h2 class="post-title">Multiplication Test Administration</a></h2>
  <p></p>
  </div>

<div class="post-content">
        
        <div align="center"><span>| <a href='admin.php?add=class'>Add Class</a> | <a href='admin.php?add=student'>Add Student</a> | <a href='admin.php?add=scores'>Add Scores</a> | <a href='admin.php?show=completetests'>View Complete Tests</a> |</span></div>


<?
print "<div class='post-content'>";
//this section is for adding a class
if ($_GET["add"] == "class") {
    if ($_GET["add"] == "class" && $_POST["classname"]) {
        $classname = $_POST["classname"];
        $query = mysql_query("INSERT INTO classes (`classid`, `classname`) VALUES ('', '$classname')");
        print "<p>Class $classname was succesfully added to the the classes list</p>";
        exit();    
    }
    print "<div class='post-title'><p>Please type in the box below which classname you would like to add to the list</p></div>";
    print "<form method='post'>
            <table style='width:300px;'>
                <tr><td>Classname</td><td><input type='text' name='classname' /></td></tr>
                <tr><td></td><td><input type='submit' value='Add Class' /></td></tr>
            </table>
            </form>";
    

    
    
//this section is for adding a student
} else if ($_GET["add"] == "student") {
    if ($_GET["add"] == "student" && $_POST["student_classname"] == "select") {
        print "<p>You did not select a class for this student</p>
                <p><a href='admin.php?add=student'>back</a></p>";
        exit();
    } else if ($_GET["add"] == "student" && $_POST["student_studentname"] && $_POST["student_classname"]) {
        
        $studentname = $_POST["student_studentname"];
        $classname     = $_POST["student_classname"];
        $query = mysql_query("INSERT INTO students (`studentid`, `student_name`, `classname`) VALUES ('', '$studentname', '$classname')");
    
        print "<p>Succsfully added student: $studentname to class: $classname</p>";
        
        exit();
    }
    print "<p>Please type the name of the student you would like to add in the box and select the classname that they belong to.</p>";
    print "<form method='post'>
                <table style='width:300px;'>
                    <tr><td>Student Name:</td><td><input type='text' name='student_studentname' /></td></tr>
                    <tr><td>Student Class:</td><td>
                        <select name='student_classname'>
                            <option value='select' selected='selected'>Select</option>";
    $query = mysql_query("SELECT * FROM classes");    
        while ($row = mysql_fetch_array($query)) {
            print "<option value='".$row["classname"]."'>".$row["classname"]."</option>";    
        }
    
    print "    </select>
                    </td></tr>
                    <tr><td></td><td><input type='submit' value='Add Student' /></td></tr>
                    </table>
                    </form>";
    
    
    
    
    
    
    
    
        
} else if ($_GET["add"] == "scores") {
print "<h2>Please select the class you would like to add results for</h2>";
        $query = mysql_query("SELECT * FROM classes");
        print "<form method='post'>
                <table>
                    <tr><td>Class</td><td>
                        <select name='add_byclass' onchange='this.form.submit();'>
                            <option value='select' selected='selected'>Select</option>";
        while ($row = mysql_fetch_array($query)) {
            print "<option value='".$row["classname"]."'>".$row["classname"]."</option>";    
        }    
    print "</select></td></tr></table></form>";
            
    
            if ($_GET["add"] == "scores" && $_POST["add_byclass"]) {
                print "<h2>Please select the student you would like to add results for</h2>";
                
                $class = $_POST["add_byclass"];
                $query = mysql_query("SELECT * FROM students WHERE classname = '$class'");
                print "<form method='post'>
                <table>
                    <tr><td>Student</td><td>
                        <select name='add_byname' onchange='this.form.submit();'>
                            <option value='select' selected='selected'>Select</option>";
                while ($row = mysql_fetch_array($query)) {
                    print "<option value='".$row["student_name"]."'>".$row["student_name"]."</option>";    
                
                }
                print "<input type='hidden' name='student_name' value='".$row["student_name"]."' />
                        </table>
                        </form>";
                print_footer();        
                exit();
            
            }
            if ($_GET["add"] == "scores" && $_POST["add_byname"]) {
                    
                $name = $_POST["add_byname"];        
                $query = mysql_query("SELECT * FROM students WHERE student_name = '$name' ORDER BY student_name");
                if ($row = mysql_fetch_array($query))    {
                        print "<form method='post' action='addscores.php'>                
                        <table width='100%' id='scores'>
                        <tr><th>Name</th><th>Class</th><th>2 x 2</th><th>3 x 3</th><th>4 x 4</th><th>5 x 5</th><th>6 x 6</th><th>7 x 7</th><th>8 x 8</th><th>9 x 9</th>
                            <th>10 x 10</th><th>11 x 11</th><th>12 x 12</th></tr>";
                    do {
                
                        print "<td style='width:50px;'>".$row["student_name"]."</td><td style='width:50px;'>".$row["classname"]."</td>";
                        print "<td><select name='add_2by2'><option value='".$row["2by2"]."'>".$row["2by2"]."</option><option value='Pass'>Pass</option><option value='Fail'>Fail</option></select></td>";
                        for ($n = 3; $n <= 12; $n++) {
                            print "<td><select name=\"add_$nby$n\"><option value='".$row["$nby$n"]."'>".$row["$nby$n"]."</option><option value='Pass'>Pass</option><option value='Fail'>Fail</option></select></td>";
                        }
                        print "</tr>";
                        
                
                    } while ($row = mysql_fetch_array($query));
                }
            
            print "</table>";
            print "<input type='submit' name='add_class_scores' value='Add Scores' />
                    <input type='hidden' value='".$name."' name='student_name' />
                    </form>";
            print_footer();
            exit();    
        }

    
    
    
    
    
    
    
    
    
    
// this section is for showing completed test results, by class or by individual
} else if ($_GET["show"] == "completetests") {
    print "<div class='post-title'><p>Please select by what you would like to view scores</p></div>
            <p><a href='admin.php?show=completetests&type=class'>By Class</a><br /><a href='admin.php?show=completetests&type=individual'>By Individual</a></p>";
    
    if ($_GET["show"] == "completetests" && $_GET["type"] == "class") {
        if ($_GET["show"] == "completetests" && $_GET["type"] == "class" && $_POST["results_byclass"]) {
            $class = $_POST["results_byclass"];
            $query = mysql_query("SELECT * FROM students WHERE classname = '$class'");
            
            if ($row = mysql_fetch_array($query)) {
                print "<h2>Viewing Results by Class</h2>
                        <table width='100%' id='scores'>
                        <th>Name</th><th>Class</th><th>2 x 2</th><th>3 x 3</th><th>4 x 4</th><th>5 x 5</th><th>6 x 6</th><th>7 x 7</th><th>8 x 8</th><th>9 x 9</th>
                        <th>10 x 10</th><th>11 x 11</th><th>12 x 12</th>";            
                do {            
                    
                    print "<tr><td>".$row["student_name"]."</td><td>".$row["classname"]."</td><td class='$class'>".$row["2by2"]."</td>
                            <td class='$class'>".$row["3by3"]."</td><td class='$class'>".$row["4by4"]."</td><td class='$class'>".$row["5by5"]."</td>
                            <td class='$class'>".$row["6by6"]."</td><td class='$class'>".$row["7by7"]."</td><td class='$class'>".$row["8by8"]."</td>
                            <td class='$class'>".$row["9by9"]."</td><td class='$class'>".$row["10by10"]."</td><td class='$class'>".$row["11by11"]."</td>
                            <td class='$class'>".$row["12by12"]."</td>";
                } while ($row = mysql_fetch_array($query));    
                
                print "</table>";
                print_footer();
            }
                
            exit();
        }
        
        $query = mysql_query("SELECT * FROM classes");
        
        print "<p>Please select which class you would like to see the results for</p>
                <form method='post'>
                    <table style='width:300px'>
                        <tr><td style='width:30px;'>Class</td><td>
                            <select name='results_byclass' onchange='this.form.submit();'>
                                <option value='select' selected='selected'>Select</option>";
        while ($row = mysql_fetch_array($query)) {
                print "<option value='".$row["classname"]."'>".$row["classname"]."</option>";
        }
        
        print "</select></td></tr>
                </table>
                </form>";
                print_footer();
    } else if ($_GET["show"] == "completetests" && $_GET["type"] == "individual") {
        if ($_GET["show"] == "completetests" && $_GET["type"] == "individual" && $_POST["results_byind"]) {
            
            $name = $_POST["results_byind"];
            $query = mysql_query("SELECT * FROM students WHERE student_name = '$name'");
            if ($row = mysql_fetch_array($query)) {
                print "<h2>Viewing Results by Student</h2>
                        <table width='100%' id='scores'>
                        <th>Name</th><th>Class</th><th>2 x 2</th><th>3 x 3</th><th>4 x 4</th><th>5 x 5</th><th>6 x 6</th><th>7 x 7</th><th>8 x 8</th><th>9 x 9</th>
                        <th>10 x 10</th><th>11 x 11</th><th>12 x 12</th>";            
                do {
                    
                for ($n = 2; $n <= 12; $n++) {
                    if ($row["$nby$n"] == " ") $class = "amber";
                    if ($row["$nby$n"] == "Fail") $class = "red";
                    if ($row["$nby$n"] == "Pass") $class = "green";
                }
                    
                    
                    
                    print "<tr><td>".$row["student_name"]."</td><td>".$row["classname"]."</td><td class='$class'>".$row["2by2"]."</td>
                            <td class='$class'>".$row["3by3"]."</td><td class='$class'>".$row["4by4"]."</td><td class='$class'>".$row["5by5"]."</td>
                            <td class='$class'>".$row["6by6"]."</td><td class='$class'>".$row["7by7"]."</td><td class='$class'>".$row["8by8"]."</td>
                            <td class='$class'>".$row["9by9"]."</td><td class='$class'>".$row["10by10"]."</td><td class='$class'>".$row["11by11"]."</td>
                            <td class='$class'>".$row["12by12"]."</td>";
                } while ($row = mysql_fetch_array($query));    
                
                print "</table>";
                print_footer();
                exit();
            }
                
            
        }
        
        $query = mysql_query("SELECT * FROM students");
            
        print "<form method='post'>
                <table>
                    <tr><td>Student</td><td>
                        <select name='results_byind' onchange='this.form.submit();'>
                            <option value='select' selected='selected'>Select</option>";
        while ($row = mysql_fetch_array($query)) {
            print "<option value='".$row["student_name"]."'>".$row["student_name"]."</option>";    
        }    
        
        print "</select></td></tr>
                </table></form>";
                
    }
                        
}

?>
          
          <div class="page-content">
            <div colspan="5" class="post-footer">&nbsp;</div>
          </div>
        </div>
        
        
</div>                            </div>
                                                
                    <p align="center"></p>        
    </div>
    
    
<p id="footer"><a href="http://www.west4me.com/moodle" title="Cunningham">Mr. Cunningham's Classroom</a></p></div>
</div>
</body>
</html>[/code]
Link to comment
Share on other sites

That is a copy/paste error. here is the db-connect
[code]<?

$location = "localhost";
$user = "******";
$password    = "****";
$db = "*****";

$conn = mysql_connect($location, $user, $password) or die("Could not connect to MySQL");
$db = mysql_select_db($db) or die("Could not select database".mysql_error());

?>[/code]

THanks for taking the time to look.
Link to comment
Share on other sites

add the red part on and tell me what error you get
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
if ($_POST) {


$user = $_POST["username"];
$pass = md5($_POST["password"]);

$query = mysql_query("SELECT * FROM login WHERE username = '$user' AND password = '$pass'")[!--coloro:red--][span style=\"color:red\"][!--/coloro--] or die(mysql_error()) ;[!--colorc--][/span][!--/colorc--]
$row = mysql_fetch_array($query);
[/quote]
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.