search

Home  >  Q&A  >  body text

Why is the php code in Vue component not working correctly?

I just want to simply use vue to connect to the database
I tried many methods but it still doesn’t work. I want to integrate the php code into the component
But it is not parsed as I thought
Image description

This is the code of the component. I just want to ask how to connect to the database. Is this wrong? . Urgent..

<template>
  <p class="see">
    <table border="1">
    <tr>
        <td>id</td>
        <td>name</td>
        <td>number</td>
        <td>eamil</td>
        <td>sex</td>
        <td>hobby</td>
        <td>education</td>
        <td>message</td>
    </tr>
    <?php 
    $link = mysqli_connect("localhost","root","") or die(mysqli_error());
    mysqli_select_db($link, "lydb");
    $result = mysqli_query($link, "select * from ly") or die(mysqli_error());
    while ($row = mysqli_fetch_array($result))
     {
     ?>
    <tr>
        <td><?php echo $row['id'];?></td>
        <td><?php echo $row['name'];?></td>
        <td><?php echo $row['number'];?></td>
        <td><?php echo $row['telephone'];?></td>
        <td><?php echo $row['eamil'];?></td>
        <td><?php $hobby=$row['hobby'];echo $hobby;?></td>
        <td><?php echo $row['education'];?></td>
        <td><?php echo $row['message'];?></td>
    <?php
    }?>
    </tr>    
    </table>
  </p>
</template>
曾经蜡笔没有小新曾经蜡笔没有小新2757 days ago483

reply all(3)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-16 13:00:19

    The poster is really talented. This is a matter of common sense, okay~~~

    The reason is very simple. PHP does not listen to the port of the vue environment you are running, and it cannot listen because the port is being occupied by node. Therefore, the PHP code cannot be parsed. The PHP code you wrote is just a piece of text for node. That’s all.

    If you want vue to obtain the content in the database through php, it is recommended to take a look at RESETful Api

    Also, refresh yourself on basic knowledge.

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-16 13:00:19

    The poster is really a talented person. This is a matter of common sense~~~
    How can js and browser directly execute PHP code? PHP needs to be processed by the WEB server PHP interpreter

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 13:00:19

    The poster is really talented. This is a matter of common sense, okay~~~

    reply
    0
  • Cancelreply