hi
i have a application where i have a text box when the user enters data in the text box i want the data to be inserted in the db and the value displayed in the same page.something like daniweb post quick reply.i know i have to use ajax but i did not acorrect code.please send some samole code .i am new to ajax
thanks.

Recommended Answers

All 8 Replies

why do you need to use ajax ?
you can do a simple postback which is alot easier.

if ajax is amust you must have some knowledge of javascript aswell.

can you be little brief......

??? sorry i dont quite understand what your asking ??

u said post back...do u mean PHP_SELF

<?
if(isset($_POST["yourname"])) {
  // Process database save
}
?>

<html>
    <body>
        <form action="<? echo $_SERVER['php_self']; ?>" method="post">
            <input type="text" name="yourname" />
            <input type="submit" value="enter data" />
        </form>
    </body>
</html>

my website link is
http://www.website.com/testing/detailforum.php?id=2
but when i use PHP_SELF ,the url changes to http://www.website.com/testing/detailforum.php
so i am getting the output

<?php

$link=mysql_connect($hostname, $username, $password);
mysql_select_db($dbid) or die("unable to connect");

$line=$_GET['id'];
$result=mysql_query("SELECT * FROM startp where postid='$line'");
for ($i = 0; $i < 1; ++$i)
{
$line = mysql_fetch_row($result);

echo "<table width='85%'  bgcolor='#D7D7D7'>";
print "<tr><td align='center'><font face='Times New Roman'  size='5'><strong> $line[1] </strong></font></td></tr>";
print "</table>";
print "<table width='85%'   bgcolor='#EBEBEB'>";
print "<tr><td></td></tr>";
print "<tr><td><font face='Times New Roman'  size='3'><strong><i>   Description</i></strong></font></td></tr>";
print "<tr><td width='1%'></td><td>$line[2]</td></tr>";
echo "</table>";

}
mysql_close($link);
?>
<?php

$link=mysql_connect($hostname, $username, $password);
mysql_select_db($dbid) or die("unable to connect");
if(isset($_POST["submit"])) {

$uname=$_SESSION['uname'];
$todays = date('Y-m-d h-i-s');
$message=$_REQUEST['message'];
$uname=$_REQUEST['uname'];
$linn=$line;
mysql_query("insert into replying(replytext,replyuser,postiid,replydate) values('$message','$uname','$linn','$todays')") or die ("ERROR:".mysql_error());
$result=mysql_query("select * from replying where postiid='$line' order by replydate DESC") or die ("ERROR:".mysql_error());
if($result)
{

while($row=mysql_fetch_array($result))
{
echo $row[0];
echo $row[1];
}
}
}
?>
 <form method="post" name="form2" action="<? echo $_SERVER['PHP_SELF']; ?>"
<input type="text" name="message">
<input type="text" name="uname">
<input type="submit" name="submit" value="submit">


</form>

thats correct you need to get the whole querystring aswell if you want to retain the querystring variable. E.G.

action="<? echo $_SERVER["REQUEST_URI"]; ?>"

thanks a lot!!!!!!!!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.