【发布时间】:2018-07-30 10:46:19
【问题描述】:
对于我正在尝试创建的个人资料页面的所有变量,我有一堆未定义的变量。
我以为我之前已经定义了它们,如下所示。我查看了类似的帖子,但初始化变量似乎也不起作用(如您所见,我尝试使用 $first )。我是 php 的新手,所以任何帮助将不胜感激:)
<?php
include_once 'Header.php';
?>
<?php
$uid = (isset($conn, $_POST['user_uid']) ? $_POST['user_uid'] : '');
$result = mysqli_query($conn, "SELECT * FROM users where user_uid='$uid'");
while($row = mysqli_fetch_array($result))
{
$first= "";
$first = $_POST['first'] ?? '';
$last= mysqli_real_escape_string($conn, $_POST['last']);
$city= mysqli_real_escape_string($conn, $_POST['city']);
$country= mysqli_real_escape_string($conn, $_POST['country']);
}
?>
<?php
include_once 'Footer.php';
?>
<table width="398" border="0" align="center" cellpadding="0">
<tr>
<td height="26" colspan="2">Your Profile Information </td>
<td><div align="right"><a href="index.php">logout</a></div></td>
</tr>
<tr>
<td width="129" rowspan="5"><img src="<?php echo $picture ?>" width="129"
height="129" alt="no image found"/></td>
<td width="82" valign="top"><div align="left">FirstName:</div></td>
<td width="165" valign="top"><?php echo $first ?></td>
</tr>
<tr>
<td valign="top"><div align="left">LastName:</div></td>
<td valign="top"><?php echo $last ?></td>
</tr>
<tr>
<td valign="top"><div align="left">City:</div></td>
<td valign="top"><?php echo $city ?></td>
</tr>
<tr>
<td valign="top"><div align="left">Country:</div></td>
<td valign="top"><?php echo $country ?></td>
</tr>
</table>
<p align="center"><a href="index.php"></a></p>
报名表:
<?php
include_once 'Header.php';
?>
<section class="main-container">
<div class="main-wrapper">
<h2>Sign Up</h2>
<form class="signup-form" action="includes/signup-inc.php" method="POST">
<div class="mainbox">
<div class="btncontainer">
<input id="radbtn1" type="radio" name="type" value="Guide" checked><br>
<label for="radbtn1"><span class="radio">Client</span></label>
</div>
</div>
<div class="mainbox">
<div class="btncontainer">
<input id="radbtn2" type="radio" name="type" value="Trainer"><br>
<label for="radbtn2"><span class="radio">Trainer</span></label>
</div>
</div>
<input type="text" name="first" placeholder="Firstname">
<input type="text" name="last" placeholder="Lastname">
<input type="text" name="email" placeholder="E-mail">
<input type="text" name="uid" placeholder="Username">
<input type="password" name="pwd" placeholder="Password">
<input type="text" name="street" placeholder="Street(not visible)">
<input type="text" name="postcode" placeholder="Postcode(not visible)">
<input type="text" name="city" placeholder="City(not visible)">
<input type="text" name="region" placeholder="Region">
<input type="text" name="country" placeholder="Country">
<input type="text" name="phonenumber" placeholder="Phone number(not
visible)">
<button type="submit" name="submit">Sign Up!</button>
</form>
</div>
</section>
<?php
include_once 'Footer.php';
?>
【问题讨论】:
-
$first = isset($_POST['first'] ) ? $_POST['first'] : ' ';
-
检查是否设置了 $_POST['first']
-
请付出更多努力,尝试以可重现的方式呈现您的问题。现在你所显示的甚至没有有 25行,所以如果你只是引用一条错误消息说“in [...]\my-profile.php on line 25” 仍然留下一些不清楚的东西。请阅读minimal reproducible example。
-
如果您的代码没有进入
while循环,那么$first将不会在以后定义。在假设一切正常之前检查您是否确实找到了匹配项。 -
这是完整的代码吗? $first 在您的代码中没有被调用,请向我们展示您首先调用 $first 的代码。