mysql - Issue passing form data to php variable. Variable seems empty -


i'm noob @ php/mysql. i've been looking around lot can't figure out what's going wrong. purpose of script: update value of item 1 , item 2 in database of user userid entered in txtuser.

i script working when use "fixed" value near userid in query. however, when try use variable ($player), doesn't work. seems variable empty...

html:

<body>    <form id="form1" action="http://www.something.com/testscript1.php" method="post" enctype="application/x-www-form-urlencoded">      <div>     <button type="submit" id="submit" value="submit" title="save">save</button>     </div>     <div>         <input id="txtuser" name="txtuser" type="text" />         <input id="txtitem1" name="txtitem1" type="text" />         <input id="txtitem2" name="txtitem2" type="text" />     </div>  </form> </body> 

php :

$host = "localhost"; $user = "username"; $password = "password"; $database = "database"; $player = mysqli_real_escape_string($connection,$_post['txtuser']); $connection = mysqli_connect($host,$user,$password,$database) or die ("connection server failed"); mysqli_select_db($connection,$database) or die ("couldn’t select database");  $item1 = mysqli_real_escape_string($connection,$_post['txtitem1']); $item2 = mysqli_real_escape_string($connection,$_post['txtitem2']);  $query = "update table set item1=$item1, item2=$item2 userid=$player"; $result = mysqli_query($connection,$query) or die ("couldn’t execute update query: ".mysqli_error($connection)); echo "<h4>data saved in database</h4>"; mysqli_close($connection);  ?> 

please put line

$player = mysqli_real_escape_string($connection,$_post['txtuser']); 

after $connection

$connection = mysqli_connect($host,$user,$password,$database) or die ("connection server failed"); 

like

$connection = mysqli_connect($host,$user,$password,$database) or die ("connection server failed"); $player = mysqli_real_escape_string($connection,$_post['txtuser']); 

because using $connection variable in mysqli_real_escape_string before initialised


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -