Hello Everyone.
Please excuse any grammatical or code mistakes as I just began coding. Also before hitting me up with security and mysql injection please understand, I am trying to just get this working and that is my next step.
On to what I am trying to accomplish. I have a table named formtest in which I want to draw data for an autocomplete text box. I am successful in doing this in my add form where it is not really needed, however in the edit form I canât get the autocomplete to work and this is where I want it to work.
Would someone be so kind to check this out for me and tell me why.
Thank you all kindly for your help!
Here are my forms:
testadd.php
[php]
<script type="text/javascript">
$(document).ready(function(){
$("#name").autocomplete({
source:'testgetautocomplete.php',
minLength:1
});
});
</script>
<?php
include_once('db.php');
if(isset($_POST['name'])
)
{
$name = $_POST['name'];
?>
<p class="deleted">
<?php
if(mysql_query("INSERT INTO formtest VALUES('','$name')"))
echo "Boat type $name Created and Added Successfully!";
else
echo "Oops! There was a problem. Please try again. If you have seen this error more than once please call UYS Support and tell them: ".mysql_error();
}
?>
</p>
<?php
$res = mysql_query("SELECT * FROM formtest ORDER BY name");
?>
Add a New User
Enter a New Name: | |
Existing Names
" . " " . " | "; echo "" . "ID" . " | "; echo "" . "Name" . " | "; echo "" . " " . " | "; echo "
" . "Edit" . " | "; echo "" . $row[id] . " | "; echo "" . $row[name] . " | "; echo "
and here is my testgetautocomplete.php (mysql connect values left out for obvious reasons)
[php]<?php
mysql_connect(âlocalhostâ, â ', â ');
mysql_select_db(" ");
$term=$_GET[âtermâ];
$query=mysql_query(âSELECT * FROM formtest where name like '%â.$term."%â order by name ");
$json=array();
while($student=mysql_fetch_array($query)){
$json[]=array(
'value'=> $student["name"],
'label'=>$student["name"]." - ".$student["id"]
);
}
echo json_encode($json);
?>[/php]
and my testedit.php
[php]
<script type="text/javascript">
$(document).ready(function(){
$("#newname").autocomplete({
source:'newtestgetautocomplete.php',
minLength:1
});
});
</script>
<title>UYS Edit Page</title>
<?php
include_once('db.php');
if( isset($_GET['edit']) )
{
$id = $_GET['edit'];
$res= mysql_query("SELECT * FROM formtest WHERE id='$id'");
$row= mysql_fetch_array($res);
}
if( isset($_POST['newname']))
{
$newname = $_POST['newname'];
$id = $_POST['id'];
$sql = "UPDATE formtest SET name='$newname' WHERE id='$id'";
$res = mysql_query($sql)
or die("Could not update".mysql_error());
echo "";
}
?>
New Name |