syntax error on jsp update validation code - sql-update

After feeling the update database table form and submitting it I get this error:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?, user_surname=?, email=?, phone_number=?, password=?, confirm_password=? wh...' at line 1. I am using JSP on Apache Netbeans 12.6, Here is my whole validation code.
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#page import="java.sql.*,java.util.*" %>
<% Class.forName("com.mysql.cj.jdbc.Driver"); %>
<%
String user_role=request.getParameter("user_role");
String user_name=request.getParameter("user_name");
String user_surname=request.getParameter("user_surname");
String email=request.getParameter("email");
String phone_number=request.getParameter("phone_number");
String password=request.getParameter("password");
String confirm_password=request.getParameter("confirm_password");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/simsdb","root","");
Statement st=con.createStatement();
int i=st.executeUpdate("update users set user_role=?, user_surname=?, email=?, phone_number=?, password=?, confirm_password=? where user_name=?");
out.println("Updated");
out.print("<br><button type=\"button\">User Management</button>");
%>
I have tried many update validation codes but they just don't update anything at all. As for this code it worked on Delete and Insert so I believe it should work on update also.

Related

Getting same style in another page when click to login

I am having a login page for user generated by devise gem.where I removed the registerable from model for only login not for signup.I have also generated an admin which gives default login credentials for user in seed.rb file.I have done some css work in login page. next I have generated an employee page for further process for users.
Here my doubt is the styling part what I have done in login page is also coming in employee page. I dont want that so I wrote some condition in application.html.erb
<% unless user_signed_in? %>
<%= render 'layouts/heading' %>
<% end %>
The method is defined in application.controller.rb
def user_signed_in? %>
render :layouts => 'application'
end
I tried a lot by changing conditions but it is still displaying or showing errors.
You said that you're using "device gem", but since you're talking about authentication, I assume you mean "devise"?
The user_signed_in? method is a helper which should be provided automatically by devise, and you should be able to use it in your views. You shouldn't need to define it in the application controller.
You probably want to make sure you do "before_filter :authenticate_user!" in the relevant controller (you can use the ":only" option if you only want this to apply for certain methods).
It's difficult to give any more information because you haven't said what errors you are getting. I assume you're getting some kind of syntax error on the definition of the "user_signed_in?" method, since you have an invalid "%>"on the end of the line, which I guess you copied-and-pasted from an ERB file.

Can't get sabisu gem to render - shows no input found for inet error

so i'm working through the api on rails tutorial - http://apionrails.icalialabs.com/book - and i keep getting the error 'no input found for inet' in my error window.
the error highlights this block of code as where the issue is occuring:
<div class="appeareable">
<% #explorer.resource_columns.each do |column| %>
<%= f.input column, input_html: {name: "#{#explorer.resource_name}[#{column}]" }, as: #explorer.column_type(column), required: #explorer.required_attribute?(column) %>
<% end %>
</div>
I tried locking out the compass and simple_form gems, but there are dependencies that start to fall apart using rails 4.1.4 and ruby 2.1.5.
it looks like simple_form is trying to render a resource named 'inet', but i can't find that anywhere in the gem code or even referenced anywhere on google.
It turns out that simple_form has a problem handling the 'inet' datatype now included in rails 4 by default for postgres - https://blog.engineyard.com/2013/new-in-rails-4 (ctrl-f for inet).
IPs used to be string datatype (varchar 255 in postgres) and so converting the db to string for the 2 IP fields in the user table (current_sign_in_ip and last_sign_in_ip) resolves this issue.
I would imagine simple_form will be updating to handle this new datatype at somepoint...though I didn't see any mention of it in their issue logs.
I did this by adding a new migration:
rails g migration change_ip_columns_in_users_table
Then I edited the migration file:
class ChangeIpColumnsInUsersTable < ActiveRecord::Migration
def change
change_column :users, :current_sign_in_ip, :string
change_column :users, :last_sign_in_ip, :string
end
end
The migration solved the problem.

url_for in an email sent by a rake task in rails 4

I have a rake task that sends out daily digest emails of player activity during a day. (See example code below.) If I run PlayerActivityMailer.activity_report.deliver in my console, everything works just fine. However, when I try to invoke the rake task, I get the following error:
rake aborted!
ActionView::Template::Error: arguments passed to url_for can't be handled.
Please require routes or provide your own implementation
After doing some research, I found that in Rails 4, they totally nerfed ActionView::Helpers::UrlHelper.url_for (http://apidock.com/rails/v4.1.8/ActionView/Helpers/UrlHelper/url_for - notice the giant red minus sign under the 4.0.2). If you look at the source, you can see the error I'm seeing - it no longer takes options. As far as I can tell, that functionality still exists in other url_fors, such as the one in ActionDispatch::Routing::UrlFor. Also, the error message suggests including Rails.application.routes.url_helpers.
What I've tried
include ActionDispatch::Routing::UrlFor in both the rake task (inside the task) and the mailer (both at the same time, and each separately)
include Rails.application.routes.url_helpers in the same places and configurations, both with and without the UrlFor include.
The error still persists. My guess is that the page view is still insisting on using the ActionView::Helpers::UrlHelper version of url_for. I don't think I can include things actually in the views (which is sloppy looking and hacky even if I could).
Example Code
(heavily sanitized)
config/environtments/development.rb:
config.action_mailer.default_url_options = { host: 'localhost:3000' }
lib/tasks/player.rake:
namespace :player do
task :activity => :environment do
PlayerActivityMailer.activity_report.deliver
end
end
app/mailers/player_activity_mailer.rb:
class PlayerActivityMailer < ActionMailer::Base
def activity_report
#activities = PlayerActivity.all
mail(to: 'foo#bar.com', subject: 'activity report')
end
end
app/views/player_activity_mailer/activity_report.html.erb:
<% #activites.each do |activity| %>
Player: <%= link_to activity.player.name, player_url(id: activity.player.id) %>
...
<% end %>
I also have a model Player, resources :players in my routes.rb file, and a PlayerActivity class with an association to Player.
I'm currently using the (really horrifying) workaround of #base_url = Rails.configuration.action_mailer.default_url_options[:host] in my mailer action and "http://#{#base_url}/players/#{activity.player.id}" in my view instead of the player_url part.
Help!
Have you tried passing just your player in the URL? Like this:
<% #activites.each do |activity| %>
Player: <%= link_to activity.player.name, player_url(activity.player) %>
<% end %>

How to display a youtube embed link that is called from database

I have an application I want to use for my teaching studio where I create lessons that students can view. the lessons are specific to each student so they are linked via a :user_id (user has_many lessons, lesson belongs_to user). I can bring up specific lessons based on which user it is but the one part I cannot figure out is how to get a video (youtube) link to display correctly. What I want is to save the link along with the text for the lesson. The text and title and all that comes up fine right now, but the video will not display with embed code and throws a routing error in the iframe window.
Here is my code for the _lesson partial. "video_url" is the name of the column in the database.
_lesson.html.erb
<li>
<span class="content">
<%= lesson.title %><br />
<%= lesson.lesson_notes %>
<iframe width="490" height="275" src="<%= lesson.video_url %>" frameborder="0" allowfullscreen></iframe>
</span>
</li>
this is the code in my show view.
show.html.erb
<% if #user.lessons.any? %>
<h3> Lessons (<%= #user.lessons.count %>)</h3>
<ol class="lessons">
<%= render #lessons %>
</ol>
<%= will_paginate #lessons %>
<% end %>
the error I get is below
No route matches [GET] "/users/www.youtube.com/embed/CFF0mV24WCY"
I kind of understand what is happening, but not really. I guess I am unsure why it is looking for that route instead of just embedding the code and then displaying the video. It brings up all the other text and stuff from the lesson so that is working fine. Is there not an easy way just to display the link so it embeds the video along with it? I have searched quite a bit but everything I find just deals with embedding the code into the html which I can do, but this needs to change based on the user so has to be pulled out of the database along with the rest of the lesson info. Any help would be greatly appreciated.
src needs to know the protocol, so if you don't include http://, the explorer assumes that the given src is next to your actual path.
A shitty solution could be add the protocol with a raw string:
src="http://<%= lesson.video_url %>"
But a way better solution is adding a filter to check if the protocol is included when you save the field.

Routing Error, receive [Get] instead of [DELETE]

I'm trying to make a link to destroy an row in a table but the problem is that I receive [GET] instead of [DELETE].
Here the error:
No route matches [GET] "/clubs/1/club_accounting/2"
My route is :
club_club_accounting_delete_path
DELETE
/clubs/:club_id/club_accounting/:id(.:format)
club_accounting#delete
My link :
<%= link_to 'Supprimer', club_club_accounting_delete_path(:id => activity.id), method: :delete %>
Any idea ?
The method: :delete option in the link_to helper adds the attribute data-method="delete" to the resultant <a> tag. This is then handled by the jquery_ujs javascript file. Make sure it's included correctly and that it shows up in your page source. If it's there, open the javascript console in your browser's developer tools to see if there's any javascript errors when you click on the link.
Other than that, your posted code looks in order.
Minor style suggestion though: you don't need to pass :id => activity.id to the path helper, just use: club_club_accounting_delete_path(activity).
If you encounter any error messages, post them back in your answer.