3raser Posted February 21, 2010 Share Posted February 21, 2010 Code: //connecting to the database $connect = mysql_connect("$dbhost","$dbuser","$dbpassword") or die("Connection failed!"); mysql_select_db("$db") or die("Database fail!"); if (!$new) { echo "<form action='edit.php' method='POST'><textarea name='newmessage' rows='10' cols='40'></textarea><br><input type='submit' value='Edit'></fomr>"; } else { //extract $extract = mysql_query("SELECT * FROM posts WHERE id='$edit'"); $numrows = mysql_num_rows($extract); while ($row = mysql_fetch_assoc($extract)) { if ($row[username]==$session) { mysql_query("UPDATE posts SET message = $new WHERE id='$edit'"); echo "Message successfully changed."; } else { echo "This isn't your message to edit!"; } } } ?> Everytime I click edit, it doesn't do anything. It just sends me to a blank message after I type in my stuff and then click edit. Also, this is an error unrelated to this. If you can help me out real quick on this, I'd appreciate it: ". $row[id] ."<a href='edit.php?id=". $id ."'>[Edit]</a> This only appears as: edit.php?id= I don't know why nothing is showing up. (And yes I have my MySQL stuff correct and everything) Quote Link to comment https://forums.phpfreaks.com/topic/192860-editing-a-message/ Share on other sites More sharing options...
3raser Posted February 21, 2010 Author Share Posted February 21, 2010 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/192860-editing-a-message/#findComment-1015838 Share on other sites More sharing options...
3raser Posted February 22, 2010 Author Share Posted February 22, 2010 Bump Quote Link to comment https://forums.phpfreaks.com/topic/192860-editing-a-message/#findComment-1015848 Share on other sites More sharing options...
merylvingien Posted February 22, 2010 Share Posted February 22, 2010 The reason you are getting a blank page is becuase you havent put the information in the database into your page! Quote Link to comment https://forums.phpfreaks.com/topic/192860-editing-a-message/#findComment-1015857 Share on other sites More sharing options...
3raser Posted February 22, 2010 Author Share Posted February 22, 2010 That's basically like an offensive to me. -.- I have my database information... Quote Link to comment https://forums.phpfreaks.com/topic/192860-editing-a-message/#findComment-1015858 Share on other sites More sharing options...
merylvingien Posted February 22, 2010 Share Posted February 22, 2010 Offensive? LOL You want to edit a post yes? Where is the form with the info from the database that you want to edit? P.S if you want offensive, you spelt form wrong... Quote Link to comment https://forums.phpfreaks.com/topic/192860-editing-a-message/#findComment-1015860 Share on other sites More sharing options...
3raser Posted February 22, 2010 Author Share Posted February 22, 2010 No I didn't? Quote Link to comment https://forums.phpfreaks.com/topic/192860-editing-a-message/#findComment-1015871 Share on other sites More sharing options...
merylvingien Posted February 22, 2010 Share Posted February 22, 2010 </fomr> Quote Link to comment https://forums.phpfreaks.com/topic/192860-editing-a-message/#findComment-1015878 Share on other sites More sharing options...
jcanker Posted February 22, 2010 Share Posted February 22, 2010 as far as the single line code issue goes, it's because your quote nesting is messed up.: ". $row[id] ."<a href='edit.php?id=". $id ."'>[Edit]</a> You start with ". $row[id]." that leaves ."<a href='edit.php?id=. out on its own without being in quotes. You thenare starting a new set of nested quotes which don't close until something later in your code. As far as the other code goes, do you have all your error reporting turned on in php.ini so you can see what's going on? It's difficult to say exactly what's going on here, because I'm not sure it's the whole set of code, so I can't see what else may or may not have going on before this since you don't open with <?php in this snippet (and, well, maybe that's the problem!): //connecting to the database $connect = mysql_connect("$dbhost","$dbuser","$dbpassword") or die("Connection failed!"); mysql_select_db("$db") or die("Database fail!"); if (!$new) { echo "<form action='edit.php' method='POST'><textarea name='newmessage' rows='10' cols='40'></textarea><br><input type='submit' value='Edit'></fomr>"; } else { //extract$extract = mysql_query("SELECT * FROM posts WHERE id='$edit'"); $numrows = mysql_num_rows($extract); while ($row = mysql_fetch_assoc($extract)) { if ($row[username]==$session) { mysql_query("UPDATE posts SET message = $new WHERE id='$edit'"); echo "Message successfully changed."; } else { echo "This isn't your message to edit!"; } } } ?> Where is $edit coming from? There's not an element in your form named "edit." Also, you'll NEVER have a $new, because you'll run the code that displays the html form, and submit it back to this page (I assume..again, not enough info on the operation process), which still doesn't have anything set for $new, so it displays the form again. Do you mean to take the value entered into the textbox named "newmessage" and enter it into the db? Also, this html is too improperly formed for a browser to intrepret it without the html headings such as <html><head><body>, since you never properly close the <form> tag. Check your php.ini settings and see what your register globals is set to. As I understand it (and I put into practice myself) they should be turned off and you should get your form data using $_POST or $_GET, depending on how secure you need the info about what's being passed to be. Here you use post, so it should be $_POST['edit'], but that assumes that there's actually a form element named "edit" to be passed on. The submit button's value is "edit" but it's not NAMED "edit." I have to say, it's REALLY hard to answer your question because of what may or may not be missing in your code. You tell us that you "have [your] database information", but based on what is posted here, you don't. Hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/192860-editing-a-message/#findComment-1015901 Share on other sites More sharing options...
jcanker Posted February 22, 2010 Share Posted February 22, 2010 Justin, did that help? Quote Link to comment https://forums.phpfreaks.com/topic/192860-editing-a-message/#findComment-1016425 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.