Okay I finished the script, it works great. Here's what it looks like:
<?php
include 'config.php';
$item=$_GET['name'];
mysql_connect($host,$username,$password);
@mysql_select_db($db_name) or die( "Unable to select database");
$var = $_POST['name'];
$none="No records found.";
$result = mysql_query("SELECT * FROM item_template WHERE (name LIKE \"%$item%\")");
echo mysql_error();
while($row = @mysql_fetch_array($result)){
echo "<form action=\"results.php\" method=\"POST\">";
echo "<input type=\"text\" name=\"id\" size=\"10\" value=\""; echo "$row[entry]\"> ";
echo "$row[name] <input type=\"submit\" name=\"Choose\"><br>";
}
if (!$item)
{
print ("$none");
}
?>
So this is the basic search engine that points to a results page. The results page displays the search information that the user selected from the search in a form, the user chooses edits what he wants to edit, then clicks the 'save' (submit) button, which then takes you to the processing page.
The processing page puts the POST data from the results page into an SQL query that is to be reinserted into the database. Now here's the problem: I can't use the mysql query:
INSERT INTO `database` (table1, table2, table3)
VALUE
(value1, value2, value3)
because you're editing a current row. To be exact, there are 106 columns in each row. I have a variable for each column. My question is, how do I replace the entire row? Here's my script "process.php" (most variables removed):
<?
include 'config.php';
mysql_connect($host,$username,$password) or die('Cannot connect to Database');
@mysql_select_db($db_name) or die( "Unable to select database");
$var = $_POST['entry'];
$XX="No records found.";
$result = mysql_query("SELECT * FROM item_template WHERE (entry LIKE \"%$var%\")");
echo mysql_error();
while($row = @mysql_fetch_array($result)){
$entry=$_POST['entry'];
$class=$_POST['class'];
$subclass=$_POST['subclass'];
$insert="INSERT INTO item_template (Entry, Class, Subclass)";
// this doesn't work, it deletes the $row[table] before $vari can be inserted.
mysql_query("DELETE from item_template WHERE entry = $entry") or die('Could not remove old entry');
// Setting the variable to array in this order //
$vari="($entry,$class,$subclass);";
// Remove the slashes //
$vari = stripslashes($vari);
// First part of SQL script //
mysql_query("$insert $value $vari") or die('Error: Query Failed');
echo "
<strong>Success!</strong><br>
The following query was inserted into your database:<br>
$insert<br>
$value<br>
$vari<br>";
}
?>
I really appreciate your help in this