Jump to content

Problem editing


captain_scarlet87

Recommended Posts

Hi,

 

I've got 3 bits of code:

 

filter(admin).php allows the user to filter the results using a drop down menu. Each result then have an edit button next to each which takes them to the edit_form_instructions page.

 

edit_form_instructions.php should display the form with the current data already in it, however I'm only getting the form to appear with no data inside. Tried to submit some different content into the blank boxes but the database table did not update.

 

edit_data_instructions deals with updating the data.

 

Can you please help, I am getting no error messages to guide me where the problem is.

 

<?php # Script 13.8 - filter(admin).php

// Include the configuration file for error management and such.
require_once ('./includes/config.inc.php');

// Set the page title and include the HTML header.
$page_title = 'filter';
include ('./includes/header.html');

?>
<h1>View Instructions:</h1>
<fieldset><p><b>Search instructions by keyword:</b><p>

<form action="search_results.php" method="get">
<div align="center">
<p>
<input name="search" type="text" size="30"/>
<input name="submit" type="submit" value="Search" />
</p>
</div>
</form>

<p><b>Filter instructions:</b><p>

<form action="filter(admin).php" method="post">
<select name="topic">
<option value="crm">CRM</option>
<option value="email">Email</option>
</select>
<input type="submit" value="Filter" />
</form>
<br>

<?php

if(isset($_POST['topic'])){ // anything posted????

    require_once ('../mysql_connect.php'); // Connect to the database.

    $dState = $_POST["topic"];

    $sqlQuery = "SELECT title, instructions_id FROM uploaded_instructions WHERE topic=\"$dState\"";
    $result = mysql_query($sqlQuery);
              while ($row=mysql_fetch_array($result)){
                echo ("<tr><td><a href=view_instructions.php?instructions_id=$row[instructions_id]> $row[title] </a> | </td>");} // <tr><td>$row[title]</td>
			echo ("<td><a href=\"edit_form_instructions.php?id=$row[instructions_id]\"><b>Edit</b></a></td>");
    include ('./includes/footer.html');

} // end anything posted???

include ('./includes/footer.html');
?></fieldset>

 

<?php # Script 13.8 - edit_form_instructions.php

// Include the configuration file for error management and such.
require_once ('./includes/config.inc.php');

// Set the page title and include the HTML header.
$page_title = 'Edit Instructions';
include ('./includes/header.html');
?>

<h1>Edit Instructions</h1>
	      <?php
	      require_once ('../mysql_connect.php'); // Connect to the database.
	      $id = mysql_real_escape_string($_GET['id']);
	      $order = "SELECT * FROM uploaded_instructions
					where instructions_id='$id'";

	      $result = mysql_query($order);
	      $row = mysql_fetch_array($result);
	      ?>
	      <fieldset>
	      <form method="post" action="edit_data_instructions.php">
	      <input type="hidden" name="id" value="<?php echo $row['instructions_id'];?>">
	        <p>
	          <b>Title: </b> <input type="text" name="title"
	        size="20" value="<?php echo $row['title'];?>">
	        </p>
	        <p>
	        	<b>Instructions: </b><br><textarea name="instructions" maxlength="1000" rows="30" cols="120" value="<?php echo $row['instructions'];?>" /></textarea> </p>
	          </fieldset>
	          <p>
	            <div align="center"><input type="submit" name="submit value" value="Edit"></div>
	          </p>

<?php // Include the HTML footer.
include ('./includes/footer.html');
?>

 

<?php
//edit_data.php
require_once ('../mysql_connect.php'); // Connect to the database.
$id = mysql_real_escape_string($_POST['id']); // added this, need to get the id from $_POST
$title = mysql_real_escape_string($_POST['title']);
$instructions = mysql_real_escape_string($_POST['instructions']);
$order = "UPDATE uploaded_instructions
          SET title='$title', instructions='$instructions'

          WHERE
          instructions_id='$id'";
mysql_query($order);
header("location:filter(admin).php");
?>

Link to comment
Share on other sites

Try echo $id; to see if your id is assigned correctly.

 

You could also try this:

         

 $order = "SELECT * FROM uploaded_instructions
                  where instructions_id='{$id}'";

 

And for the record: Its not recommended to call arrays without apostrophes so you should use $arr['key'] instead of $arr[key].

 

And if id is number (as i think it is) i'd recommend just checking it out like this:

if(!is_numeric($id)) exit('lol hacker');

Link to comment
Share on other sites

The instructions_id is not displaying in the url to be passed over to the edit_form_instructions.php page.

 

So must be a problem with the filter(admin).php page but can't seem to find it.

 

The weird thing is the instructions_id is being passed over from the filter page with the view instructions function that works fine but no with the edit link.

 

 

Link to comment
Share on other sites

Oops my fault, had a extra } that wasn't needed.

 

By removing that the id is being passed over and the text in the title box is showing but nothing in the instructions box. Exactly the same code is used for both except the instructions one is a textarea, this shouldn't make a difference though???

 

b>Title: </b> <input type="text" name="title"
	        size="20" value="<?php echo $row['title'];?>">
	        </p>
	        <p>
	        	<b>Instructions: </b><br><textarea name="instructions" maxlength="1000" rows="30" cols="120" value="<?php echo $row['instructions'];?>" /></textarea> </p>
	          </fieldset>
	          <p>

 

Anyone know why this is happening?

 

 

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.