Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Ok please if anyone could help with this simple php and mysql question.

I'm new to databases, and trying to create my first user-friendly database. but i ran in to small problem.

I have a page that displays data, Than I also have a page where same data is displayed along with edit link, that goes to the edit form. However in the edit form the info is not coming up.

Here is my "edit.php" it shows info from database along with edit link:

    $con = mysql_connect("localhost","root","");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }

    mysql_select_db("beyondmotors", $con);

    $result = mysql_query("SELECT * FROM vehicles");

    echo "<table border='1'>
    <tr>
    <th>ID</th>
    <th>Year</th>
    <th>Make</th>
    <th>Model</th>
    <th>Mileage</th>
    </tr>";

    while($row = mysql_fetch_array($result))
      {
      echo "<tr>";
      echo "<td>" . $row['id'] . "</td>";
      echo "<td>" . $row['year'] . "</td>";
      echo "<td>" . $row['make'] . "</td>";
      echo "<td>" . $row['model'] . "</td>";
      echo "<td>" . $row['mileage'] . "</td>";
      echo ("<td><a href="edit_form.php?id=$row[id]">Edit</a></td></tr>");
      echo "</tr>";
      }
    echo "</table>";

    mysql_close($con);

And here is the Edit form :

    <html>
    <head>
    <title>Form Edit Data</title>
    </head>

    <body>
    <table border=1>
      <tr>
        <td align=center>Form Edit Employees Data</td>
      </tr>
      <tr>
        <td>
          <table>
          <?
          $con = mysql_connect("localhost","root","");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }

    mysql_select_db("beyondmotors", $con);
          $order = "SELECT * FROM vehicles where id=$id";
          $result = mysql_query($order);
          $row = mysql_fetch_array($result);
          ?>
          <form method="post" action="edit_data.php">
          <input type="hidden" name="id" value="<? echo "$row[id]"?>">
            <tr>        
              <td>Year</td>
              <td>
                <input type="text" name="year" 
            size="20" value="<? echo "$row[year]"?>">
              </td>
            </tr>
            <tr>        
              <td>Make</td>
              <td>
                <input type="text" name="make" 
            size="20" value="<? echo "$row[make]"?>">
              </td>
            </tr>
            <tr>        
              <td>Model</td>
              <td>
                <input type="text" name="model" 
            size="20" value="<? echo "$row[model]"?>">
              </td>
            </tr>
            <tr>
              <td>Mileage</td>
              <td>
                <input type="text" name="mileage" 
              value="<? echo "$row[mileage]"?>">
              </td>
            </tr>
            <tr>
              <td align="right">
                <input type="submit" 
              name="submit value" value="Edit">
              </td>
            </tr>
          </form>
          </table>
        </td>
      </tr>
    </table>
    </body>
    </html>

Than I also have Edit data, but it doesnt even get to that. Here is what i get at the edit form!! http://s562.photobucket.com/albums/ss69/intensemx/?action=view&current=pic.jpg

I followed this tutorial :

Help i'm lost here, Thanks in advance :)

Can any one recommend good place where I can get a similar tutorial.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
190 views
Welcome To Ask or Share your Answers For Others

1 Answer

The tutorial you are using is assuming that short tags are turned on. Alter the code to use <?php instead.

It also suffers from an SQL injection vulnerability.

It also appears to assume that register_globals is turned on.

Do not use that tutorial. It is dangerously bad.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...