I am only beginner at this. I don't understand this fully, half of it was given to me and other half was my team writing it out. I can't work out how to create a form to edit a table. There is people.php file. Thats the file I want to put in edit form. Search and Insert form is working fine. In different folder there called crud_single_table. In that folder there are code for update, insert, confirm_update, etc. No edit code in there yet cos I don't know excalty what code put in there.

In my people.php

<?php
WHERE name!='fluffy' ORDER BY name";
$header = "PEOPLE";
$table = "people";
$query = "Select * from ".$table." where true ";

	$value = '';
	if (isset($_GET['value']))
	{
		$value = $_GET['value'];
	}

	$field = '';
	if (isset($_GET['field']))
	{
		$field = $_GET['field'];
	}

	$mode = $_GET['mode'];
	if ($mode == '')
	{
		$mode = 'search';
	}
	
$result = mysql_query ($query) or die("Query failed");

$rows = mysql_num_rows ($result);
$columns = mysql_num_fields($result);
?>
<script>
	function refresh()
	{
// some code here
	}
	function insert_new()
	{		
		var sURL = unescape(window.location.pathname);
		//alert (sURL);
		window.location.href = sURL+"?here=<?php echo $here ?>&mode=insert";
	}
	function update_data(pino,gino)
	{		
		var sURL = unescape(window.location.pathname);
		//alert (sURL);
		window.location.href = sURL+"?here=<?php echo $here ?>&mode=update&field="+pino+"&value="+gino;
		//alert (sURL+"?here=<?php echo $here ?>&mode=update&field="+pino+"&value="+gino);
	}
</script>

<div id=manage_content>
	<input type=button id=button1 value='Refresh' onclick="javascript:refresh();">
	<input type=button id=button1 value='Search table' onclick="javascript:viewall();">
	<input type=button id=button1 value='Insert new' onclick="javascript:insert_new();">
</div>
</div>

<div id=manage_form>
<?php
	$form_as_html = "<B>FIELDS</B> "."MODE = ".$mode." <P><table id='table2' width=100%>";
	
if ($mode == 'search')
{
	include("crud_single_table/search.php");
	echo $form_as_html;
}

if ($mode == 'insert')	
{
	include("crud_single_table/insert.php");
	echo $form_as_html ;
}	

if ($mode == 'confirm_insert')
{
	include("crud_single_table/confirm_insert.php");
	//echo $form_as_html;
}

if ($mode == 'update')
{
	include("crud_single_table/update.php");
	echo $form_as_html ;
}

if ($mode == 'confirm_update')
{
	include("crud_single_table/confirm_update.php");
	//echo $form_as_html;
}

if ($mode == 'confirm_search')
{
	include("crud_single_table/search.php");
	echo $form_as_html;
}
?>
</div>
<div id=list_content>
<?php
	include("crud_single_table/show_select.php");
	echo ($result_as_html);
?>
</div>
<?php
	mysql_close();
?>

Recommended Answers

All 2 Replies

Member Avatar for diafol

Maybe me, but can't really work out what you're trying to do here. Why don't you just have one include file with several functions as opposed to loads of include files with probably no functions at all, just small bits of code?

For example, in the file posted:

include('crud_single_table/functions.inc.php');

switch($mode){
  case 'search':
    $action = search(...); //call the search function
    break;
  case 'insert':
    $action = insert(...); //call the insert function
    break;
  case 'confirm_insert':
    $action = confirm_insert(...); //call the confirm_insert function
    break;
  
      (other functions...etc etc)
}
echo $form_as_html;

In your functions.inc.php file:

function search (...){
    (whatever your code)
    return $output;
}
 (etc)

By the way, I think your Edit code is your Update code. But perhaps I got you really wrong.

Thanks. Lecturer given us code like that in that sort of layout so we just carried it on same layout. Bit too late to change it cos deadline coming few days time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.