user1162494
user1162494

Reputation: 43

updating database using jsp

i am creating a website with a database attached using netbeans, and MySQL. I have written a piece of code for information submitted in a form on the website to be entered into the database, however the actual input is not inserted into the database, only '$_POST[username]','$_POST[date]','$_POST[message1]','$_POST[acknowledgment]'... i want these values to be the values the user inputs.

can anyone help me to fix this or suggest anything please

<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%-- 
    Document   : teacher1
    Created on : 07-Mar-2012, 02:36:31
    Author     : 
--%><sql:update var="messages" dataSource="jdbc/noticeboard">
    INSERT INTO messages (username, postedon, message, acknowledgment)
VALUES ('$_POST[username]','$_POST[date]','$_POST[message1]','$_POST[acknowledgment]')
</sql:update>



<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>    <body>
        <h1>Hello World!</h1>

        <h1>Submit your notices below:</h1>

        <form name="messages" action="teacher1messages.jsp" method="POST"     enctype="multipart/form-data">
        <h1>Username:</h1>
        <input type="text" name="username" value="eg.cs09kkk1" />
            <h1>Date of notice:</h1>
            <input type="text" name="date" value="dd/mm/yy" />
            <h1>Notice:</h1>
            <textarea name="message1" rows="4" cols="20">
[Type your notices here]
            </textarea>
            <input type="submit" value="submit" name="submit" />
            <h1>Acknowledgment:</h1>
            <input type="text" name="acknowledgment" value="" />
        </form>


    </body>
</html>

thank you!!!

Upvotes: 0

Views: 2544

Answers (1)

tusar
tusar

Reputation: 3424

$_POST[username] notation is for PHP I guess. Use something like this :

<sql:update var="messages" dataSource="jdbc/noticeboard">
    INSERT INTO messages (username, postedon, message, acknowledgment)
    VALUES ('<%=request.getParameter("username")%>',
        '<%=request.getParameter("date")%>',
        '<%=request.getParameter("message1")%>',
        '<%=request.getParameter("acknowledgment")%>')
</sql:update>

Update :

Try some this also, i'm not sure whether could parse the parameters.

<sql:update var="messages" dataSource="jdbc/noticeboard">
INSERT INTO messages (username, postedon, message, acknowledgment)
VALUES (?,?,?,?)
    <sql:param value='<%=request.getParameter("username")%>'/>
    <sql:param value='<%=request.getParameter("date")%>'/>
    <sql:param value='<%=request.getParameter("message1")%>'/>
    <sql:param value='<%=request.getParameter("acknowledgment")%>'/>
</sql:update>

Upvotes: 1

Related Questions