Why can't the data I just inserted in this code be displayed? Open cx. php (the last piece of code) separately. you can view the data on this page, but you cannot view the data you just inserted when you jump to the page. why? Thank you.
$ Con = mysql_connect ("localhost", "root ","");
If (! $ Con)
{
Die ('could not connect: '. mysql_error ());
}
Mysql_select_db ("t1", $ con );
$ SQL = "INSERT INTO stu (id, name, num)
VALUES ('$ _ POST [firstname]', '$ _ POST [lastname]', '$ _ POST [age]') ";
If (! Mysql_query ($ SQL, $ con ))
{
Die ('Error: '. mysql_error ());
}
Echo "1 record added ";
Mysql_close ($ con)
?>
Last section:
$ Con = mysql_connect ("localhost", "root ","");
If (! $ Con)
{
Echo "failed to connect to database ";
Exit;
}
$ SQL = 'use T1 ';
Mysql_query ($ SQL, $ con );
$ SQL = 'select * from stu ';
$ Rs = mysql_query ($ SQL, $ con );
$ List = array ();
While ($ row = mysql_fetch_assoc ($ rs )){
$ List [] = $ row;
}
?>
Student ID |
Name |
Age |
Foreach ($ list as $ v ){Echo'
';Echo'
'. $ V ['id'].' | ';Echo'
'. $ V ['name'],' | ';Echo'
'. $ V ['num'].' | ';Echo'
Edit | ';Echo'
';}?>
Reply to discussion (solution)
The data just inserted cannot be viewed after the jump.
Insert2.php: the file you submitted
Cx. php is to view
No jump code
The data just inserted cannot be viewed after the jump.
Insert2.php: the file you submitted
Cx. php is to view
No jump code
The error message in the second section is that the following section has a jump, but the inserted data cannot be displayed.
$ Con = mysql_connect ("localhost", "root ","");
If (! $ Con)
{
Die ('could not connect: '. mysql_error ());
}
Mysql_select_db ("t1", $ con );
$ SQL = "INSERT INTO stu (id, name, num)
VALUES ('$ _ POST [firstname]', '$ _ POST [lastname]', '$ _ POST [age]') ";
If (! Mysql_query ($ SQL, $ con ))
{
Die ('Error: '. mysql_error ());
}
Echo "script" alert ('published successfully'); location. href = 'cx. php'; script ";
Mysql_close ($ con)
?>
1. check whether the database has data,
2. when viewing the query, print the query SQL.
1. check whether the database has data,
2. when viewing the query, print the query SQL.
If the database is inserted, it cannot be displayed.
Foreach ($ list as $ v ){
You reversed it.
It should be
Foreach ($ v as $ list ){
Foreach ($ list as $ v ){
You reversed it.
It should be
Foreach ($ v as $ list ){
The code on the last page is not displayed.
Can I execute cx. php separately for display?
The last line is displayed. Have you checked it carefully?
For your browser, can location. href = 'cx. php' generate actual http requests? Please verify
General Writing
Location = 'cx. php'
Or
Location. reload ('cx. php ')
Or
Location. replace ('cx. php ')
Can I execute cx. php separately for display?
The last line is displayed. Have you checked it carefully?
For your browser, can location. href = 'cx. php' generate actual http requests? Please verify
General Writing
Location = 'cx. php'
Or
Location. reload ('cx. php ')
Or
Location. replace ('cx. php ')
I tried it as you said, but it still didn't work. if I didn't refresh the page of cx. php, I just jumped to the previous page and inserted all the data that couldn't be displayed after the jump.
After refresh, the data will be displayed, but after you insert the data again, if the inserted data is still not displayed, can you try my code on your machine? thank you!
What is the result of caching? Try to add a random number after the jump url
What is the result of caching? Try to add a random number after the jump url
How can we add random numbers? why is this not the case when I open them separately?
This has nothing to do with cache!
If the data can be displayed separately, all data in the stu table can be displayed in the past.
==In fact, I still don't quite understand what the problem is
Echo "script" alert ('published successfully'); location. href = 'cx. php'; script ";
Change
Echo "script" alert ('published successfully'); location. href = 'cx. php? R = '+ Math. random (); script ";
What is the result of caching? Try to add a random number after the jump url
How can we add random numbers? why is this not the case when I open them separately?
Echo "script" alert ('published successfully'); location. href = 'cx. php'; script ";
Change
Echo "script" alert ('published successfully'); location. href = 'cx. php? R = '+ Math. random (); script ";