Jump to content

Recommended Posts

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)

Link to comment
https://forums.phpfreaks.com/topic/192860-editing-a-message/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/192860-editing-a-message/#findComment-1015901
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.