Jump to content

Editing MySql Help


newbtophp

Recommended Posts

I've completed a way to delete data from my msqyl. But im having trouble, whenever I want to edit data i have to delete the whole line and resubmit.

 

Is their a way I can add a drop down on the "Status" and "Reason" column, the drop down would contain the same options as the submit form.

 

Heres my manage.php:

 

<?php

//Include mysql config
include "config.php";
include "password_protect.php";

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo $name; ?></title>

<LINK href="includes/style.css" rel="stylesheet" type="text/css">
</head>
<center>
<table width="600" cellspacing="0" cellpadding="0" id="main">
<tr><td><center>
<h1><?php echo $name; ?></h1>	<table width="100%" border="0" cellspacing="5" cellpadding="5" id="result">
<a href="index.php">Home</a>     <a href="manage.php">Manage</a>     <a href="index.php?logout=1">Logout</a>

<tr>

<body>
<div align="center">
  <table width="50%" height="100%" border="0" align="center">
    <tr valign="middle">
      <td><div align="center">
        <p>
	<?php


	echo"<br>";
	if($_POST["posting"] == "yes")
	{
		if(empty($_POST["reason"]) || empty($_POST["website"]) || empty($_POST["status"]))
		{
			echo "Please fill all the fields.";
		}
		else
		{
			$md5 = md5($_POST["name"].time());
			$sql = "INSERT INTO downloads (md5, reason, website, status) VALUES ('".$md5."','".$_POST["reason"]."','".$_POST["website"]."','".$_POST["status"]."');";
			sql($sql);
			$md5 = $rewrite.$md5;
			echo "Sucessfully Added!<br>";
		}
	}

	if($_GET["delete"])
	{
			$sql = "DELETE FROM downloads WHERE id = '".$_GET["delete"]."'";
			sql($sql);
	}

	$sql = "SELECT * FROM downloads";
	$fieldarray = array("reason","website","status");
	?>
	<table width="100%" bgcolor="#333333" style="text-align:center;">
	<?php


	echo maketable($sql, $fieldarray, "md5", 0, 1);
	?>
	</table>
        <br />
	</p>
<?php
//Submit form
?>
<form id="login" name="login" method="post" action="manage.php">
          <input name="posting" type="hidden" id="posting" value="yes" />
          Reason:<BR>
          <select name="reason" id="reason" >
          <option value="Nulled">Nulled</option>
<option value="Reselling">Reselling</option>
<option value="No License">No License</option>
	   </select>
          <BR>Website Url:<BR>
           <input name="website" type="text" id="website" value="http://www." />
           <BR>Status:<BR>
           <select name="status" id="status" >
<option value="Pending Action">Pending Action</option>
<option value="DMCA Sent">DMCA Sent</option>
<option value="CLOSED">CLOSED</option>
	   </select><BR>
	  <BR> <input type="submit" name="submit" value="Add" class="submit" /></p>
          </form>
                  <p>

Link to comment
Share on other sites

The code which I posted currently looks like (When I submit data from the form, it has a drop down field for reason and status, but it cant be changed when submitted):

 

oldone.jpg

 

So I want, to remove the delete column, and make some of the (reason, status) collumns be editable via a drop down menu.

 

Like below (but obviously neater then my paint skills, by css)

 

newone.jpg

Link to comment
Share on other sites

So remove your delete link, change it to a dropdown menu, then add a switch based on the value of that drop down:

 

switch ($_POST['dropdown'])
{
  case 'update':
    // do update query here
    break;
  case 'delete':
    // do delete query here
    break;
  // add other drop down options below this
}

Link to comment
Share on other sites

Heres the code, I assembled it by following mysql tutorials:

 

Im new to php and sql, so Im confused of which lines to edit and replace

 

<?php

//Include mysql config
include "config.php";
include "password_protect.php";

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo $name; ?></title>

<LINK href="includes/style.css" rel="stylesheet" type="text/css">
</head>
<center>
<table width="600" cellspacing="0" cellpadding="0" id="main">
<tr><td><center>
<h1><?php echo $name; ?></h1>



<table width="100%" border="0" cellspacing="5" cellpadding="5" id="result">
<a href="index.php">Home</a>     <a href="manage.php">Manage</a>     <a href="index.php?logout=1">Logout</a>

<tr>

<body>
<div align="center">
  <table width="50%" height="100%" border="0" align="center">
    <tr valign="middle">
      <td><div align="center">
        <p>





<?php










echo"<br>";





if($_POST["posting"] == "yes")





{







if(empty($_POST["reason"]) || empty($_POST["website"]) || empty($_POST["status"]))







{









echo "Please fill all the fields.";







}







else







{









$md5 = md5($_POST["name"].time());









$sql = "INSERT INTO downloads (md5, reason, website, status) VALUES ('".$md5."','".$_POST["reason"]."','".$_POST["website"]."','".$_POST["status"]."');";









sql($sql);









$md5 = $rewrite.$md5;









echo "Sucessfully Added!<br>";







}





}










if($_GET["delete"])





{









$sql = "DELETE FROM downloads WHERE id = '".$_GET["delete"]."'";









sql($sql);





}












$sql = "SELECT * FROM downloads";





$fieldarray = array("reason","website","status");





?>





<table width="100%" bgcolor="#333333" style="text-align:center;">





<?php






echo maketable($sql, $fieldarray, "md5", 0, 1);





?>





</table>
        <br />





</p>
<?php
//Submit form
?>
<form id="login" name="login" method="post" action="manage.php">
          <input name="posting" type="hidden" id="posting" value="yes" />
          Reason:<BR>
          <select name="reason" id="reason" >
          <option value="Nulled">Nulled</option>
<option value="Reselling">Reselling</option>
<option value="No License">No License</option>





   </select>
          <BR>Website Url:<BR>
           <input name="website" type="text" id="website" value="http://www." />
           <BR>Status:<BR>
           <select name="status" id="status" >
<option value="Pending Action">Pending Action</option>
<option value="DMCA Sent">DMCA Sent</option>
<option value="CLOSED">CLOSED</option>





   </select><BR>





  <BR> <input type="submit" name="submit" value="Add" class="submit" /></p>
          </form>
                  <p>

 

This the submit form which contains the predifined drop down options:

 

<?php
//Submit form
?>
<form id="login" name="login" method="post" action="manage.php">
          <input name="posting" type="hidden" id="posting" value="yes" />
          Reason:<BR>
          <select name="reason" id="reason" >
          <option value="Nulled">Nulled</option>
<option value="Reselling">Reselling</option>
<option value="No License">No License</option>









   </select>
          <BR>Website Url:<BR>
           <input name="website" type="text" id="website" value="http://www." />
           <BR>Status:<BR>
           <select name="status" id="status" >
<option value="Pending Action">Pending Action</option>
<option value="DMCA Sent">DMCA Sent</option>
<option value="CLOSED">CLOSED</option>









   </select><BR>









  <BR> <input type="submit" name="submit" value="Add" class="submit" /></p>
          </form>
                  <p>

Link to comment
Share on other sites

This is what I've come up with;

 

Select the checkbox then click the edit button, which opens an edit form for the row. On the form the field reason and status is a drop down.

 

It dont display though?

 

<?php
include 'config.php';
?>

<style type="text/css"><!--
div.message {
    display: block;
    margin: 10px 40px;
    padding: 5px 10px;
}

div#error.message {
    background-color: #fcc;
    border: 1px solid #f00;
    color: #f00;
    font-weight: bold;
}

form table.data-grid {
    border: 1px solid #d0e0ed;
    border-collapse: collapse;
    width: 100%;
}

form table.data-grid thead tr {
    background-color:#77003c;
    border: none;
}

form table.data-grid thead tr th {
    color: #fff;
    text-align: center;
}

form table.data-grid tr .input-col {
    text-align: center;
    width: 10%;
}

form table.data-grid tr .url {
    width: 40%;
}

form table.data-grid tr .link {
    width: 40%;
}

form table.data-grid tr .visits {
    width: 10%;
}

form table.data-grid tr td input[type="submit"] {
    background-color: #3893b2;
    border: 1px solid #166687;
    color: #fff;
    font-weight: bold;
}
--></style>

<?php
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
   if (!isset($_POST["submit"]))
   {
      $id = $_GET["id"];
      $sql = "SELECT * FROM downloads WHERE 'id'";
      $result = mysql_query($sql);        
      $myrow = mysql_fetch_array($result);


}

$data = mysql_query("SELECT * FROM `downloads`");
if(!$data)
{
    echo '<div style="background-color: #fcc; border: 1px solid #f00; color: #f00; font-weight: bold; padding: 5px 10px;">
        No data returned.
    </div>';

    if(mysql_error())
{
            echo '<div style="background-color: #fcc; border: 1px solid #f00; color: #f00; font-weight: bold; padding: 5px 10px;">
                MySQL Error (#'.mysql_errno().'): '.mysql_error().'
            </div>';
    }
    exit;
}

?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="data-grid-form">
    <table class="data-grid" cellspacing="0" cellpadding="0">
        <thead>
            <tr>
                <th class="input-col">
                    <input type="checkbox" onclick="toggleAll(this);" id="checkAllBox" />
                </th>
                <th class="website">Website</th>
                <th class="reason">Reason</th>
                <th class="status">Status</th>
            </tr>
        </thead>
        <tbody>
            <?php while($row = mysql_fetch_assoc($data)): ?> 
            <tr>
                <td class="input-col">
                    <input type="checkbox" name="ids[]" value="<?php echo $row['id']; ?>" />
                </td>
                <td class="website"><?php echo $row['website']; ?></td>
                <td class="reason"><?php echo $row['reason']; ?></td>
                <td class="status"><?php echo $row['status']; ?></td>
            </tr>
            <?php endwhile; ?>
            <tr>
                <td colspan="4" style="text-align: center;">
               
                    <input type="submit" name="cmd" value="edit" />
                    
                </td>
            </tr>
        </tbody>
    </table>
</form>

<?
   if ($_POST["$submit"])
   {
      $website = $_POST["website"];
  $reason = $_POST["reason"];
  $status = $_POST["status"];
  
  $sql = "UPDATE downloads SET website='$website',message='$reason',who='$status' WHERE id=$id";
      //replace news with your table name above
      $result = mysql_query($sql);
      echo "Thank you! Information updated.";
}
}
?>

<script type="text/javascript"><!-- // --><![CDATA[
function toggleAll(input)
{
    // Will the inputs be checked or not?
    var checked = input.checked;

    var form = document.getElementById('data-grid-form');
    if(form.elements.length)
    {
        for(var i=0; i<form.elements.length; i++)
        {
            var input = form.elements[i];

            if(input.type == 'checkbox')
            {
                input.checked = checked;
            }
        }
    }
}
// ]]></script>

Link to comment
Share on other sites

I looked over my code and it still displays a blank page, the sql and table is defined correctly;

 

<?php
include 'config.php';
?>

<style type="text/css"><!--
div.message {
    display: block;
    margin: 10px 40px;
    padding: 5px 10px;
}

div#error.message {
    background-color: #fcc;
    border: 1px solid #f00;
    color: #f00;
    font-weight: bold;
}

form table.data-grid {
    border: 1px solid #d0e0ed;
    border-collapse: collapse;
    width: 100%;
}

form table.data-grid thead tr {
    background-color:#77003c;
    border: none;
}

form table.data-grid thead tr th {
    color: #fff;
    text-align: center;
}

form table.data-grid tr .input-col {
    text-align: center;
    width: 10%;
}

form table.data-grid tr .url {
    width: 40%;
}

form table.data-grid tr .link {
    width: 40%;
}

form table.data-grid tr .visits {
    width: 10%;
}

form table.data-grid tr td input[type="submit"] {
    background-color: #3893b2;
    border: 1px solid #166687;
    color: #fff;
    font-weight: bold;
}
--></style>

<?php
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
   if (!isset($_POST["submit"]))
   {
      $id = $_GET["id"];
      $sql = "SELECT * FROM downloads WHERE 'id'";
      $result = mysql_query($sql);        
      $myrow = mysql_fetch_array($result);


}

$data = mysql_query("SELECT * FROM `downloads`");
if(!$data)
{
    echo '<div style="background-color: #fcc; border: 1px solid #f00; color: #f00; font-weight: bold; padding: 5px 10px;">
        No data returned.
    </div>';

    if(mysql_error())
{
            echo '<div style="background-color: #fcc; border: 1px solid #f00; color: #f00; font-weight: bold; padding: 5px 10px;">
                MySQL Error (#'.mysql_errno().'): '.mysql_error().'
            </div>';
    }
    exit;
}

?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="data-grid-form">
    <table class="data-grid" cellspacing="0" cellpadding="0">
        <thead>
            <tr>
                <th class="input-col">
                    <input type="checkbox" onclick="toggleAll(this);" id="checkAllBox" />
                </th>
                <th class="website">Website</th>
                <th class="reason">Reason</th>
                <th class="status">Status</th>
            </tr>
        </thead>
        <tbody>
            <?php while($row = mysql_fetch_assoc($data)): ?>
            <tr>
                <td class="input-col">
                    <input type="checkbox" name="ids[]" value="<?php echo $row['id']; ?>" />
                </td>
                <td class="website"><?php echo $row['website']; ?></td>
                <td class="reason"><?php echo $row['reason']; ?></td>
                <td class="status"><?php echo $row['status']; ?></td>
            </tr>
            <?php endwhile; ?>
            <tr>
                <td colspan="4" style="text-align: center;">
               
                    <input type="submit" name="cmd" value="edit" />
                   
                </td>
            </tr>
        </tbody>
    </table>
</form>

<?
   if ($_POST["$submit"])
   {
      $website = $_POST["website"];
     $reason = $_POST["reason"];
     $status = $_POST["status"];
    
     $sql = "UPDATE downloads SET website='$website',message='$reason',who='$status' WHERE id=$id";
      //replace news with your table name above
      $result = mysql_query($sql);
      echo "Thank you! Information updated.";
   }
}
?>

<script type="text/javascript"><!-- // --><![CDATA[
function toggleAll(input)
{
    // Will the inputs be checked or not?
    var checked = input.checked;

    var form = document.getElementById('data-grid-form');
    if(form.elements.length)
    {
        for(var i=0; i<form.elements.length; i++)
        {
            var input = form.elements[i];

            if(input.type == 'checkbox')
            {
                input.checked = checked;
            }
        }
    }
}
// ]]></script>

 

Anyone can help me please?

 

Cheers

Link to comment
Share on other sites

Heres the relevant code without css and js:

 

<?php
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
   if (!isset($_POST["submit"]))
   {
      $id = $_GET["id"];
      $sql = "SELECT * FROM downloads WHERE 'id'";
      $result = mysql_query($sql);        
      $myrow = mysql_fetch_array($result);


}

$data = mysql_query("SELECT * FROM `downloads`");
if(!$data)
{
    echo '<div style="background-color: #fcc; border: 1px solid #f00; color: #f00; font-weight: bold; padding: 5px 10px;">
        No data returned.
    </div>';

    if(mysql_error())
{
            echo '<div style="background-color: #fcc; border: 1px solid #f00; color: #f00; font-weight: bold; padding: 5px 10px;">
                MySQL Error (#'.mysql_errno().'): '.mysql_error().'
            </div>';
    }
    exit;
}

?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="data-grid-form">
    <table class="data-grid" cellspacing="0" cellpadding="0">
        <thead>
            <tr>
                <th class="input-col">
                    <input type="checkbox" onclick="toggleAll(this);" id="checkAllBox" />
                </th>
                <th class="website">Website</th>
                <th class="reason">Reason</th>
                <th class="status">Status</th>
            </tr>
        </thead>
        <tbody>
            <?php while($row = mysql_fetch_assoc($data)): ?>
            <tr>
                <td class="input-col">
                    <input type="checkbox" name="ids[]" value="<?php echo $row['id']; ?>" />
                </td>
                <td class="website"><?php echo $row['website']; ?></td>
                <td class="reason"><?php echo $row['reason']; ?></td>
                <td class="status"><?php echo $row['status']; ?></td>
            </tr>
            <?php endwhile; ?>
            <tr>
                <td colspan="4" style="text-align: center;">
               
                    <input type="submit" name="cmd" value="edit" />
                   
                </td>
            </tr>
        </tbody>
    </table>
</form>

<?
   if ($_POST["$submit"])
   {
      $website = $_POST["website"];
     $reason = $_POST["reason"];
     $status = $_POST["status"];
   
     $sql = "UPDATE downloads SET website='$website',message='$reason',who='$status' WHERE id=$id";
      //replace news with your table name above
      $result = mysql_query($sql);
      echo "Thank you! Information updated.";
   }
}
?>

 

Link to comment
Share on other sites

My Progress...

 

On my submission form I have 2 drop down menus with options for Reason and Status.

 

Now I've found a way to submit, I want to be able to edit the data.

 

My table is called downloads, and I want to be able to edit the 3 rows, Website (field), Reason (dropdown) and Status (dropdown). The trouble is when I select a checkbox to edit a row, the edit form loads the options as fields and not drop downs (like the submit form)

 

 

 

<?php

//Include mysql config
include "config.php";

?>
<?php
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
   if (!isset($_POST["submit"]))
   {
      $id = $_GET["id"];
      $sql = "SELECT * FROM downloads WHERE 'id'";
      $result = mysql_query($sql);        
      $myrow = mysql_fetch_array($result);


}

$data = mysql_query("SELECT * FROM `downloads`");
if(!$data)
{
    echo '<div style="background-color: #fcc; border: 1px solid #f00; color: #f00; font-weight: bold; padding: 5px 10px;">
        No data returned.
    </div>';

    if(mysql_error())
{
            echo '<div style="background-color: #fcc; border: 1px solid #f00; color: #f00; font-weight: bold; padding: 5px 10px;">
                MySQL Error (#'.mysql_errno().'): '.mysql_error().'
            </div>';
    }
    exit;
}

?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="data-grid-form">
    <table class="data-grid" cellspacing="0" cellpadding="0">
        <thead>
            <tr>
                <th class="input-col">
                    <input type="checkbox" onclick="toggleAll(this);" id="checkAllBox" />
                </th>
                <th class="website">Website</th>
                <th class="reason">Reason</th>
                <th class="status">Status</th>
            </tr>
        </thead>
        <tbody>
            <?php while($row = mysql_fetch_assoc($data)): ?>
            <tr>
                <td class="input-col">
                    <input type="checkbox" name="ids[]" value="<?php echo $row['id']; ?>" />
                </td>
                <td class="website"><?php echo $row['website']; ?></td>
                <td class="reason"><?php echo $row['reason']; ?></td>
                <td class="status"><?php echo $row['status']; ?></td>
            </tr>
            <?php endwhile; ?>
            <tr>
                <td colspan="4" style="text-align: center;">
               
                    <input type="submit" name="cmd" value="edit" />
                   
                </td>
            </tr>
        </tbody>
    </table>
</form>

<?
   if ($_POST["$submit"])
   {
      $website = $_POST["website"];
     $reason = $_POST["reason"];
     $status = $_POST["status"];
   
     $sql = "UPDATE downloads SET website='$website',message='$reason',who='$status' WHERE id=$id";
      //replace news with your table name above
      $result = mysql_query($sql);
      echo "Thank you! Information updated.";
   }
}
?>

 

 

This is my submit form (which contains the options, I've only displayed the html to shorten the code):

 

<form id="login" name="login" method="post" action="manage.php">
          <input name="posting" type="hidden" id="posting" value="yes" />
          Reason:<BR>
          <select name="reason" id="reason" >//Options for Reason
          <option value="Nulled">Nulled</option>
<option value="Reselling">Reselling</option>
<option value="No License">No License</option>





   </select>
          <BR>Website Url:<BR>
           <input name="website" type="text" id="website" value="http://www." />
           <BR>Status:<BR>
           <select name="status" id="status" >//Options for Status
<option value="Pending Action">Pending Action</option>
<option value="DMCA Sent">DMCA Sent</option>
<option value="CLOSED">CLOSED</option>





   </select><BR>





  <BR> <input type="submit" name="submit" value="Add" class="submit" /></p>
          </form>
                  <p>

Link to comment
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.