I have written the following code and not able to figure out the errors in it..
It not poping out any errors ..what it does is that it just stays on the html page
whats wrong in it?
html page
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
function get(){
$("#button1").click(function(){
$.post('script_1.php', { name: form.name.value },
function(output) {
$('#age').html(output).show();
}) ;
});
}
$("#button2").click(function(){
$('form#myForm').attr({action: "script_2.php"});
$('form#myForm').submit();
});
});
</script>
</head>
<body>
<form id="myForm" method="post">
doi: <input type="text" name="name"/>
<input type="button" id="button1" value ="Get" onclick="get();"/>
<input type="button" id="button2" value="Submit to script 2" />
title:<input type="text" name="title"/>
</form>
<div id="age"></div>
</body>
</html>
script_1.php for the first button is
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL ^ E_NOTICE);
//connect to database
$name = mysql_real_escape_string($_POST['name']);
if ($name==NULL)
echo "please enter an id!";
else
{
$age= mysql_query("SELECT title FROM parentid WHERE id ='$name'");
$age_num_rows = mysql_num_rows($age);
if ($age_num_rows==0)
echo "id does not exist";
else
{
$sql ="SELECT * FROM parentid WHERE id = '$name'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$abc_output= "Existing data of the record <br />";
$abc_output .="Title: " . $row['title'] . "<br />" ;
$abc_output .="Report No: " . $row['reportno'] . "<br />" ;
$abc_output .="URL: " . $row['calc_url'] . "<br />" ;
$abc_output .="Institution: " . $row['institution'] . "<br />" ;
}
}
echo $abc_output;
}
}
?>
script_2.php is another php file
with update operation in database.
//title form is only used in script_2.php for updation.
script_1.php is used for displaying already present elements in DB.
Help appreciated.
There is a slight problem with your HTML and Javascript code. The way you declared the click functions, was improper. Try this:
Here are your two SQL queries that you asked for: