Why is the php code in Vue component not working correctly?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-16 12:58:19
0
3
491

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>
曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(3)
仅有的幸福

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.

滿天的星座

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

曾经蜡笔没有小新

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template