Form help with php

General discussions related to php

Moderators: macek, egami, gesf

HueJorgan
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Jan 29, 2003 11:00 am

Form help with php

Postby HueJorgan » Wed Jan 29, 2003 11:41 am

I am making a simple site with php that accepts a last name from the visitor and prints out the corresponding extension number for that name. I am accessing a database for this. I have that part all set. The part I am having trouble with is the calling of the function I need to use from the HTML. It might be the placement of the php too, I am not really sure. Here is the code:


<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
</head>

<body>

<?php

function go()
{
echo "here";
$result = mysql_query("SELECT * FROM main WHERE NAME = namefield.value",$db);
//numfield = mysql_result($result,0,"EXTENSION");
}


$db = mysql_connect("localhost", "root");
mysql_select_db("phonelist",$db);

?>
<p>&</p>
<p>Last Name <input type="text" name="namefield" size="20"><input type="submit" value="Submit" name="click" onClick="php:go()">
<p>Extension <input type="text" name="numfield" size="17"></p>

</body>

</html>

Any help would be greatly appreciated.

Thanks.
Matt

TheIceman5
New php-forum User
New php-forum User
Posts: 28
Joined: Tue Jan 21, 2003 9:31 pm
Contact:

Postby TheIceman5 » Thu Jan 30, 2003 1:07 am

change it to this, and change page.php to the name of your script. this should work.

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
</head>

<body>

<?php

if($_POST["action"]=="update"){
echo "here";
$db = mysql_connect("localhost", "root");
mysql_select_db("phonelist",$db);
$result = mysql_query("SELECT * FROM main WHERE NAME = '".$_POST["namefield"]."'",$db);
//numfield = mysql_result($result,0,"EXTENSION");
}

?>
<p>&</p>
<form name="form1" action="page.php" method=post>
<p>Last Name <input type="text" name="namefield" size="20"><input type="submit" value="Submit" name="click">
<p>Extension <input type="text" name="numfield" size="17">
<input type="hidden" name="action" value="update"></p>
</form>

</body>

</html>

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Fri Jan 31, 2003 1:25 am

from HueJorgan's example there were no <form> tags.

TheIceman5
New php-forum User
New php-forum User
Posts: 28
Joined: Tue Jan 21, 2003 9:31 pm
Contact:

Postby TheIceman5 » Fri Jan 31, 2003 1:55 am

Redcircle wrote:from HueJorgan's example there were no <form> tags.


meaning??

well im my example there is no 'go' function.

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Fri Jan 31, 2003 2:00 am

no <form> tag meaning your browser does not know how to encode the information you are submitting. If you use Iceman's example it should work granted you output the query result out to the browser.

HueJorgan
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Jan 29, 2003 11:00 am

Postby HueJorgan » Mon Feb 03, 2003 5:13 am

OK,
That code is linking the site to php code which is the major part of what I was trying to accomplish. But, I still need to fill the input field "numfield" with the first result in the resultset.

The code I had previously was numfield = mysql_result($result,0,"EXTENSION"); but that was giving me all sorts of errors. Any ideas?? Thanks Alot.

Matt


Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 2 guests