CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   text box (http://www.codingforums.com/showthread.php?t=283733)

gayathri 12-07-2012 09:24 AM

text box
 
Hi,
I did a php code for inserting and updating elements into the database.
Nw i want to do the coding for, When clicking the submit button, a messagebox with input field get open asking to enter the name.How shall i do this please any1 help me. :)

Custard7A 12-07-2012 09:37 AM

You can do that with Javascript instead. At that point you are still waiting for the user to enter some data, so you would want them to do so before sending it off to be processed by your PHP script.

It may be more appropriate if the name input field is already avaliable to be filled-out. You should bear in mind that a submit button (in the format of a submit button) will usually be expected to submit the page, not progress to another step.

gayathri 12-07-2012 10:23 AM

I can understand. bt still i dont knw where to set the input field in the code. will u please tell it with an example.

Redcoder 12-07-2012 11:11 AM

You put Javascript code in HTML code. Then set an event trigger that will cause a message box(or prompt) to appear. Then set your PHP code to process the textbox/messagebox/prompt using $_POST.

I don't know whether you know any Javascript as you have not stated but check out documentation on Javascript here:

http://www.w3schools.com/js/default.asp

PHP $_POST:

http://www.w3schools.com/php/php_post.asp

http://php.net/manual/en/reserved.variables.post.php

You have not stated what exactly you know or don't know.

gayathri 12-07-2012 12:15 PM

I knw little bit in java script.
the following is a piece of my code. In this i dnt knw were to add to get input field i text box

Code:

<html>
<head>
<title>QBank</title>
</head>
<body>
<form name="Board" action="boards1.php" method="post">
id :<input type="text" name="sid">
name : <input type="text" name="sname"><br>
<table border="1">
<tr><th>Id</th><th>Name</th></tr>
<?
include("config.php");
$sql1="select * from Boards order by id";
$res1=mysql_query($sql1);
while($row = mysql_fetch_array($res1))
{
echo "<tr><td>$row[0]</td><td>$row[1]</td></tr>";
}
?>
</table>
<input type="submit" value="Save" name="insert" />
<input type="submit" value="update" name="update"/>
<input type="submit" value="clear" name="clr"/>
</form>
</body>
</html>

Code:

<?php
include("config.php");
$id=$_POST['sid'];
$name=$_POST['sname'];
$update=$_POST['update'];
//$save=$_POST['insert'];
echo $update." ".$id." ".$name." ";
/*if(($sav=="Save"))
{
echo "hai";

$sql="insert into Boards(id,name)values($id,'$name')";
$res=mysql_query($sql);
}*/
if(($update=="update"))
{
//echo "hai1";
$sql1="update Boards set name='$name' where id=$id";
echo $sql1;
$res1=mysql_query($sql1);
if($res1)
echo "<script>($res1)</script>";
}
?>

any1 please tell me

Custard7A 12-08-2012 12:51 AM

You should just create another <input type="text"... Creating a pop-up box in Javascript to gain additional data is quite flawed, without efficient fall-backs at least. Some people may have Javascript disabled and your form will then break.

gayathri 12-10-2012 02:47 AM

Thanks Custard7A and Redcoder for ur useful post. With ur ideas i did my code. And its working too. thanks :)


All times are GMT +1. The time now is 07:23 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.