Updating Rows ( 2 Views )

no kitty!
  1. Alright, I'm trying to write part of my script that will edit an exisiting SQL Row.

    PHP Code:

    <?php
    require('config.php');

    $editconnect = mysql_connect("$server", "$user", "$pass");
    mysql_select_db("$db", $editconnect) or die('Connection Failed!');
    $editsql = 'SELECT articletitle,article FROM articles';
        
    $result = mysql_query($editsql, $editconnect) or die(mysql_error());
        
    $nr=mysql_num_rows($result);
    for(
    $n=0;$n<$nr;$n++)
    {
    $edit=mysql_fetch_row($result);

    echo
    "
    <div align=\"center\">
    <form name=\"addarticle\" method=\"post\" action=\"edit.php\">
      <table width=\"513\" height=\"267\" align=\"cemter\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#FFFFFF\" class=\"box\">
        <tr bgcolor=\"#1B9FFF\">
          <td width=\"94\" height=\"29\" align=\"center\"><font size=\"1\" color=\"#FFFFFF\"><strong>Article
            Title</strong>:</font></td>
          <td width=\"413\" height=\"29\" align=\"left\" valign=\"middle\">
            &nbsp;&nbsp;
            <input name=\"articletitle\" type=\"text\" value=\"$edit[0]\">
          </td>
        </tr>
        <tr>
          <td width=\"94\" height=\"202\" align=\"center\" bgcolor=\"#89CDFF\"><font color=\"#FFFFFF\" size=\"1\"><strong>Article:</strong></font></td>
          <td align=\"center\" bgcolor=\"#89CDFF\"><textarea name=\"article\" cols=\"70\" rows=\"15\">$edit[1]</textarea></td>
        </tr>
        <tr align=\"center\" valign=\"middle\" bgcolor=\"#1B9FFF\">
          <td colspan=\"2\"><input type=\"submit\" name=\"Edit\" value=\"Edit\">
            <input name=\"Reset\" type=\"reset\" id=\"Reset\" value=\"Reset\"></td>
        </tr>
      </table>
    </form>
    </div>
    <br>
    <br>
    "
    ;
    }

    if (
    $Edit) {
    $title = $_POST['articletitle'];
    $art = $_POST['article'];

    $result=MYSQL_QUERY(("'UPDATE articles SET articletitle = $title', 'articles = SET article = $art'"), $editconnect);
        echo
    '<font color="#1B9FFF"><b>Editing Completed</b></font>';
    }
    ?>

    Now, there's really nothing wrong with my code, except that it just doesn't work. It displays the Current rows perfectly fine, but if you modify it, and click 'Edit' it really doesn't do anything. Can anyone try to help me figure this out?

    Script is located at http://ffx2.net/am/edit.php

    (UMUT , Netherlands Antilles)

  2. You really should work on your debugging skills instead of just posting here and waiting for someone to tell you what's wrong. Getting help for every syntax error is not the way to solve problems in php.

    http://www.php.net/manual/en/language.types.string.php under the "simple syntax" title and further down explains how variables are parsed within strings.

    (mehmet ali, Afghanistan)

  3. Quote:

    Originally Posted by Anarchos
    You have a number of problems with the script. For one thing, you need a way to identify which row is being edited. You should have an auto_incremented id column in your articles table that you can use to identify each row. Then when you're displaying the edit form for each row, you should output a hidden field that contains the id. Finally, when updating you need to add a WHERE id=$_POST['id'] clause at the end.

    Also, in your SQL code you need quotes around all strings that are being updated. articletitle and article are both strings so the values of $title and $art need quotes around them. I suggest that instead of running mysql_query() directly on that string, you use a variable like $sql to hold the sql query you want to execute. Then you can output $sql before you run the query just to see what exactly is being executed.

    Oops, the URL is http://ffx2.net/am/edit.php

    Working on two projects at once.
    Well, I do have an ID for each row, so I'll try that your way. Thanks

    [edit]

    I've made the changes, but I get a prase error (See link Above)

    PHP Code:

    if ($_POST['Edit']) {
    $title = $_POST['articletitle'];
    $art = $_POST['article'];

    $update = "UPDATE articles SET articletitle = '$title', article = '$art' WHERE articleid=$_POST['id']"; //Line 53 Here

    $result=MYSQL_QUERY("$update", $editconnect);
        echo
    '<font color="#1B9FFF"><b>Editing Completed</b></font>';
    }

    Not sure what the problem is.

    (selen, Bulgaria)

  4. You have a number of problems with the script. For one thing, you need a way to identify which row is being edited. You should have an auto_incremented id column in your articles table that you can use to identify each row. Then when you're displaying the edit form for each row, you should output a hidden field that contains the id. Finally, when updating you need to add a WHERE id=$_POST['id'] clause at the end.

    Also, in your SQL code you need quotes around all strings that are being updated. articletitle and article are both strings so the values of $title and $art need quotes around them. I suggest that instead of running mysql_query() directly on that string, you use a variable like $sql to hold the sql query you want to execute. Then you can output $sql before you run the query just to see what exactly is being executed.

    (OSMAN, Hong Kong)

  5. 404: file not found.

    (barış, Argentina)

  6. Alright thanks. But I'm still getting nothing:

    http://artofstealth.net/edit.php

    Any more ideas?

    (semih, Vanuatu)

  7. Your query is all messed up. I think it should be this:
    PHP Code:

    MYSQL_QUERY("UPDATE articles SET articletitle = $title, article = $art", $editconnect)


    (HÜSEYİN, Bolivia)

  8. I've already changed it to if ($_POST['Edit'])

    And yeah, I'm getting it from a form.

    (selim, Costa Rica)

  9. Where are you getting the $Edit variable from? If it's from a form, even if the same page handles and displays the form, you have to use the $_POST or $_GET super global.

    (ALİ, Brazil)

  10. I'm pretty sure the variable is taken from the name= part. That happens to be $Edit. I didn't really use Lowercase, so that can't be it.

    (yusuf, Kazakhstan)

  11. Sorry I was reading it wrong, it's supposed to be $edit, I think because you define the variable $edit and I think you meant to use that instead of $Edit.

    (özge cern, Marshall Islands)

  12. I changed it, but it's still not working.

    (elif, Guam)

  13. Your
    PHP Code:

    $Edit

    variable should be
    PHP Code:

    $_POST['Edit']


    (gizem, United Arab Emirates)

  14. Thanks, and do excuse me; I'm just starting in php.

    (yurgun güzler, Qatar)



Related Topics ... (or search in 1.720.883 topics !)

updating multiple rows (14)
updating 6 rows from 1 form? (2)
updating multiple rows (2)
updating multiple rows @ once (11)
updating multiple rows at once (3)
help with updating several rows in mysql. (3)
updating values in rows via a specified amount (5)
updating all password rows to md5 (3)
retrieving and updating multiple rows (3)




copyright © 2007-2031 Pfodere.COM ( 7 Pfoyihuee Online )

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 
0.6449