ok so i am trying to make a program that is able to viewed on the web using mysql and php together. i have to show a little icon or something saying would you like to view the listing you submitted. this is my program but i keep getting a error as Parse error: syntax error, unexpected T_STRING in /home/bfinnegan/public_html/listclass.php on line 15
here is listclass.php

<?php
include("include.php");
doDB;

if(!$_POST)
{       $display_block="<h1>Select an entry</h1>";

        $get_list_sql="SELECT id,
                        CONCAT_WS(name,last) AS display_name
                        FROM student_name ORDER BY name, last";
        $get_list_res="mysqli_query($mysqli,$get_list_sql)
                        or die(mysqli_error($mysqli));

        if(mysqli_num_rows($get_list_res)<1)
        {       $display_block .= "Sorry, no records found";
        }else if{
                $display_block .= "
                <form method=\"post\" action=\"".SERVER["PHP_SELF"]."\">
                <p><strong>Select a name to view:</strong><br/>
                <select name=\"sel_id\">
                <option value=\"\">-- Select One --</option>";

                while($recs=mysqli_fetch_array($get_list_fes))
                {       $id=recs['id'];
                        $display_name=stripslashes($recs["display_name"]);
                        $display_block .="<option value=\"".$id."\">".
                        $display_name."</option>";
                }
                $display_block .="
                </select>
                <input type=\"submit\" name=\"submit\"
                                value=\"View Selected Name\"></p>
                </form>";
        }

mysqli_free_result($get_list_res);
} else if($_POST)
{       if($_POST["sel_id"] ==""){
        header("Location: listclass.php");
        exit;
}

        $get_student_sql="SELECT concat_ws(' ',name,last, class_name,class_num,profes,class_name2,class_num2,profes2) as
                display_name FROM student WHERE id='".$POST["sel_id"]."'";
        $get_student_res=mysqli_query($mysqli,$get_student_sql)
                        or die(mysqli_error($mysqli));

        while($name_info=mysqli_fetch_array($get_student_res))'{
                $display_name=stripslashes($name_info['display_name']);
        }
        $display_block="<h1>Showing List for".$display_name."</h1>";
        mysqli_free_result(get_student_res);

        $display_block .="<br/>
        <p align=\"center\">
        <a href=\"".$SERVER["PHP_SELF"]."\">select another</a></p>";
}

mysqli_close($mysqli);
?>
<html>
<head>
<title>Listing</title>
</head>
<body>
<?php echo $display_block; ?>
</body>
</html>

Recommended Answers

All 7 Replies

Member Avatar for spthorn

Go back to line 11 - there's an extra double-quote in there.

ah ok thank you so much! i have another problem with a part that goes to this program. it is suppose to go to another page that says would you like to add another but it doesnt. it stays on the same page.

include("include.php");
        if(!$_POST){
        $display_block="
        <form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">
        <p><strong>First/Last Name:</strong><br/>
        <input type=\"text\" name=\"name\" size=\"20\" maxlength=\"50\">
        <input type=\"text\" last=\"last\" size=\"20\" maxlength=\"50\"></p>

        <p><strong>Class Name:</strong><br/>
        <input type=\"text\" name=\"class_name\" size=\"20\" maxlength=\"50\"></p>

        <p><strong>Class Number:</strong><br/>
        <input type=\"text\" name=\"class_num\" size=\"20\" maxlength=\"25\"></p>

        <p><strong>Professor:</strong><br/>
        <input type=\"text\" name=\"profes\" size=\"20\" maxlength=\"50\"></p>

        <p><strong>Class Name:</strong><br/>
        <input type=\"text\" name=\"class_name2\" size=\"20\" maxlength=\"50\"></p>

        <p><strong>Class Number:</strong><br/>
        <input type=\"text\" name=\"class_num2\" size=\"20\" maxlength=\"25\"></p>

        <p><strong>Professor:</strong><br/>
        <input type=\"text\" name=\"profes2\" size=\"20\" maxlength=\"50\"></p>

        <p><input type=\"submit\" name=\"submit\" value=\"Add Class\"></p>
        </form>";

        }else if($_POST)
        {//add to tables
        if(($_POST["name"]== "") || ($_POST["last"]== "")){
                header("Location: addclass.php");
                exit;
        }

        //connect to the database
        doDB;

        //add to student_name table
 $add_student_sql="INSERT INTO student_name (name, last,class_name,class_num,profes,class_name2,class_num2,profes2)
        VALUES('".$_POST["name"]."','".$_POST["last"]."','".$_POST["class_name"]."','".$_POST["class_num"]."','".$_POST["profes"]."',
                '".$_POST["class_name2"]."','".$_POST["class_num2"]."','".$_POST["profes2"]."' )";
        $add_student_res=mysqli_query($mysqli,$add_student_sql)
                        or die(mysqli_error($mysqli));


        mysqli_close($mysqli);
        $display_block="<p>Your class has been added.
        Would you like to <a href=\"addclass.php\">add another</a>?</p>";
}
?>
<html>
<head>
<title>Add A Class</title>
</head>
<body>
<h1>Add a Class</h1>
<?php echo $display_block;?>
</body>
</html>
Member Avatar for spthorn

ah ok thank you so much! i have another problem with a part that goes to this program. it is suppose to go to another page that says would you like to add another but it doesnt. it stays on the same page.

That's because you added a condition that if both the First and Last name are blank, just go to the original page. This condition is always true because you didn't give the "last" field a name:

<input type=\"text\" name=\"name\" size=\"20\" maxlength=\"50\">
        <input type=\"text\" last=\"last\" size=\"20\" maxlength=\"50\"></p>

That last line should say name=\"last\" .

ah ok thanks! now i get this error Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /home/bfinnegan/public_html/addclass.php on line 46

Warning: mysqli_error() expects parameter 1 to be mysqli, null given in /home/bfinnegan/public_html/addclass.php on line 47

Member Avatar for spthorn

Looks like you're not properly connecting to the database. But I can't very well test that - looks like the db connection code is in your include file.

look the problem is with connectivity only ```try out that

ah ok.. ill look at it and try to fix thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.