i have some problem here with Edit Data Using ASP.NET Razor in WebMatrix
i write this code for edit a data using the Update command but unfortunately it doesnt work :s :s
Razor code :
@{
{
var userId = Request["UserId"];
var db = Database.Open("intranet");
var query = "UPDATE Personne SET Demande = @0 WHERE UserId LIKE '%@1%'";
db.Execute(query,"refuser", userId);
}
}
the html code :
<form action="responsable.cshtml" method="post">
<input type="hidden" name="UserId" value="saadwafqui" />
<input type="submit" value="Oui" />
</form>
Your code is vulnerable to SQL injection. I would recommend you fixing this. Also you seem to be using some
IsPostvariable which is not quite clear where is being defined.Example:
Notice the syntax around the LIKE clause:
This will match all records that have
UserIdin the middle. If you wanted to match only records that the UserId starts with the value in the request:and if you wanted exact match simply use the
=operator instead of a LIKE clause.Also your markup looks completely broken. There’s no
window.locationattribute. Maybe you meant something like this:or with a GET request if you prefer: