In PHP, the data inserted in this Code cannot be displayed, but the page for querying data can be displayed as sad.

Source: Internet
Author: User
This problem has plagued me for several days. The following figure shows how to jump to the query page after the data is submitted in the form, but it does not show that the inserted data database has been inserted, but if it is opened separately the Data Query page shows who can help me. below is my...

This problem has plagued me for several days. The following figure shows how to jump to the query page after the data is submitted in the form, but it does not show that the inserted data database has been inserted, but if it is opened separately the Data Query page shows who can help me?

The following is my code. You can try it. At first, I thought it was a cache problem. I used several browsers.
Submitted on the first page




The second page Inserts

$ Con = mysql_connect ("localhost", "root", ""); // 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 = 'cx2. php'; script ";
Mysql_close ($ con)
?>

The third page is queried. If this page is opened separately, the inserted data will be displayed, but the jump page will not be displayed, just as it is in the picture.

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

}
Echo '$ SQL'
?>





  • Student ID
  • Name
  • Age

    
       '. $ V ['id'].''; Echo'
  • '. $ V ['name'],'
  • '; Echo'
  • '. $ V ['num'].'
  • '; Echo'
  • Edit
  • ';}

    ?>



Reply content:

This problem has plagued me for several days. The following figure shows how to jump to the query page after the data is submitted in the form, but it does not show that the inserted data database has been inserted, but if it is opened separately the Data Query page shows who can help me?

The following is my code. You can try it. At first, I thought it was a cache problem. I used several browsers.
Submitted on the first page




The second page Inserts

$ Con = mysql_connect ("localhost", "root", ""); // 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 = 'cx2. php'; script ";
Mysql_close ($ con)
?>

The third page is queried. If this page is opened separately, the inserted data will be displayed, but the jump page will not be displayed, just as it is in the picture.

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

}
Echo '$ SQL'
?>





  • Student ID
  • Name
  • Age

    
       '. $ V ['id'].''; Echo'
  • '. $ V ['name'],'
  • '; Echo'
  • '. $ V ['num'].'
  • '; Echo'
  • Edit
  • ';}

    ?>



Use the header as the jump header ('location: xxx. php'). Check the error. It seems to be a version issue.

It should be a problem with your version. You can add @ before mysql_connect. I use your source code to test everything locally and there will be no error. However, this is not a positive solution. I suggest you upgrade the version or you can talk about the version of mysql you are using.


  

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.