Please help me solve the difficult problem. I am a novice. I hope to explain it as clearly as possible. Thank you!
圆子
圆子 2019-04-25 16:45:06
0
4
1053

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


}

?>


圆子
圆子

reply all(2)
Ds
$_SESSION['username']这样才可以获取到值吧


  • reply I don't understand what you mean. Can you tell me where it is specifically?
    圆子 author 2019-04-26 19:15:20

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 I tried changing the userid and username to the same one, but it didn't work.
    圆子 author 2019-04-26 19:17:48
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!