Note that there are some explanatory texts on larger screens.

plurals
  1. POexist db user registration with xquery
    primarykey
    data
    text
    <p>I'm trying to create a user registration form and create collection upon registration. I tried following code, but when i try to execute i get this error: <strong>HTTP 400 Bad Request</strong> and page cannot be displayed. Here is the code:</p> <pre><code>xquery version "1.0"; declare namespace request="http://exist-db.org/xquery/request"; declare namespace response="http://exist-db.org/xquery/response"; declare namespace xdb="http://exist-db.org/xquery/xmldb"; declare option exist:serialize "method=xhtml media-type=text/html indent=yes"; declare variable $database-uri as xs:string { "xmldb:exist:///db" }; declare variable $redirect-uri as xs:anyURI { xs:anyURI("login.xql") }; declare function local:header() as node(){ &lt;div style="background-color:#b0c4de; padding: 20px; border: 1px solid black;"&gt; &lt;h1&gt;test&lt;/h1&gt; &lt;/div&gt; }; declare function local:footer() as node(){ &lt;div style="background color:#eee; height: 1%; padding:20px; border: 1px solid black;"&gt; &lt;p&gt;PROJECT&lt;/p&gt; &lt;/div&gt; }; declare function local:reg($user as xs: string) as element()? { let $password := request:get-parameter("password", "") let $password2 := request:get-parameter("password2", "") return if (not(xdb:exists-user($user))) then ( xdb:create-collection($database-uri, $user), xdb:create-user($user, $password, "guest", ()), response:redirect-to($redirect-uri) ) else &lt;p&gt;User already exists!&lt;/p&gt; }; declare function local:do-reg() as element()? { let $user := request:get-parameter("user", ()) return &lt;p&gt;{$user}&lt;/p&gt; if($user) then local:reg($user) else () }; &lt;html&gt; &lt;head&gt;&lt;title&gt;Registration&lt;/title&gt; &lt;/head&gt; &lt;body&gt; {local:header()} &lt;h1&gt;Forma for reg&lt;/h1&gt; &lt;form action="{request:get-uri()}"&gt; User Name: &lt;br /&gt; &lt;input type="text" name="user" size="20" /&gt; &lt;br /&gt; Password: &lt;br /&gt; &lt;input type="password" name="password" size="20" /&gt; &lt;br /&gt; Confirm: &lt;br /&gt; &lt;input type="password" name="password2" size="20" /&gt; &lt;br /&gt; &lt;input type="submit" /&gt; &lt;input type="reset" name="reset" value="Clear" /&gt; &lt;/form&gt; {local:do-reg()} {local:footer()} &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Please help, i'm beginner in xquery and exist db. Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload