By studying, I am making a customer search system with PHP and HTML.
The customer search system is a system in which when you enter a customer name and customer number and press the search button, the data (customer phone number, customer address) that matches the input contents is retrieved from the database and automatically entered.
If either or both of the customer name and customer number have not been entered, I would like to be able to output the message "Please enter."
Also, if there is no applicable data, I would like to be able to output a back button with the message "There is no applicable data. Please re-enter."
I get an error message, and even if I correct it, I get the same error message.
What kind of program should be created to create the ideal system?
(You can ignore menu.php.)
Warning: Undefined array key "pkey" in C: \ xampp \ htdocs \ customer \ c_search.php on line 2
Fatal error: Uncaught Error: Call to undefined function mysql_connect () in C: \ xampp \ htdocs \ customer \ c_search.php: 4 Stack trace: # 0 {main} thrown in C: \ xampp \ htdocs \ customer \ c_search.php on line 4
Corresponding source code
<? php
$pkey = trim ($_REQUEST ['pkey']);
$db = mysql_connect ('localhost','user','pass');
$rc = mysql_select_db ('example');
$result = mysql_query ("select * from example");
$result = mysql_query ($query);
if (! $result) {
$message ='Invalid query:'. mysql_error (). "\ n";
$message. ='Whole query:'. $Query;
die ($message);
}
while ($row = mysql_fetch_assoc ($result)) {
echo $row ['C_name'];
echo $row ['C_num'];
echo $row ['C_phon'];
echo $row ['C_sa'];
}
mysql_free_result ($result);
?>
<! DOCTYPE html PUBLIC "-// W3C // DTD XHTML 1.0 Transitional // EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml" xml: lang = "ja" lang = "ja">
<head>
<meta charset = "UTF-8">
<meta name = "viewport" content = "width = device-width">
<title>Customer search</title>
<link rel = "stylesheet" href = "ser_style.css">
</head>
<body>
Customer search
<label for = "C_name">Customer name<span>Required</span></label>
<input type = "text" name = "C_name">
<label for = "C_num">Customer number<span>Required</span></label>
<input type = "number" name = "C_num">
<label for = "C_phon">Customer Phone Number</label>
<input type = "tel" name = "C_phon">
<label for = "C_sa">Customer Address</label>
<input type = "text" name = "C_sa">
<button type = "submit">Search</button>
<form action = "menu.php" method = "GET">
<button type = "submit">Go to menu</button>
</form>
</body>
</html>
What I tried
・ I tried to get an error message, but it doesn't work.
・ I wrote a PHP statement in my own way
The software used is xammp, the file name is C_search.php and the CSS file is ser_style.css.
-
Answer # 1
-
Answer # 2
mysql_connect ()
Is an obsolete function and cannot be used.
Strictly speaking, it's a function that you can use if you have an older version of PhP installed, but you shouldn't even use it.If it is listed in any teaching material, it is too old to be used, so it is strongly recommended to change to a new teaching material.
-
Answer # 3
mysql_connect ()
Is a function that has been deprecated long ago. Not available in recent versions of php.
Perhaps the textbook I'm referring to is old, so it's a good idea to change it to a textbook that supports at least php 7 or later.
Related articles
- php - at the time of narrowing down search: i want to make a conditional branch when checking only parent terms or checking both
- php - when making a subscription with ec-cube, i would like to add a function that automatically places orders on behalf of cust
- php - in wordpress 1 i want to display only fixed pages and 2 search results excluding specific categories
- php - how to get data when making an app that summarizes purchase history
- php vending machine system: i want to eliminate the undefined index error that appears when purchasing an unselected product wit
- taxonomy-i want to implement a refined search on my custom taxonomyphp page
- php - a system that supports images of a specified size
- php - i want to search wordpress in real time
- some files are not searched by glob function (file search) of php
- php - how can i narrow down the search to a fixed page?
- php - want to customize wordpress bbpress site search results
- php - i want to include a custom field in the search result with a check box in wordpress
- php - implementation of a search function for creating a fictitious ec site
- php - about making browser games like vivid army
- php - how to search encrypted data and performance
- php - i don't want to be caught in the search when i get the data i want to do wherenot called rails with laravel
- when you create a question site with php, display the question page etc on the search engine
- php - i want to get the number of search results (index number) of "site: ~" on google
- php - how to refine your search for custom posts
- php - png image is not displayed
- php - i want to implement two iframes on the same page so that the height is not overwritten
- i want to write php that displays only 3 articles
- i want to specify the path of the php file in the public folder of laravel from javascript
- php - i want to be able to appear by clicking the drop-down menu that appears when hovering
- php security measures (validation) question about validation of input elements on the server side
- php - the value cannot be retained when the quantity of the shopping cart is changed by select/option
- php - about passing through without com with input [type = email]
- php - when outputting the value of the contents of the array no matter how many characters, can we take a frame for a fixed valu
I'm using a function that starts with mysql_, but are there any documents or books that I refer to?
The functions starting with mysql_ have various problems, and the successor mysqliIt has been replaced with a group of functions starting with _.
(For the time being, just add i.)
Let's change the function that should not be used before, such as not being able to access the database, to a mysqli function. Alternatively, it is recommended to completely change to the method of using PDO.
PHP: Which API to use --Manual
For the basic method of using PDO, refer to here.
It is written that it is important enough for veterans to read it again.
Summary when connecting to a database with PHP-Qiita
If you're referring to an old book or document,
Switch to one that can be confirmed to be compatible with PHP7 or later.
Even if you learn the old method now, you will only relearn it, and forcibly running the old PHP is not preferable for vulnerability countermeasures.
As explained in the mysql_ system, it may be a problem that transaction processing is not performed.
$_REQUEST ['pkey']
The way of referencing is not good.It should be implemented after clearly designing whether to receive by POST or GET.
If that consciousness is weak, it will adversely affect the system by illegally receiving parameters from the outside unintentionally.
And I suddenly refer to it even though I don't know if it exists or not
$pkey = trim ($_REQUEST ['pkey']);
That is not good.
(Warning: Cause of Undefined array key "pkey")
PHP: filter_input --Manual
It is easy to make full use of.