How to do searching in PHP and AJAX?

Plis need help with Ajax, php?

  • I have a question about ajax, php so plis help me anyone. So i have created a form it has two id nume and mesaj i also conect to my database and with while loop so that i could display couple of forms with different values from database: <?php $result1=mysql_query("SELECT * FROM post",$pr); $myrow2 = mysql_fetch_array($result1); do { ?> <div id="txtHint"><b>Person info will be listed here.</b></div> <form method="post" name="form1" onsubmit="ajaxrequest('test_post.php'); return false;"> Your name: <input type="text" name="nume" id="nume" value='<?php echo $myrow2["text"]; ?>' /> Your message: <input type="text" name="mesaj" id="mesaj" value='<?php echo $myrow2["text2"]; ?>'> <input type="submit" value="Send" onmousemove="showUser(9)"/> </form> <?php } while($myrow2 = mysql_fetch_array($result1)); ?> And here the ajax code: <script type="text/javascript"><!-- function get_XmlHttp() { var xmlHttp = null; if(window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } else if(window.ActiveXObject) { // for Internet Explorer 5 or 6 xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } return xmlHttp; } function ajaxrequest(php_file) { var request = get_XmlHttp(); var nume = document.getElementById('nume').value; var mesaj = document.getElementById('mesaj').value; var the_data = 'nume='+nume+'&mesaj='+mesaj; request.open("POST", php_file, true); // sets the request request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); request.send(the_data); } --></script> The problem is that it display only first form values when i submit, when i submit other forms button it still submits first form values so plis help me i need help badly, some example code would be nice.

  • Answer:

    I am sorry, but your code is so badly organized that I can't follow it. Please, LEARN how to sructure your code properly. There are 4 basics structures available at http://web2coders.com, freephp scripts, basic lessons 1 to 4. Learn from them. Good luck.

MailL at Yahoo! Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.