Cory94bailly Posted May 28, 2008 Share Posted May 28, 2008 My code: <?php ob_start(); require 'config.php'; // Make a MySQL Connection mysql_connect($path, $username, $password) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); //Starts if you click the submit button. if(isset($_POST['submit'])) { //Set the variable! //Update it! $query = "UPDATE notepad SET notepad='$updated'"; mysql_query($query) or die(mysql_error()); echo "<meta http-equiv='refresh' content='1;url=index.php'>"; echo "variables"; } else { //Error message. die('Error!!!!!!!!!'); } list($notepad) = mysql_fetch_row($result); //The form. ?> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> <p>Text:<br> <textarea rows="10" cols="50" name="news"><?php echo $notepad ?></textarea> </p> <input type="submit" name="submit" value="Submit"> </form> <?php //End it!!! ob_end_flush(); ?> Now all I am getting is "Error!!!!!!!!!" Any help? (Btw, I know I did it wrong somehow =/) Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted May 28, 2008 Author Share Posted May 28, 2008 Just noticed.. I didn't define 2 or 3 variables. New code: <?php ob_start(); require 'config.php'; // Make a MySQL Connection mysql_connect($path, $username, $password) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); //Starts if you click the submit button. if(isset($_POST['submit'])) { //Set the variable! //Update it! $query = "UPDATE notepad SET notepad='$updated'"; $updated = $_POST['updated']; mysql_query($query) or die(mysql_error()); echo "<meta http-equiv='refresh' content='1;url=index.php'>"; } else { //Error message. die('Error!!!!!!!!!'); } $query = "SELECT notepad FROM notepad"; list($notepad) = mysql_fetch_row($result); //The form. ?> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> <p>Text:<br> <textarea rows="10" cols="50" name="updated"><?php echo $notepad ?></textarea> </p> <input type="submit" name="submit" value="Submit"> </form> <?php //End it!!! ob_end_flush(); ?> Still get "Error!". Quote Link to comment Share on other sites More sharing options...
peranha Posted May 28, 2008 Share Posted May 28, 2008 if(isset($_POST['submit'])) Try if(isset($_POST['updated'])) Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted May 28, 2008 Author Share Posted May 28, 2008 if(isset($_POST['submit'])) Try if(isset($_POST['updated'])) Same error.. Btw, it should be submit so the script starts when the Submit button is hit. Quote Link to comment Share on other sites More sharing options...
peranha Posted May 28, 2008 Share Posted May 28, 2008 That will only run the script is the button is hit. Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted May 28, 2008 Author Share Posted May 28, 2008 That will only run the script is the button is hit. Yes..... I want it to update if they click submit, not update nothing............................................ Quote Link to comment Share on other sites More sharing options...
peranha Posted May 28, 2008 Share Posted May 28, 2008 <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> should be <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted May 28, 2008 Author Share Posted May 28, 2008 Please, stop posting in this topic.. echoing it works too. Anyone else? Besides, that wouldn't cause the error. Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted May 28, 2008 Author Share Posted May 28, 2008 Ok, I got it to atleast show the box now.. <?php ob_start(); require 'config.php'; // Make a MySQL Connection mysql_connect($path, $username, $password) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); //Starts if you click the submit button. if(isset($_POST['submit'])) { //Set the variable! //Update it! $query = "UPDATE notepad SET notepad='$updated'"; $updated = $_POST['updated']; mysql_query($query) or die(mysql_error()); echo "<meta http-equiv='refresh' content='1;url=index.php'>"; } $query = "SELECT notepad FROM notepad"; $result = mysql_query($query); list($notepad) = mysql_fetch_row($result); //The form. ?> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> <textarea rows="10" cols="50" name="updated"><?php echo $notepad ?></textarea> <input type="submit" name="submit" value="Submit"> </form> <?php //End it!!! ob_end_flush(); ?> But it's not showing the text if I submit it. Quote Link to comment Share on other sites More sharing options...
peranha Posted May 28, 2008 Share Posted May 28, 2008 if you look at the error, you are missing the ; at the end. I just use a shorter version. If you dont want to listen, maybee you shouldnt be posting problems. Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted May 28, 2008 Author Share Posted May 28, 2008 if you look at the error, you are missing the ; at the end. I just use a shorter version. If you dont want to listen, maybee you shouldnt be posting problems. Whatever. Anyone....???????? Quote Link to comment Share on other sites More sharing options...
peranha Posted May 28, 2008 Share Posted May 28, 2008 <?php echo $_SERVER['PHP_SELF'] ?> <?php echo $notepad ?> you are missing the ; at the end of each of these. That is your problem. Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted May 28, 2008 Author Share Posted May 28, 2008 <?php echo $_SERVER['PHP_SELF'] ?> <?php echo $notepad ?> you are missing the ; at the end of each of these. That is your problem. Again, no it wasn't.. Heh, still showing a blank box... I put text in it, submit, and it stays blank.. Quote Link to comment Share on other sites More sharing options...
dezkit Posted May 28, 2008 Share Posted May 28, 2008 <?php echo $_SERVER['PHP_SELF']; ?> <?php echo $notepad; ?> Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted May 28, 2008 Author Share Posted May 28, 2008 <?php echo $_SERVER['PHP_SELF']; ?> <?php echo $notepad; ?> Ok god! lol. It's just not inserting the data. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 28, 2008 Share Posted May 28, 2008 The original problem was that you had the die() and else clause attached to the if (isset($_POST)) thing. So therefore, it would immediately jump to that. Quote Link to comment Share on other sites More sharing options...
peranha Posted May 28, 2008 Share Posted May 28, 2008 $updated = $_POST['updated']; That line needs to be before this line $query = "UPDATE notepad SET notepad='$updated'"; You need to assign the variable before you can use it. $updated = $_POST['updated']; $query = "UPDATE notepad SET notepad='$updated'"; Quote Link to comment Share on other sites More sharing options...
Prismatic Posted May 28, 2008 Share Posted May 28, 2008 Sorry ignore this. Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted May 28, 2008 Author Share Posted May 28, 2008 Well I got it to work.. <?php ob_start(); require 'config.php'; // Make a MySQL Connection mysql_connect($path, $username, $password) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); //Starts if you click the submit button. if(isset($_POST['submit'])) { //Set the variables! //Update it! $updated = $_POST['updated']; $query = "UPDATE notepad SET text='$updated'"; mysql_query($query) or die(mysql_error()); echo "<meta http-equiv='refresh' content='1'>"; } $query = "SELECT text FROM notepad"; $result = mysql_query($query); list($notepad) = mysql_fetch_row($result); //The form. ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <textarea rows="10" cols="50" name="updated"><?php echo $notepad; ?></textarea> <input type="submit" name="submit" value="Submit"> </form> <?php //End it!!! ob_end_flush(); ?> Quote Link to comment 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.