SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict nueva's Avatar
    Join Date
    Apr 2006
    Location
    Uk, London
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    after I insert an article the Database is still empty

    I have write it a script where I have to submit articles and then the articles will be inserted in the database, but every time when I submitted the database is stil empty, can some one help me here pls.

    here is the code.......

    validation.jsp - page

    Code:
    <&#37;
    	int article_id = 0;
    	String Category_Name = null;
    	String article_title = null;
    	String article_desc = null;
    	String User_ID = null;
    	String Article_text = null;
    	
    	try
    	{
    		article_id = 0;
    		Category_Name  = request.getParameter("Category_Name");
    		article_title = request.getParameter("article_title");
    		article_desc = request.getParameter("article_desc");
    		User_ID = request.getParameter("User_ID");
    		Article_text = request.getParameter("Article_text");
    		
                    System.out.println("lll here ==== "+Category_Name);
    	}
    	catch(Exception e)
    	{
    e.printStackTrace();
    		
    	}
    	
    	// assume invalid
    	boolean paramProd = false;
    	if (article_title != null )
    	{
    		// setvalid
    	   	paramProd = true;
    	}
    submitart.jsp page

    Code:
    <%@ page contentType="text/html; charset=iso-8859-1" language="java"  import="java.sql.*" errorPage="" %>
    <%@ include file ="connection.jsp" %>
    
    <form action="submitaction.jsp" method="post">
    	  <table>     
                        <tr> 
                          <td height="28" valign="top"><table width="456" border="0" cellspacing="0" cellpadding="0"> 
                            <tr> 
                              <td width="124" align="right">Article Title</td> 
                              <td width="26"></td> 
                              <td><input type="text" name="article_title"></td> 
                            </tr> 
                          </table></td> 
                        </tr> 
    					<td height="24" valign="top"><table width="456" border="0" cellspacing="0" cellpadding="0"> 
                            <tr> 
                              <td width="124" align="right">Author Name</td> 
                              <td width="26"></td> 
                              <td><input type="text" name="User_ID"></td> 
                            </tr> 
                          </table></td>
    					  <tr>
    					  <td height="28" valign="top"><table width="456"  border="0" cellspancing="0" cellpadding="0">
    					  <tr>
    					  <td width="120" height="102" align="right" valign="top">Article Description:</td>
    					  <td width="21"></td>
    					         <td width="307">
    							 <textarea name="article_desc" rows="5" cols="30"></textarea></td>
    					 </tr>
    					  </table></td>
    					<tr> 
                          <td height="28" valign="top"><table width="456" border="0" cellspacing="0" cellpadding="0"> 
                            <tr> 
                              <td width="119" align="right" valign="top">Article Text:</td> 
                      <td width="28"></td> 
                              <td width="309">
    							<textarea name="Article_text" rows="10" cols="30"></textarea></td> 
                            </tr> 
                          </table></td> 
    					  <tr> 
                          <td height="28" valign="top"><table width="456" border="0" cellspacing="0" cellpadding="0"> 
                            <tr> 
                              <td width="124" align="right">Select Category:</td> 
                              <td width="26"></td> 
                              <td><select name="Category_Name">
                                      <%
                                        PreparedStatement statement  = con.prepareStatement("select Category_Name from category");
                                        ResultSet  resSet = statement.executeQuery();
                                        while(resSet.next()){
                                            String cat = resSet.getString("Category_Name");
                                            %>
                                            <option value="<%=cat%>"><%=cat%></option>
                                            <%
                                        }
                                      %>
    						  </select>
    						  </td> 
                            </tr> 
                          </table></td> 
                        </tr> 
    					<tr>
    					 <td height="28" valign="top"><table width="456" border="0" cellspacing="0" cellpadding="0">
    					  <tr>
    					   <td width="124" align="right"></td>
    					   <td width="26"></td>
    					   <td><input type="submit" value="Submit Now!"></td>
    					  </tr>
    					 </table></td>
    					</tr>
    					</table>
          </form>
    Code:
    submiataction.jsp page
    
    <%@ page contentType="text/html; charset=iso-8859-1" language="java"  import="java.sql.*" errorPage="" %>
    <%@ include file ="connection.jsp" %>
    <%@ include file ="validate.jsp" %>
    <%
            //Get Category_Name
    		PreparedStatement statement;
    		//insert article when all the fields are fill it up
    		if (paramProd){
    		    
               //insert the new article here
                        try{
    		   statement  = con.prepareStatement("insert into articles (Category_Name, article_title, article_desc, User_ID, Article_text,) values(?,?,?,?,?)");	
    		   statement.setString(1,Category_Name);
               statement.setString(2,article_title);
    		   statement.setString(3,article_desc);
    		   statement.setString(4,User_ID);
    		   statement.setString(5,Article_text);
    		   statement.executeUpdate();
    		   
    }catch(Exception e){
        System.out.println("here i am");
        e.printStackTrace();
    }
    		/** Item Insert it **/
    
    		}
    %>
    
    
    <!-- Display the last article inserted OK -->
    <% if (paramProd){ %>
        <h3>The article was inserted in the database OK</h3>
        
    <%} else { %>
    
    <h3>Please try again</h3>
    
    <%} %>
      <% con.close();%>
      </tr>
    </table>
    <div align="center"><br>
      Design Created By <a href="http://danstuts.com">DansTuts.com
      </a>
      <!-- End ImageReady Slices -->

  2. #2
    SitePoint Addict nueva's Avatar
    Join Date
    Apr 2006
    Location
    Uk, London
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I sort it out now, i know what was the problem, i need to read to code more so i can see it...
    im so glad...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •