SQL database front end data input form - sql

I have a TSQL database and for the sake of simplicity I created one table called staffrecords with the fields (StaffID, FirstName, Surname, DateofBirth)
I require something where my client can enter data into and will go into the database instantly. So instead of doing insert querys or typing data into the database they can have a front end online application and submit it like that.
Can you guys advise will be the above requirements and point me in the right direction.

I'm not sure what you mean by instantly. As far as I know, the only way to get Data into an SQL Database are the two methods you described above: INSERT statements and typing it into the database directly. If you want to remove a little bit of latency on getting the data into the database on the front end, I would recommend using AJAX in order to add data to the database as the user types it into the front end interface.
E.g.,
User opens the form page: send a message to a server side script telling it to make a new row.
User enters their StaffID: AJAX this information and fill out the appropriate cell in the database using a REPLACE command.
etc., etc.
Obviously, periodically the database will have to scan for empty rows and remove them as these can result from the user visiting the page but not entering any data. A workaround to this could be only creating the row when the first field is filled out.
Hope this helps!

I developed this code to execute a sample to insert the data into the database.
<?php
$servername="localhost";
$username="root";
$password="";
$dbname="demo";
//CREATE CONNECTION
$conn=new mysqli($servername,$username,$password,$dbname);
//CHECK CONNECTION
if ($conn->connect_error)
{
die("connection failed:".$conn->connect_error);
}
//$sql="INSERT INTO student(CATEGORY_NAME) VALUES ('Grapes')";
//isset();
//Die();
if (isset($_POST["add"]))
{
$sql="INSERT INTO category(CATEGORY_ID,CATEGORY_NAME) VALUES ('','".$_POST["CATEGORY_NAME"]."')";
//echo $sql;
//die();
$result=$conn->query($sql);
if ($result===TRUE)
{
echo"NEW RECORD CREATED SUCCESSFULLY";
}
else
{
echo "ERROR:".$sql."<br>".$conn->error;
}
}
$conn->close();
?>
<!DOCTYPE html>
<html>
<head>
<title>CATEGORY</title>
</head>
<body align="center">
<div>
<form action="" method="POST">
<td align="center" bgcolor="lightblue"><b>CATEGORY:</b><input type="value" name="CATEGORY_NAME" WIDTH="1000" value=""/></td>
</br>
</br>
<button type="submit" name="add" value="add">ADD</button>
</form>
</div>
</body>
</html>

Related

How in Sinatra would I check that the term the user has input into a form already exists in your database?

Making a budget app while learning to use Ruby/Sinatra/SQL. Part of it involves letting the user add new vendors that they can assign transactions to. My add transaction and add vendor functions both work, but one thing I'd like to do is be able to throw up an error if the vendor that the user is trying to add - eg 'Amazon' is already in the database, before returning to my index of vendors.
The closest that I've come to getting something working is making the name column of the vendor table UNIQUE. But if I enter a name that's already in existence in the field, I get the "PG::UniqueViolation" error.
Is there a way to tell Sinatra that you don't want this error to flag up, you just want to redirect back to the index of vendors without the repeated value.
My working submission form currently looks like:
<div id="new-transaction">
<form action="/vendors/create" method="POST">
<label for="name">New vendor name:</label>
<input type="text" name="name" id="vendorName" />
<input type="submit" value="Add new vendor" id="btn-new-vendor">
</form>
</div>
Go ahead and use that error as a response to work with in your app. You can add a begin/rescue/end block to your method:
# some code before
begin
DB.add_your_vendor_method
rescue
go_back_to_index
end
show_value_to_user
# some code after
You can make that block error specific, too. There is some nice write up on ruby error handling over at http://rubylearning.com/satishtalim/ruby_exceptions.html

Vue.js if statement with two variables

I need to check if the current user is the author of the question to allow him to see/use the delete question button.
But with my implementation I can´t see the button at all:
<form #submit.prevent="deleteQuestion(question.id)">
<input type="submit" v-if="this.currentUser === question.author" value="Löschen"/>
</form>
I get question.author with a JSON request , currentUser is set during the login.
Thanks for taking the time,
Fierl.
this.currentUser and question.author are not the same objects, even though they might contain the same data. This is why the comparison fails.
Your user objects probably have an id property (or some other primary key). Compare against that instead.
<input type="submit" v-if="this.currentUser.id === question.author.id" value="Löschen"/>

Update certain data in SQL with JSP

i've been learning web programming (JSP and SQL) for the past few days, i need help with certain problem, so i need to show the list of all name of members from my database, add button beside it, and when i click it, i need to update the data in database, which name is exactly the same name besides the button .
I have successfully show the data and button, and i know syntax for updating in SQL, but i have no idea how to validate when i click the button, it updates the data with the same name exactly besides the button. Let's just pretend all name is unique. This is my sample code:
<div id="textArea">
<%
String query = "SELECT * FROM member";
ResultSet rs = st.executeQuery(query);
while(rs.next()){%>
<table>
<tr>
<td><%out.print(rs.getString("Fullname"));%></td>
<td> <input type="button" value="Change Role"/> </td>
</tr>
</table>
<%
}
%>
</div>
Any help is really appreciated. thanks!
You have to write Java code in a JSP Page for updating certain data from JSP.
You can write Java Code inside a scriptlet in a JSP page.
You have to write scriptlet inside <% ...%> tag, Please see sample below:
<%
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test");
Statement st=con.createStatement();
......
%>
Please follow the post below to execute update query directly from JSP:
Jsp sql update query

SocialEngine 4 - Followers/Following status display too long

I have problem at columns Followers/Following which I put on the right side of my website and also on browse members page. The problems are:
1) when user post too long status its not displayed right on firefox
2) in cause of the long text follow/unfollow are displayed someone in the middle of the status
You can see what I mean by the added images.
What I suggest for a fix (but I don't know how to do it :() is this:
just remove status in this boxes (its not really needed to see last user status there)
or
limit the status characters
Also is there a way users can "clear" their status because I think it stays there until new one is posted, which is pretty stupid. Like if you post something which is ralated to something now but makes non sense in the futre and then you dont post new status for like 10 days and someone sees it, it will look stupid.
thats the code
<div class='profile_friends_body'>
<div class='profile_friends_status'>
<span>
<?php echo $this->htmlLink($member->getHref(), $member->getTitle()) ?>
</span>
<?php echo $member->status; ?>
</div>
Thanks in advance and I think fix like that will be helpful to others too.
image2
I managed to remove it from application/modeules/User/widgets/profile-friends-followers/index.tp
also its the same in profile-friends-followers and profile-friends
in the files I found this
<div class='profile_friends_body'>
<div class='profile_friends_status'>
<span>
<?php echo $this->htmlLink($member->getHref(), $member->getTitle()) ?>
</span>
<?php echo $member->status; ?>
</div>
and when you remove status; ?> then statuses are not shown anymore on this widgets, but I wanted just to limit the displayed characters and tried to use substr but couldn't manage to do it at the first time

HTML text input and using the input as a variable in a script(tcl)/sql(sqlite)

I'm very VERY new at this whole web thing. And I'm just very confused in general. Basically, what I want to do is take an input via text using HTML and adding that input to database, table trans. Should be simple but I am lost.
<li>Transaction Number</li>
<li><input type=|text| name=|tnumber| </li> // do i need to use value?
<li>Employee Name</li>
<li><input type=|text| name=|ename| </li>
<li><input type=|SUBMIT| value=|Add|></li>
......
......
sqlite3 db $::env(ROOT)/database.db
db eval {INSERT INTO trans VALUES ($tnumber, $ename)}
db close
They are both in a same file and there are only two fields to the database to keep things simple. What I can see here is that tnumber and ename aren't declared as variables. So how do I do that so that the text input is assigned to respective variables?
You're after the ncgi package (in Tcllib), which you can use to decode the values in the form and extract them into variables. To do this, you'd have a webpage with a form like this:
<form method="POST" action="/cgi-bin/addTransaction.tcl">
<li>Transaction Number: <input type="text" name="tnumber">
<li>Employee Name: <input type="text" name="ename">
<li><input type="submit" value="Add">
</form>
(I'll not go into much more depth with the details of writing a form on a webpage.)
Then, in your program (addTransaction.tcl) you do something like this:
package require ncgi
package require sqlite3
ncgi::parse
set xact [ncgi::value "tnumber"]
set name [ncgi::value "ename"]
sqlite3 db $::env(ROOT)/database.db
db eval {INSERT INTO trans VALUES ($xact, $name)}
db close
Note that I've changed the names of the variables to be different from the ones in the webform. This is to show that they do not need to be the same. A few other things to note are that you can make the transaction number field optional (supply a default via the second optional argument to ncgi::value) and it might also be better to do generation of transaction ids in the database (but that's another separate question; I've focussed in this answer on how to couple from the web into SQLite).
Of more interest is the fact that the above code is free of SQL injection attacks. However, whenever you come to taking the contents of the database and sending it back out to the web, you'll need to be careful again or you'll leave open XSS attacks. That's when the html package (Tcllib again) is useful, since it lets you generate correct hazard-free output with minimal effort. But that's another question...