create a program to change registration details
It – Hardware & Software | Kiana Donar | 2 viewsAdvance setting
The register contents modification program (myphp5.php and myphp5-1php) it draws up.
1. As for the table tab1 which is used in the sample program of this series
Server name — localhost
Database name — workdb
Password — karipass
Because so you explain the fact that it is set as prerequisite, after the XAMPP installing the setting of MySQL which is done please draw up table tab1 in advance in reference.
2. Because it houses the PHP program which is introduced with this article in “C:xampphtdocstest”
Please draw up “the test” folder in advance inside “the C:xampphtdocs” folder.
3. This program uses user defined function.
User defined function please draw up myfunc.php of compilation in advance.
1. The register contents modification program (myphp5.php) it draws up
To copy the below-mentioned contents in text editor, file name as “myphp5.php”
It retains on “the C:xampphtdocstest” inside.
*caution : myphp5.php character code of the file SJIS please save to specify the.
PHPeditor or sakura editor it is convenient to use an editor that specifies the character encoding, such as.
<?php /we define a functionmyfunc.phpread only once require_once(“myfunc.php”); /HTMLoutput statement HTMLthe start of the print(“<HTML>n”); /HTMLoutput statement HEADthe start of the print(“<HEAD>n”); /the character codeSHIFT_JISand the specified print(“<META HTTP-EQUIV=”Content-Type” CONTENT=”text/html; charset=”Shift_JIS”>n”); /HTMLoutput statement TITLEspecified print(“<TITLE>myphp5</TITLE>n”); /HTMLoutput statement HEADthe end of the print(“</HEAD>n”); /HTMLoutput statement BODYthe start of the print(“<BODY>n”); /inpnumcheck for the presence of the input to the field if (strlen($HTTP_POST_VARS["inpnum"]) == 0) { /HTMLoutput statement registration confirmation print(“<B>registration change</B><BR><BR>”); /HTMLoutput statement FORMthe start of the print(“<FORM action=myphp5.php method=post>”); /HTMLoutput statement description of the input field print(“of data you want to changenumberplease enter the<BR><BR>”); /HTMLoutput statement specified in the input field print(“<INPUT type=text name=inpnum size=8 maxlengh=8><BR><BR>”); /HTMLoutput statement change button print(“<INPUT type=submit value=change>”); /HTMLoutput statement cancel button print(“<INPUT type=reset value=cancel><BR>”); /HTMLoutput statement FORMthe end of the print(“</FORM>”); } else { /myphp5.phpthe data entered into the input format frompostit passed in /$HTTP_POST_VARSfield by inpnum retrieves the contents of the $safetextstored in the $safetext = $HTTP_POST_VARS["inpnum"]; /chkcharby the function$safetextto remove the invalid characters in the chkchar($safetext); /$keystore the result of the removal of illegal characters $key = $safetext; /numberwhether the numerical value of the field is_numeric checked by function if (is_numeric($key)) { /numberthe value of the field in the range (0or more n/a below) to check whether if ($key >= 0 and $key <= n/a { } else { /numberif the value of a field is out of range to display an error message echo “numberis0from n/a please specify a number between<BR><BR>”; /HTMLoutput statement javascriptlink back to the previous page using the echo “<A HREF=’myphp5.php’ onClick=’history.back();return false;’>go back</A><BR>”; /interrupting the processing of the later exit; } } else { /numberif the value of a field is non-numeric display an error message echo “numberplease specify the number<BR><BR>”; /HTMLoutput statement javascriptlink back to the previous page using the echo “<A HREF=’myphp5.php’ onClick=’history.back();return false;’>go back</A><BR>”; /interrupting the processing of the later exit; } /DBconnection is initiated to server name–localhost user name–root password–karipass $dbHandle = mysql_connect(“localhost”,”root”,”karipass”) or die(“can not connect dbn”); /MySQLthe character code of the clientsjisset to mysql_query(“SET NAMES sjis”) or die(“can not SET NAMES sjis”); /dbname workdb $db = “workdb”; /SQLsentence tab1from the tablenumberextract the line equal to the value of a column value has been entered in the input field $sql = “select * from tab1 where number = ‘$key’”; /SQLto execute a statement $rs = mysql_db_query($db,$sql); /mysql_num_rows to get the number of rows using the function $rows = mysql_num_rows($rs); /to get the number of columns $fields = mysql_num_fields($rs); /to obtain the line $row=mysql_fetch_array($rs); /was enterednumberif there is a row of data to output if ($rows > 0) { /HTMLoutput statement heading output print(“<B>change registration details</B><BR><BR>”); /HTMLoutput statement description of buttons output print(“after you enter the item you want to change, please press the change button. <BR>”); /HTMLoutput statement FORMspecifies the start of print(“<FORM action=myphp5-1.php method=post>”); /HTMLoutput statement specifies the start of a table print(“<TABLE border=1>”); /HTMLoutput statement specify the head of the table print(“</TR><TH>column name</TH><TH>before the change</TH><TH>after the change</TH></TR>”); /testrepeated as many times as the number of columns in the table for ($i=0;$i<$fields;$i++){ /HTMLoutput statement the column name <TD>enclosed in output print(“</TR><TD><B>”.mysql_field_name($rs,$i).”</B></TD><TD>”. $row[$i].”</TD>”); /HTMLoutput statement numberoutput the contents of the column can not be changed typeishiddeninnumberpass the contents of the column if ($i == 0) { print(“<TD><INPUT type=hidden name=’”. mysql_field_name($rs,$i). “‘value=’”. $row[$i]. “‘</TD>”); } /HTMLoutput statement nameoutput the contents of the column input field for changing the output if ($i == 1) { print(“<TD><INPUT type=text name=’”. mysql_field_name($rs,$i). “‘ length=40 maxlength=40 value=’”. $row[$i]. “‘ </TD>”); } /HTMLoutput statement noteoutput the contents of the column input field for changing the output if ($i == 2) { print(“<TD><INPUT type=text name=’”. mysql_field_name($rs,$i). “‘ length=60 maxlength=60 value=’”. $row[$i]. “‘ </TD>”); } print(“</TR>”); } /HTMLoutput statement specifies the end of the table print(“</TABLE><BR>”); /HTMLoutput statement specify the change button print(“<INPUT type=submit value=change>”); /HTMLoutput statement specify a cancel button print(“<INPUT type=reset value=cancel><BR>”); /HTMLoutput statement FORMspecifies the end of print(“</FORM>”); } else { /was enterednumberif the line does not exist it prints an error message print(“numberis [".$key. "] data is not registered<BR>”); } /unloaded from memory a record result mysql_free_result($rs); /DBdisconnect the connection to the mysql_close($dbHandle); } /HTMLoutput statement javascriptlink back to the previous page using the print (“<BR><A HREF=javascript:history.back()>go back</A><BR>”); /HTMLoutput statement BODYthe end of the print(“</BODY>n”); /HTMLoutput statement HTMLthe end of the print(“</HTML>n”); ?> <BR> <A HREF=”myphp.php”>menu</A><BR> subsequently, on the next page myphp5-1php to create a.
2.1 program change registration details(myphp5-1.php)create a
copy the text editor the contents of the following, the name of the file myphp5-1.php as
C:xampphtdocstest and save it in the.
*caution : myphp5-1.php character code of the file SJIS please save to specify the.
PHPeditor or sakura editor it is convenient to use an editor that specifies the character encoding, such as.
<? require_once to which just one time reads myfunc.php which defines php / function (“myfunc.php”); /HTML sentence start print of output HTML (“<HTML> n “); /HTML sentence start print of output HEAD (“<HEAD> n “); / character code SHIFT_JIS and appointment print (“<META HTTP-EQUIV= “Content-Type ” CONTENT= “text/html; charset= “Shift_JIS “> n “); /HTML sentence appointment print of output TITLE (“<TITLE> myphp5-1< /TITLE> n “); /HTML sentence end print of output HEAD (“</HEAD> n “); /HTML sentence start print of output BODY (“<BODY> n “); /myphp5.phpthe data entered into the input format frompostit passed in /$HTTP_POST_VARSfield by number retrieves the contents of the $safetextstored in the $safetext = $HTTP_POST_VARS["number"]; /chkcharby the function$safetextto remove the invalid characters in the chkchar($safetext); /$keystore the result of the removal of illegal characters $key = $safetext; /myphp5.phpthe data entered into the input format frompostit passed in /$HTTP_POST_VARSfield by name retrieves the contents of the $safetextstored in the $safetext = $HTTP_POST_VARS["name"]; /chkcharby the function$safetextto remove the invalid characters in the chkchar($safetext); /$keystore the result of the removal of illegal characters $name = $safetext; /myphp5.phpthe data entered into the input format frompostit passed in /$HTTP_POST_VARSfield by noteretrieves the contents of the $safetextstored in the $safetext = $HTTP_POST_VARS["note"]; /chkcharby the function$safetextto remove the invalid characters in the chkchar($safetext); /$keystore the result of the removal of illegal characters $note = $safetext; /nameinput characters are out of range if the field is to display an error message if (strlen($name) < 6 or strlen($name) > 40){ echo “namein case of half-width6characters or more40characters, if the full-width3characters or more20please enter the number of characters in the characters<BR><BR>”; echo “<A HREF=’myphp5.php’ onClick=’history.back();return false;’>go back</A><BR>”; exit; } /DBconnection is initiated to server name–localhost user name–root password–karipass $dbHandle = mysql_connect(“localhost”,”root”,”karipass”) or die(“can not connect dbn”); /MySQLthe character code of the clientsjisset to mysql_query(“SET NAMES sjis”) or die(“can not SET NAMES sjis”); /dbname workdb $db = “workdb”; /SQLsentence tab1from the tablenumberextract the line equal to the value of the column value is entered in the input field /and update $sql = “update tab1 set name=’$name’,note=’$note’ where number=’$key’”; /SQLto execute a statement $rs = mysql_db_query($db,$sql); /SQLsentence tab1from the tablenumberextract the line equal to the value of the column value is entered in the input field $sql = “select * from tab1 where number = ‘$key’”; /SQLto execute a statement $rs = mysql_db_query($db,$sql); /mysql_num_fields gets the number of columns to use the function $fields = mysql_num_fields($rs); /mysql_num_rows to get the number of rows using the function $rows = mysql_num_rows($rs); /check result output print(“has been changed as follows:<BR>”); /HTMLoutput statement TABLEspecifies the start of print(“<TABLE border=1>”); /testrepeated as many times as the number of columns in the table for ($i=0;$i<$fields;$i++){ /HTMLoutput statement the column name <TD>output in bold enclose it in print(“<TD><B>”.mysql_field_name($rs,$i).”</B></TD>”); } /to obtain the line $row=mysql_fetch_array($rs); /HTMLoutput statement the start of the line of the table<TR> the output print(“<TR>”); /testrepeated as many times as the number of columns in the table for($j=0;$j<$fields;$j++){ /HTMLoutput statement the contents of the column </TD>enclosed in output print(“<TD>”.$row[$j].”</TD>”); } /HTMLoutput statement new line of table</TR> the output print(“</TR></TABLE>”); /HTMLoutput statement TABLEspecifies the end of print(“</TR></TABLE>”); /HTMLoutput statement javascriptlink back to the previous page using the print (“<BR><A HREF=myphp5.php>go back</A><BR>”); /DBdisconnect the connection to the mysql_close($dbHandle); /HTMLoutput statement BODYthe end of the print(“</BODY>n”); /HTMLoutput statement HTMLthe end of the print(“</HTML>n”); ?> test the program change registration details on the next page.
3 change program registration(myphp5.php,myphp5-1.php)test of
program changestab1of data you want to change the tablenumberspecified
appropriatenumberto modify the data in.
flow of the program is as follows:.
1.registration change form (myphp5.php) to display the, you want to changenumberreceive the value of the.
2. was entered in the registration change formnumberif the data there is a change registered contents to display the form.
3. change program registration data(myphp5-1.php) is, received from the registration change form contentnumberdata
a test table tab1 if you want to exist in the change form was received from the registration data
name, noteafter checking each value of, test table if there is no error tab1 to update the relevant data.
start the browser, in the address field
http://localhost/test/myphp.php
type, press the enter key.
menu screen will appear for the test program,
list after reviewing the data before the change is, change select the.
we list the data before the change.
of data you want to changenumberenter the.
data before the change is displayed.
enter the data after the change, change press the button.
data has been changed.
list we list the data after the change is.
numberis 1 that the data has been changed can be confirmed.
if the display does not change, please try pressing the refresh button on your browser.
it is not registerednumberif you try to change the data will result in an error.
Additional items from "It – Hardware & Software"
- Lenovo ThinkPad X60
- BOSE SoundDock review! take advantage of more! iPod mini
- pcDtrying to take advantage of the drive
- PHP5installing and configuring
- 10less than ten thousand yen good find the! KDL-16M1
- to reduce the size of the image material3one+αmethod of let’s reduce the image
- 2the title of the line1line fit to2ways
- world firstSideShowequipped withASUS W5Fe
- with easy installation, good sound easy to enjoy YHT-S401
- Office Spesialist Word, ExcelofExpertfull marks! her senior2reason for the perfect score for both subjects