search

Home  >  Q&A  >  body text

Please help me solve the difficult problem. I am a novice. I hope to explain it as clearly as possible. Thank you!

This is the code for the message section of the page. The problem is that the account is logged in, and then the message title and content are written, but the display fails after submission. I don’t know what went wrong. I hope you can teach me. Thank you. !

<?php

require("header.php");

if($_SESSION[username]=="")

{

echo "<script>alert('Please log in first');history.back();</script>";

exit;

}

if($act=="save")

{

if($title=="" || $content=="")

{

echo "<script>alert('Message title, content, cannot be empty');history.back();</script>";

exit;

}


##$sql="insert into liuyan (title,content,userid) values ​​('$title','$content','$_SESSION [username]')";


$res=mysql_query($sql);

if($res)

{

echo "<script>alert('success');location.href='guest.php';</script>";

exit;

}

else


exit("Failed");


}

?>


圆子圆子2029 days ago1063

reply all(4)I'll reply

  • Ds

    Ds2019-04-26 16:52:22

    $_SESSION['username']这样才可以获取到值吧


    reply
    0
  • 圆子

    I don't understand what you mean. Can you tell me where it is specifically?

    圆子 · 2019-04-26 19:15:20
  • 2019-04-26 15:07:51

    Failure to display means that the program has entered, so it should be a problem with your SQL statement. You can put the sql statement into the database and run it. I feel that it may be a problem with the third column of your insert statement, which is inserted. The field name is userid, but the value that follows is username. Moreover, it is best to use camel case for naming. A good coding habit

    reply
    0
  • 圆子

    I tried changing the userid and username to the same one, but it didn't work.

    圆子 · 2019-04-26 19:17:48
  • Cancelreply