Tenaciousmug Posted May 7, 2011 Share Posted May 7, 2011 Whenever I hit the submit button, it's not even reading if they hit it and doing all that if and else statements I have. Why is not noticing the submit button? I had this working last night, but my dumb self saved over it with another file I was editing. <?php session_start(); include("config.php"); include("logincheck.php"); $time = date_default_timezone_set("US/Eastern"); $timeformat = date("Y-m-d H:i:s"); $author = $_SESSION['username']; $title = $_POST['title']; $body = $_POST['body']; if (isset($_POST['submit'])) { if (!empty($title)) { if (!empty($body)) { $sql = "INSERT INTO news (author, title, body, time) VALUES ('$author', '$title', '$body', NOW())"; mysqli_query($cxn, $sql); $error = "Your news posting has been submitted successfully."; } else { $error = "You must fill out the body of the posting!"; } } else { $error = "You must fil out the title of the posting!"; } } $sql = "SELECT userlevel FROM members WHERE userid='".$_SESSION['userid']."'"; $result = mysqli_query($cxn, $sql); $row = mysqli_fetch_array($result); if ($row['userlevel'] != 2) { $error = "You do not have the power to view this page!"; header("Location: news.php"); } else { ?> <?php include("header.php"); ?> <h1>Post News</h1> <?php echo $error; ?> <form method="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post"> <b>Author:</b> <?php echo $author; ?><br> <b>Title:</b><br> <input type="text" maxlength="25" name="title" value="<?php echo $title; ?>" /><br> <b>Body:</b><br> <textarea name="body" maxlength="999" rows="10" cols="40"><?php echo $body; ?></textarea><br> <input type="submit" name="submit" value="Post News" /> </form> <?php } ?> <?php include("footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/235779-not-reading-submit-button/ Share on other sites More sharing options...
fugix Posted May 7, 2011 Share Posted May 7, 2011 do you receive any errors? Quote Link to comment https://forums.phpfreaks.com/topic/235779-not-reading-submit-button/#findComment-1211961 Share on other sites More sharing options...
Tenaciousmug Posted May 7, 2011 Author Share Posted May 7, 2011 No it just refreshes the page. I do notice that it's putting all the attributes up in the URL. I mean it's reading them perfectly fine. But whenever I hit submit, it doesn't actually follow the if (isset($_POST['submit'])) I have going on. I took away that whole IF statement and it does the same thing. So I know it's not reading the submit button. I just don't get why it's not because last night, it was. :/ And I'm looking at my old books and I have everything correct... Quote Link to comment https://forums.phpfreaks.com/topic/235779-not-reading-submit-button/#findComment-1211963 Share on other sites More sharing options...
PFMaBiSmAd Posted May 7, 2011 Share Posted May 7, 2011 You have set the method to the script_name in the following - method="<?php echo $_SERVER['SCRIPT_NAME']; ?>" That should be - action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" Quote Link to comment https://forums.phpfreaks.com/topic/235779-not-reading-submit-button/#findComment-1211965 Share on other sites More sharing options...
Tenaciousmug Posted May 7, 2011 Author Share Posted May 7, 2011 OMG! Thank you sooo much! That's the spot I kept looking at. I guess I just need a second pair of eyes sometime. Genius. WONDERFUL. (: Quote Link to comment https://forums.phpfreaks.com/topic/235779-not-reading-submit-button/#findComment-1211967 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.