I just looked at the code above and found a mistake, and I wrote the gender judgment out of the loop. I apologize to you here, and now I have corrected it in time. Oh, low-level mistakes. But it is a good thing to find mistakes, to sum up the lessons ... Good good, do not find excuses, bow to admit, hehe.
OK, let's start writing edit and delete function. Let's change the show.php page so that it has an operating area and add the edit and delete connections. Let the user to operate, the specific code I posted out first, I have to make the format as far as possible to see, how you can not understand the words, you may compare the above show.php see OH.
input.php File Code: (Updated Version)
copy content to clipboard
Code:
[<a href= "input.php" > continue to add </a>]
<?php
Here is the PHP code
$sql = "SELECT * from ' addr_list '";/SQL statement to execute (here is the browsing Data feature)
Require (' conn.php '); Call conn.php file, perform database operations
?>
<!---here HTML code, create a table--->
<table width= "100%" border= "1" >
<tr>
<th width= "13%" bgcolor= "#CCCCCC" scope= "col" > Name </th>
<th width= "13%" bgcolor= "#CCCCCC" scope= "col" > Sex </th>
<th width= "13%" bgcolor= "#CCCCCC" scope= "col" > Mobile </th>
<th width= "13%" bgcolor= "#CCCCCC" scope= "col" > Mailbox </th>
<th width= "29%" bgcolor= "#CCCCCC" scope= "col" > Address </th>
<th width= "19%" bgcolor= "#CCCCCC" scope= "col" > Operations </th>
</tr>
<?php
Here is the PHP code
Determining gender
while ($row = Mysql_fetch_row ($result))//Loop start
{
if ($row [2]==0)
{
$sex = ' lady ';
}
Else
{
$sex = ' Sir ';
}
?>
<!---a looping HTML table with PHP code--->
<tr>
<td><?php echo $row [1];?></td>
<td><?php Echo $sex; ?></td>
<td><?php echo $row [3];?></td>
<td><?php echo $row [4];?></td>
<td><?php echo $row [5];?></td>
<td><div align= "center" >
[<a href= "edit.php?id=<?php echo $row [0];?>" > Edit </a>]
[<a href= "del.php?id=<?php echo $row [0];?>" > Delete </a>]
</div></td>
</tr>
<?php
}
?>
</table>
Description: Our two links [edit] and [delete] point to the edit.php and del.php pages, now these two pages have not been done, let's first figure out why we write it. We can see it in the form of: edit.php?id=xxx, so what is XXX? Said before, can not forget Oh, $row [0] on behalf of the call ID, we use the PHP statement to write to the link, so it will grow to look like that, hehe. After the conversion, it should be in the address bar to display similar edit.php?id=1 address, this is a way to transfer value, if you want to study, hehe, Google slightly, I do not say more here. OK, so let's see if they actually uploaded the values to edit.php and del.php pages, so let's write these two pages test, remember is testing oh, so not the full version, hehe.
edit.php file code: (incomplete)
Copy Content to Clipboard
Code:
<?php
echo $id;
?>
del.php file code: (incomplete)
Copy Content to Clipboard
Code:
<?php
echo $id;
?>
Description: Two twins look exactly the same, hehe. OK, you can test it, run show.php, point [edit] or [delete], see if the value of $id can show or change, if successful, we can continue.
OK, now we have to formally write edit.php and del.php, if you have already made clear post.php and show.php how to write, then these two are not a problem, much the same, so don't be too nervous. Let's write edit.php first.
edit.php File Code: (full version)
copy content to clipboard
Code:
<?php
$sql = "SELECT * from ' addr_list '
WHERE ' id ' = ' $id '; The SQL statement that needs to be executed (here is the browsing Data feature)
To be aware of the ID Oh, this statement is somewhat different from the show.php
Require (' conn.php '); Call conn.php file, perform database operations
$row = Mysql_fetch_row ($result); Save the result set of the SQL execution statement as an array (queued up)
?>
<!---We can add the Input.php form button to the PHP code, only the sex part to do special treatment--->
<form id= "Form1" Name= "Form1" method= "Post" action= "edited.php" >
<p> Name: <input name= "name" type= "text" id= "name" value= "<?php echo $row [1];?>"/></p> "
<p>
<?php
Special treatment of sex, if it is 0 to select the woman, or the selection of Mr. Checked= "checked" is selected OH
if ($row [2]==0)
{
echo ' Sex: <input type= "Radio" name= "Sex" value= "0" checked= "checked" Ms./>
<input type= "Radio" name= "Sex" "value=" 1 "Mr./>";
}
Else
{
echo ' Sex: <input type= "Radio" name= "Sex" value= "0"/>
<input type= "Radio" name= "Sex" value= "1" checked= "checked", "/>";
}
?>
</p>
<p> Mobile: <input name= "mobi" type= "text" id= "mobi" value= "<?php" Echo $row [3];?> "/></p>"
<p> e-mail: <input name= "Email" type= "text" id= "email" value= "<?php echo $row [4];?>"/></p> "
<p> Address: <input name= "addr" type= "text" id= "addr" value= "<?php echo $row [5];?>"/></p> "
<p>
<input type= "Submit" name= "Submit" value= "Add"/>
<input type= "reset" name= "Submit2" value= "rewrite"/>
</p>
</form>
Description: In fact, is to copy input.php to modify it, oh, here is to pay attention to is the $SQL statement, here is a conditional sentence of SQL, used to identify the ID, there is the sex processing part. Checked= "Checked" indicates that the radio button has been selected, which is a part of the idea. We also have to do a edited.php page to send processing changes to the data, its function is similar to post.php. Oh, we hurry to do it, it is almost finished!
edited.php File Code:
copy content to clipboard
Code:
<?php
SQL statement to execute (here is the Modify Data feature)
$sql = "UPDATE ' addr_list ' SET"
' Name ' = ' $name ',
' Sex ' = ' $sex ',
' mobi ' = ' $mobi ',
' Email ' = ' $email ',
' Addr ' = ' $addr '
WHERE ' addr_list '. ' id ' = 12 ';
Call conn.php file, perform database operations
Require (' conn.php ');
Show action tips, note $result is also conn.php in the OH
if ($result)
{
Echo ' Congratulations, modify success! <p> ';
}
?>
[<a href= "show.php" > View address Book </a>] [<a href= "input.php" > continue to add </a>]
Note: Here is also the $sql SQL statement, I here indent processing, convenient for everyone to see clearly, we write when there is no need to write, hehe. With post.php sorta, so also needless to say slightly, we test it. At last the del.php is left, and the victory is in sight! Oh.
del.php File Code: (full version)
Copy Content to Clipboard
Code:
<?php
//需要执行的SQL语句(这里是删除数据功能)
$sql = "DELETE FROM `addr_list` WHERE `id`='$id'";
//调用conn.php文件,执行数据库操作
require('conn.php');
//显示操作提示,注意$result也是conn.php里的哦
if($result)
{
echo '恭喜,删除成功!<p>';
}
?>
[<a href="show.php">查看通讯录</a>] [<a href="input.php">继续添加</a>]
Description: This is also a mold made out, oh, very simple, that is, $sql SQL DELETE statements a little different, anyway, or suggest you to learn SQL syntax, very useful, because it is widely used.
OK, here, this article is all over. I will not upload the source code to let everyone download slightly, lest some people like me as lazy, oh, this recruit more absolutely, forced to learn people to see, have the benefit.
So, or use the old closing to end it, hehe:
Important note, must see Oh, this is just the simplest, most basic things, just used to learn, can not put into use Oh, or what the problem is not to blame me ah, hehe. If you want to use them, but also to do a lot of improvement, such as the addition of some validation functions, optimize the code and so on, or that sentence: there is no shortage of places, you are welcome to correct, so that everyone laughed at.
Write the most fundamental purpose of this article: hope to give a little help to those in need. I am also self-study of PHP, know that one of the hard, so although they are very vegetables, but also want to know to share, but also hope that everyone can do this: common learning, common progress