Jump to content

stvnkrs10

New Members
  • Posts

    2
  • Joined

  • Last visited

stvnkrs10's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. i realized in the testedit.php i left a piece of code for something i was trying please change : (the source file line) <script type="text/javascript"> $(document).ready(function(){ $("#newname").autocomplete({ source:'newtestgetautocomplete.php', minLength:1 }); }); </script> to <script type="text/javascript"> $(document).ready(function(){ $("#newname").autocomplete({ source:'testgetautocomplete.php', minLength:1 }); }); </script>
  2. 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 <html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script> <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" /> <script type="text/javascript"> $(document).ready(function(){ $("#name").autocomplete({ source:'testgetautocomplete.php', minLength:1 }); }); </script> </head> <!----- Start Add Form ------> <?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"); ?> <form action="testadd.php" method="POST"> <br /> <br /> <br /> <br /> <h1>Add a New User</h1> <table class="center"> <tr> <td>Enter a New Name: </td><td><input type="text" id="name" name="name" /></td> </tr> <tr> <td></td><td><input type="submit" value=" Add >>> "/></td> </tr> </table> </form> <!----- End Add Form ------> <!----- Start Table List ------> <h1>Existing Names</h1> <table class="results"> <?php /* ********* Table Headers ********** */ echo "<tr>"; echo "<td>" . " " . "</td>"; echo "<td>" . "ID" . "</td>"; echo "<td>" . "Name" . "</td>"; echo "<td>" . " " . "</td>"; echo "</tr>"; /* ********* Table data loop ********* */ while( $row = mysql_fetch_array($res)) { echo "<tr>"; echo "<td>" . "<a href='testedit.php?edit=$row[id]'>Edit</a>" . "</td>"; echo "<td>" . $row[id] . "</td>"; echo "<td>" . $row[name] . "</td>"; echo "</tr>"; } ?> </table> <!----- End Table List ------> </body> </html> and here is my testgetautocomplete.php (mysql connect values left out for obvious reasons) <?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); ?> and my testedit.php <html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script> <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" /> <script type="text/javascript"> $(document).ready(function(){ $("#newname").autocomplete({ source:'newtestgetautocomplete.php', minLength:1 }); }); </script> <title>UYS Edit Page</title> </head> <body> <!----- Start Edit Form ------> <?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 "<meta http-equiv='refresh' content='0;url=testadd.php'>"; } ?> <table class="centerwithroom"> <form action="testedit.php" method="POST"> <tr> <td>New Name </td><td><input type="text" name="newname" value="<?php echo $row[1]; ?>"/></td> </tr> <td></td><td><input type="submit" value=" Update "/></td> </tr> <input type="hidden" name="id" value="<?php echo $row[0]; ?>"/> </form> </table> <!----- End Edit Form ------> </body> </html>
×
×
  • 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.