perezf Posted July 3, 2007 Share Posted July 3, 2007 Im making a page that allow a user to choose the page he wants to edit from a drop down, then he can edit the info for that page for some reason its loading up a blank page, i think i have it write but can someone take a look and let me know if it is being done right <?php if ($_POST['choosepage']) { if($_POST['Submit']) { include ("../includes/dbconnect.inc.php"); $pageid = $_POST['pages']; $heading = $_POST['pageheader']; $information = $_POST['pageinfo']; mysql_query("UPDATE pages SET pageheader = '$heading' WHERE pageid = '$pageid'"); mysql_query("UPDATE pages SET pageinfo = '$information' WHERE pageid = '$pageid'"); echo "Update Complete!"; } else { include ("../includes/dbconnect.inc.php"); $pageid = $_POST['pages']; $query = "SELECT * FROM pages WHERE pageid = '$pageid'"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result) or die(mysql_error()); ?> <h1>Update Page</h1> <form id="Submit" name="Submit" method="post" action=""> <p>Heading:<br /> <input name="pageheader" type="text" id="pageheader" size="50" value="<?php echo $row['pageheader']; ?>" /> </p> <p>Information: <br /> <textarea name="pageinfo" cols="50" rows="15" id="pageinfo"><?php echo $row['pageinfo']; ?> </textarea> </p> <p> <input type="submit" name="Submit" value="Edit Page" /> </p> </form> <?php } } else { ?> <h1>Choose a Page</h1> <form action="" method="post" name="pages"> <select name="pages"> <?php include ("../includes/dbconnect.inc.php"); $query = "SELECT pageid, pageheader, pageinfo FROM pages"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"". $row['pageid'] ."\">".$row['pageheader']."</option>"; } ?> </select> <p> <label> <input type="submit" name="choosepage" id="choosepage" value="Choose Page" /> </label> </p> </form> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/58225-i-need-help-with-my-script/ Share on other sites More sharing options...
trq Posted July 3, 2007 Share Posted July 3, 2007 Its very difficult to read your code due to its lack of indentation, however, these lines... if ($_POST['choosepage']) { should be... if (isset($_POST['choosepage'])) { Just another tip. These queries... mysql_query("UPDATE pages SET pageheader = '$heading' WHERE pageid = '$pageid'"); mysql_query("UPDATE pages SET pageinfo = '$information' WHERE pageid = '$pageid'"); Should be done in one execution. eg; mysql_query("UPDATE pages SET pageheader = '$heading', pageinfo = '$information' WHERE pageid = '$pageid'"); And you should really check it actually worked before displaying a success message. eg; if (mysql_query("UPDATE pages SET pageheader = '$heading', pageinfo = '$information' WHERE pageid = '$pageid'")) { echo "Update Complete!"; } Link to comment https://forums.phpfreaks.com/topic/58225-i-need-help-with-my-script/#findComment-288717 Share on other sites More sharing options...
perezf Posted July 3, 2007 Author Share Posted July 3, 2007 thanks for the tips but i click the submit button to edit the page it takes me to my choose a page section and never updates the page Link to comment https://forums.phpfreaks.com/topic/58225-i-need-help-with-my-script/#findComment-288721 Share on other sites More sharing options...
trq Posted July 3, 2007 Share Posted July 3, 2007 Id'e like to help, but as I said, your code is very difficult to follow. Link to comment https://forums.phpfreaks.com/topic/58225-i-need-help-with-my-script/#findComment-288725 Share on other sites More sharing options...
perezf Posted July 3, 2007 Author Share Posted July 3, 2007 i organized the code so now can you help <?php if(isset($_POST['choosepage'])) { if(isset($_POST['editpage'])) { include ("../includes/dbconnect.inc.php"); $pageid = $_POST['pages']; $heading = $_POST['pageheader']; $information = $_POST['pageinfo']; if (mysql_query("UPDATE pages SET pageheader = '$heading', pageinfo = '$information' WHERE pageid = '$pageid'")) { echo "Update Complete!"; } } else { include ("../includes/dbconnect.inc.php"); $pageid = $_POST['pages']; $query = "SELECT * FROM pages WHERE pageid = '$pageid'"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result) or die(mysql_error()); ?> <h1>Update Page</h1> <form id="editpage" name="editpage" method="post" action=""> <p>Heading:<br /> <input name="pageheader" type="text" id="pageheader" size="50" value="<?php echo $row['pageheader']; ?>" /></p> <p>Information:<br /> <textarea name="pageinfo" cols="50" rows="15" id="pageinfo"><?php echo $row['pageinfo']; ?> </textarea></p> <p><input type="submit" name="editpage" id="editpage" value="Edit Page" /></p> </form> <?php } } else { ?> <h1>Choose a Page</h1> <form action="" method="post" name="pages"> <select name="pages"> <?php include ("../includes/dbconnect.inc.php"); $query = "SELECT pageid, pageheader, pageinfo FROM pages"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"". $row['pageid'] ."\">".$row['pageheader']."</option>"; } ?> </select> <p><label><input type="submit" name="choosepage" id="choosepage" value="Choose Page" /></label></p> </form> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/58225-i-need-help-with-my-script/#findComment-288749 Share on other sites More sharing options...
trq Posted July 3, 2007 Share Posted July 3, 2007 Both these will never be true at the same time. if(isset($_POST['choosepage'])) { if(isset($_POST['editpage'])) { Hence, your update code will never run. Link to comment https://forums.phpfreaks.com/topic/58225-i-need-help-with-my-script/#findComment-288753 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.