Jump to content

update/ mysql table row information


RCS

Recommended Posts

OK I have a script that allows me to delete information for a table row, I need to make the same script allow me to update information in table row that I choose from form.

 

This is current script

 

update.php

 

    <form name="delete" method="POST" action="delete.php">

        <p>Select the sales ad you would like to delete 

          <select name="select" id="select">

            <option value="1">1</option>

            <option value="2">2</option>

            <option value="3">3</option>

            <option value="4">4</option>

            <option value="5">5</option>

            <option value="6">6</option>

            <option value="7">7</option>

            <option value="8">8</option>

            <option value="9">9</option>

            <option value="10">10</option>

          </select>

        </p>

        <p>

          <input type="submit" name="submit" id="submit" value="Submit">

</p>

      </form>

 

This is the script that does everything.

delete.php

 

include("dbinfo.inc");

// open database connection

$connection = mysql_connect($db_host, $db_user, $db_passwd) or die ("Unable to connect!");

// select database

mysql_select_db($db_name) or die ("Unable to select database!");

if(isset($_POST['submit'])){

// Get ID

$id=mysql_real_escape_string($_POST['select']);

// generate and execute query

$query = "DELETE FROM upload WHERE id = '{$id}'";

$result = @mysql_query($query);

  if($result){

  echo "Delete Successfull<br />";

  } else {

  die ("Error in query: $query. " . mysql_error()."<br />");

  }

// close database connection

mysql_close($connection);

// print result

echo "<font size=-1><a href=update.php>Go back to the main page</a></font>";

} else {

//show form

//AND EXECUTE QUERY TO GET ALL THE ID's IN THE DATABASE:

$SQL = "SELECT * FROM `upload` ORDER BY `id` ASC";

$Q = mysql_query($SQL);

echo('<form action="'.$_SERVER['PHP_SELF'].'" method="POST" ">');

echo('<p align="center"> </p>');

echo ('<p>');

  if(mysql_num_rows($Q) > 0){

  echo('<select name="select" id="select">

        <option>Update</option>');

    while($DATA = mysql_fetch_assoc($Q)){

    echo('<option value="'.$DATA['id'].'">'.$DATA['id'].'</option>');

    }

    echo('</select>');

  } else {

    echo('There are no records in the database!');

  }

  echo('        </p>

                  <p align="center">

                      <input type="submit" name="Submit" id="Submit" value="Submit">

                    </p>

                    </form>');

 

}

 

now how do I make it so that I can also change information in a row?

 

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/100221-update-mysql-table-row-information/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.