喜IAM試圖獲取從數據庫中的記錄後更新查詢,並需要在數據庫中,但如果IAM試圖讓錯誤,更新查詢,如下喜IAM試圖點擊編輯按鈕,在PHP MySQL的
注意:未定義的變量:導致C:\ xampp \ htdocs \ index \ index.php在第57行 警告:mysql_num_rows()期望參數1爲資源,null爲C:\ xampp \ htdocs \ index \ index.php中給出的行57
這裏是我的代碼:
的index.php
<?php
session_start();
?>
<title> Dashboard </title>
</head>
<?php
$username = $_SESSION['username'];
if($username)
{
?>
<h3> Welcome <?php echo $username; ?></h3>
<?php
}
else
{
echo "no";
}
?>
<body>
<form method="post" action="personalinfo.php" id="myform">
<input type='hidden' value="<?php echo $username; ?>" name='email'>
<div class="box-body table-responsive no-padding">
<table class="table table-hover">
<tr>
<th>ID</th>
<th>Name</th>
</tr>
<tr>
<?php
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_array($result)) {
?>
<td><?php echo $row['first_name']; ?></td>
</tr>
<?php
}
}
?>
</table>
</div>
<input type="button" value="Logout" id="logout" onClick="document.location.href='login.php'" />
</form>
</body>
Personalinfo.php
<?php
$connection = mysql_connect("localhost", "root", "") or die(mysql_error());
$db = mysql_select_db("accountant", $connection);
$email=$_POST['email'];
$firstname = $_POST['first_name'];
$res = "SELECT * FROM registered WHERE email ='$email' ";
$result=mysql_query($res);//this is for comparing ids
$res1 = "SELECT first_name FROM registered WHERE email ='$email' ";
$result=mysql_query($res1);//this is for getting first_name from database table
$query = mysql_query("UPDATE registered SET first_name='$firstname' WHERE email= '$email'");
// mysql_query("$query") OR die("Error:".mysql_error());
if($query)
{
echo "Successfully Registered";
}
else{
echo "Registration has not been completed.Please try again";
}
誰能幫我關於提前this.Thanks
[PHP:「通知:未定義變量」和「通知:未定義指數」]的可能的複製( http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – Epodax
錯誤似乎有點清楚...順便說一句,停止使用mysql_ *功能,並開始使用準備聲明使用PDO或mysqli_ * – Naruto
但我的查詢中有什麼問題,我已經完成我知道mysqli是最新的,但我應該知道我做錯了 – user5751258