autocomplete textbox in an editing php form

Hello Everyone.

Please excuse any grammatical or code mistakes as I just began coding. :slight_smile: 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

<?php /* ********* Table Headers ********** */ echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; /* ********* Table data loop ********* */ while( $row = mysql_fetch_array($res)) { echo ""; echo ""; echo ""; echo ""; echo ""; } ?>
" . " " . "" . "ID" . "" . "Name" . "" . " " . "
" . "Edit" . "" . $row[id] . "" . $row[name] . "
[/php]

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
[/php]

in the testedit.php please ignore the source:‘newtestgetautocomplete.php’, and change back to source:‘testgetautocomplete.php’, as I was trying something that didn’t work :frowning:

Why implement something you know is insecure when you will have to change everything afterwards?

Sponsor our Newsletter | Privacy Policy | Terms of Service