Why can't the data I just inserted in this code be displayed?

Source: Internet
Author: User
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;
}
?>

















Foreach ($ list as $ v ){Echo' ';Echo' ';Echo' ';Echo' ';Echo' ';Echo' ';}?>
Student ID Name Age
'. $ V ['id'].''. $ V ['name'],''. $ V ['num'].'Edit





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 ";

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.