简体   繁体   中英

How do I assign the value of a textbox to a variable?

How do I assign the value of a textbox to a variable?

Here is my form:

<form id="" method="post" action="photo_upload.php" enctype="multipart/form-data">
<table align="center" cellpadding="0" cellspacing="0" border="0" width="650px">
  <tr>
  <td colspan="7">
  <input type="text" id="albumName" name="albumName" value="jaghamachi"/>  
  </td>
  </tr>
  <tr>
  <td width="50px" align="center"/>
  <td align="center" width="100px">Upload Pics::</td>
  <td align="center" width="50px"/>
  <td align="center" width="200px">
      <input type="file" id="file" name="file"/>
  </td>
  <td align="center" width="50px"/>
  <td align="center" width="100px">
      <input type="submit" name="submit" id="submit" value="submit" class="button" style="width: 100px;" />
  </td>
  <td align="center" width="50px"/>   
  <tr>
  <td height="16px"/>
  </tr>
  </table>
  </form>
<?php
// here i want a code similar to string str = Text1.Text like in .net;
//i want a code smthng like this 
//$value= albumName.value; how to do it?? here albumName is the textbox type in above form
?>

How can it be done, without using javascript or jquery?

You can do it like this:

$albumName = $_POST['albumName'];

Here:

  • $albumName is the variable name containing value of text box named albumName
  • $POST is the form method POST eg <form method="POST"

Note 1: For that to work, it is assumed that you submit the form first.

Note 2: To submit to same page, set action attribute of <form> tag to empty

您唯一可以做的就是发布表单,以及$_POST的值

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM