Page 1 of 1

How do you handle non-text/textarea form inputs?

Posted: Tue Nov 12, 2002 7:20 pm
by mezzanine
Hi, I have a form which I use to feed a mySQL database through PHP code and the text inputs on the form are working beautifully but using the same technique on other inputs (i.e. my SELECT, radio buttons and checkbox) gives a blank result in the database. Please help! I read something about arrays but it scared me so I ran away :oops:

View the page by following the links from here to the online form: www-stu.sel.cam.ac.uk/societies/scms/indexjoin.html (sorry about frames and clumsy formatting/coding/general rubbishness this was my first ever page!)

Thanks in advance for your help! :-)

Here is the relevant code 1)/////////////From the HTML form:

<form name="application" method="post" action="form.php">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Forename&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Surname
<br>
<SELECT NAME="Title[]" SIZE="1">
<OPTION SELECTED>Mr.
<OPTION>Mrs.
<OPTION>Ms.
<OPTION>Miss.
<OPTION>Dr.
<OPTION>Prof.
<OPTION>Rev.
</SELECT>&nbsp;
<INPUT TYPE="text" NAME="forename" SIZE="30" >
<INPUT TYPE="text" NAME="surname" SIZE="30">
<br><br>
<INPUT TYPE="radio" NAME="type" VALUE="Student">&nbsp; Selwyn Student
<br>
<INPUT TYPE="radio" NAME="type" VALUE="Fellow">&nbsp; Fellow/Fellow's Partner
<br>
<INPUT TYPE="radio" NAME="type" VALUE="External"> &nbsp;External (non-Selwyn)
<br>
<br>Contact telephone number&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;E-mail address
<br>
<INPUT TYPE="text" NAME="phone" SIZE="30">
<INPUT TYPE="text" NAME="email" SIZE="30">
<br><br><hr width=100%><i>For external members only</i><br><br>Address including postcode<br>
<TEXTAREA NAME="address" ROWS=6 COLS=30>
</TEXTAREA>
<br><br><hr width=100%><i>For student members only</i><br><br>Instrument(s) played and approximate standard reached<br>
<TEXTAREA NAME="instruments" ROWS=6 COLS=30>
</TEXTAREA>
<br><INPUT TYPE="checkbox" NAME="interested" VALUE="yes">I would be interested in playing in future SCMS orchestral concerts
<br><br><hr width=100%><br>

2)//////////////////////from the php script page

<?php
$dbconnect=mysql_connect("localhost", "scms", "Changeme");
if (!$dbconnect)
{echo("<p>Unable to connect to the database server at this time.</p>"); exit();}
else {echo("<p>Connected to mySQL database on server...</p>");}
mysql_select_db("scms");
if (!@mysql_select_db("scms") )
{echo("<p>Unable to locate the SCMS database at this time.</p>"); exit();}
else {echo("<p>Using SCMS database...</p>");}
$sql="INSERT INTO scms SET
title='$title',
forename='$forename',
surname='$surname',
phone='$phone',
email='$email',
type='$type',
address='$address',
instruments='$instruments',
interested='$interested'";

if (@mysql_query($sql))
{echo("<p>Succesful!</p>");}
else {echo("<p>Error:" . mysql_error() . "</p>");}
?>

Posted: Wed Nov 13, 2002 3:21 am
by volka
use

Code: Select all

echo '&lt;pre&gt;'; print_r($_POST); echo '&lt;/pre&gt;';
at the top of your php-script to see what has been posted (and how php calls it ;) )
$_POST might be $HTTP_POST_VARS depending on your php-version