comptech Posted November 26, 2011 Share Posted November 26, 2011 hi i want when click on button , then execute function in php that perform query like this: <input type="button" name="search1" value="search1" onclick="f()" /><input type="text" name="search" > <?php$search=$_POST['search'];$link=mysql_connect('localhost','root','3580');if(!$link) die('coud not connect to mysql');mysql_select_db("testDb") or die('coud not coonect to data base' .mysql_error());mysql_query("SET NAMES 'utf8'"); $query="select model from production where id=$search";$result=mysql_query($query) or die("query failed:".mysql_error());$row=mysql_fetch_array($result);$modelValue=$row['model'];mysql_free_result($result);mysql_close($link);?> Link to comment Share on other sites More sharing options...
Ingolme Posted November 26, 2011 Share Posted November 26, 2011 PHP doesn't interact with the page. In order to detect a button being pressed, put the button in a form and set the action attribute of the form to the URL of the PHP page that processes the data. Link to comment Share on other sites More sharing options...
comptech Posted November 26, 2011 Author Share Posted November 26, 2011 i write this but doesnt work: <?phpfunction f(){$search=$_POST['search']; $link=mysql_connect('localhost','root','3580');if(!$link) die('coud not connect to mysql');mysql_select_db("testDb") or die('coud not coonect to data base' .mysql_error());mysql_query("SET NAMES 'utf8'");$query="select model from production where id=$search";$result=mysql_query($query) or die("query failed:".mysql_error());$row=mysql_fetch_array($result);$modelValue=$row['model']; mysql_free_result($result);mysql_close($link);}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title> </head><body><form action="t3.php" method="post"> <input type="button" value="serach1" onclick="f()"/> <input type="text" name="search" value="" /> <br /><br /> <input type="text" name="modelValue" value="<?php echo($modelValue); ?>" /></form></body></html> Link to comment Share on other sites More sharing options...
Ingolme Posted November 26, 2011 Share Posted November 26, 2011 PHP does not recognize events. It stops running as soon as the page finishes loading. PHP runs on the server, generates HTML, and sends the HTML to the client. If you want to run a certain PHP script when something is clicked, just link to a page that runs that script. <a href="file.php">Do something</a> And in file.php put the code that you want to execute. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.