Note that there are some explanatory texts on larger screens.

plurals
  1. POVariable that changes from String to Integer after some IF ELSE tests
    text
    copied!<p>I have a problem and i cant find a solution. After a html post i have a variable that correctly assigned as the user select "M" or "F". Im sorry if the source is bad written, it's my first time coding!!</p> <p><strong>HTML:</strong></p> <pre><code>&lt;select style="width:75px;" name="sesso" multiple&gt; &lt;option value="m"&gt;Male&lt;/option&gt; &lt;option value="f"&gt;Female&lt;/option&gt; &lt;/select&gt; </code></pre> <p>Here is a part of the PHP code where I find the problem:</p> <pre><code>$reg_nome = strip_tags($_POST['nome']); $reg_username = strip_tags($_POST['username']); $reg_password = strip_tags($_POST['password']); $reg_passwordck = strip_tags($_POST['passwordck']); $reg_sesso = strip_tags($_POST['sesso']); $reg_data = date("Y-m-d"); $uomo = "m"; $donna = "f"; </code></pre> <p>Here it works. The printed variable <code>$reg_sesso</code> is correct "M" or "F".</p> <pre><code>echo "sesso = $reg_sesso"; $stmt = $mysqli-&gt;prepare("SELECT username FROM users WHERE username= ?"); $stmt-&gt;bind_param('s', $reg_username); $stmt-&gt;execute(); $stmt-&gt;bind_result($query_username); $stmt-&gt;store_result(); $n_row = $stmt-&gt;num_rows; $stmt-&gt;close(); if ($n_row==1) //check if the user exists { echo "L'utente $reg_username è già registrato"; } else { if (preg_match("#.*^(?=.{8,20})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).*$#", $reg_password)) //check if password is ok { if($reg_password==$reg_passwordck) //check if two pass are the same { if($reg_sesso=$uomo||$reg_sesso=$donna) //se è stato inserito M o F { echo " sesso= $reg_sesso "; // Here $reg_sesso is 1 not "M" or "F" $password_sha1=(sha1($reg_password)); $stmt = $mysqli-&gt;prepare("INSERT INTO users (nome,username,password,data,sesso) VALUES (?,?,?,?,?)"); $stmt-&gt;bind_param('sssss', $reg_nome, $reg_username, $password_sha1, $reg_data, $reg_sesso); $stmt-&gt;execute(); $stmt-&gt;close(); movePage(301,"login.php"); exit; </code></pre>
 

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