HTML发布php变量以形成附加数据

时间:2022-10-16 12:29:54

I am setting up a users-only page, where the users can access a database. I require the form they use to add things to the database to grab their name from the users database, which was accessed earlier in the document to verify their account, and place it in a column labeled Added By for that new row.

我正在设置一个仅用户页面,用户可以在其中访问数据库。我需要他们用来向数据库添加内容的表单,以便从用户数据库中获取他们的名字,用户数据库在文档中先前被访问以验证他们的帐户,并将其放在标记为新增行的添加的列中。

So, I'm using the following code <script> $(document).ready(function() { $.post("insert.php",{"name":"Keegan"});}); </script> Which works well for putting my name through, but i can't figure out how to get the variable out of the above php tags.

所以,我使用以下代码

1 个解决方案

#1


1  

You can try this:

你可以试试这个:

<script>
  var r = <?php echo $thename; ?>;
</script>

or this:

或这个:

 <?php
    echo '<script>var r = ' . $thename . ';</script>';
  ?>

#1


1  

You can try this:

你可以试试这个:

<script>
  var r = <?php echo $thename; ?>;
</script>

or this:

或这个:

 <?php
    echo '<script>var r = ' . $thename . ';</script>';
  ?>