Jump to content

quick form help


pratkal

Recommended Posts

ok guys first thanks for all for helping me on old post now i am still learning and want an helpi want to create a form First Field - NameSecond Field - EmailThird Field - i am a <checkbox here> Male <checkbox here>Femalei know i can do it easily by taking a multiple options box but i wana learn anyhow i am planing to store them into database $dbname table user table data - name , email , ###### please tell me how to create this form also tell me how i make sure that the user who send the details only send legit info for ex he put only email in email feilds for ex - abcd@abcd.com i am able to create the feld but user can enter any text item in it thanks

Link to comment
Share on other sites

  • Replies 64
  • Created
  • Last Reply

Concerning $_POST, it's the same as anything else. If they check the box, $_POST will have an entry with the checkbox's name where the value will be whatever value you set for the checkbox. The main difference between checkboxes and other inputs are that if the box was not checked, then the item is not in $_POST at all. So you can use the isset function to see if they checked the box.

Link to comment
Share on other sites

Do you really mean checkbox? Male-or-female is usually a pair of radio buttons.
Unless their between operations, or born with both key and keyhole, someone must have brought some sort of court action so you have to the option to select both, because of this...???
Link to comment
Share on other sites

well was able to run the other thing just a quick help to find whats wrong in my new code

<?phpinclude '../config.php';$con = mysql_connect("$dbhost","$dbuser","$dbpass");if (!$con)  {  die('Could not connect: ' . mysql_error());  }else  {  echo "user Created ";  }//this will fetch the data from the form $fname = $_POST["fname"];$lname = $_POST["lname"];$email = $_POST["email"];$username = $_POST["username"];$password = $_POST("password");$npassword = md5($password);//this will connect to database and post the info in tablesmysql_select_db("$dbname", $con);mysql_query("INSERT INTO admin (fname, lname, username, password, email)VALUES ('$fname', '$lname', '$username', '$npassword', '$email')");mysql_close($con);?>

error i get trying to run the codeFatal error: Function name must be a string in /home/goaddwor/public_html/test/install/install.php on line 19the html code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title></head><body><form id="form1" name="form1" method="post" action="install.php">  <p>	<label for="fname">first name</label>	<input type="text" name="fname" id="fname" />  </p>  <p>	<label for="lname">last name</label>	<input type="text" name="lname" id="lname" />  </p>  <p>	<label for="email">email</label>	<input type="text" name="email" id="email" />  </p>  <p>	<label for="username"></label>	<label for="username">username</label>	<input type="text" name="username" id="username" />  </p>  <p>	<label for="password">password</label>	<input type="password" name="password" id="password" />  </p>  <p>	<input type="submit" name="send" id="send" value="Submit" />  </p></form></body></html>

Link to comment
Share on other sites

thanks :)you might gona hate me but im asking a old que again

 <?phpinclude '../config.php';$con = mysql_connect("$dbhost","$dbuser","$dbpass");if (!$con)  {  die('Could not connect: ' . mysql_error());  }else  {  echo "Table in database created please click continue to go to next step ";  }// Create tablemysql_select_db("$dbname");$sql1 = "CREATE TABLE admin(id INT NOT NULL AUTO_INCREMENT,PRIMARY KEY(id),username varchar(100) NOT NULL,password varchar(100)NOT NULL,fname varchar(100) NOT NULL,lname varchar(100) NOT NULL,email varchar(100) NOT NULL,)";mysql_query($sql, $con) or exit(mysql_error());$sql2 = "CREATE TABLE user(id INT NOT NULL AUTO_INCREMENT,PRIMARY KEY(id),username varchar(25) NOT NULL,password varchar(25)NOT NULL,fname varchar(25) NOT NULL,lname varchar(25) NOT NULL,###### varchar(10) NOT NULL,mobile varchar(10) NOT NULL,telephone varchar(10) ,address varchar(100) NOT NULL,email varchar(100) NOT NULL,messages varchar(500) NOT NULL,)";mysql_query($sql, $con) or exit(mysql_error());$sql3 = "CREATE TABLE registrant(id INT NOT NULL AUTO_INCREMENT,PRIMARY KEY(id),username varchar(25) NOT NULL,password varchar(25)NOT NULL,fname varchar(25) NOT NULL,lname varchar(25) NOT NULL,mobile varchar(10) NOT NULL,telephone varchar(10) ,address varchar(100) NOT NULL,email varchar(100) NOT NULL,)";mysql_query($sql, $con) or exit(mysql_error());mysql_close($con);?>

this is last code i need help in today i swear ( i only scripted this 3 codes yet lol )

Link to comment
Share on other sites

that still did create issue anyhow i fix the above code my selfnow the main code i am having the issue with

<?phpinclude 'config.php';$con = mysql_connect("$dbhost","$dbuser","$dbpass");if (!$con)  {  die('Could not connect: ' . mysql_error());  }//this will fetch the data from the form $fname = $_POST["fname"];$lname = $_POST["lname"];$email = $_POST["email"];$###### = $_POST["######"];$mobile = $_POST["mobile"];$telephone = $_POST["telephone"];$categories = $_POST["catogries"];$aboutme = $_POST["aboutme"];$address = $_POST["address"];$username = $_POST["username"];$password = $_POST["password"];$npassword = md5($password);echo $_POST['catogries'];//this will connect to database and post the info in tablesmysql_select_db("$dbname");$SQL = "INSERT INTO user (fname, lname, username, password, email, ######, mobile, telephone, catogries, message)VALUES ('$fname', '$lname', '$username', '$npassword', '$email', '$######', '$mobile', '$telephone', '$catogries', '$aboutme'))"; mysql_query ($SQL,$con);mysql_close($con);?>

the html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title></head><body><form id="form1" name="form1" method="post" action="registeruser.php">  <p>	<label for="fname">First name</label>	<input type="text" name="fname" id="fname" />  </p>  <p>	<label for="lname">Last Name</label>	<input type="text" name="lname" id="lname" />  </p>  <p>	<label for="email">email</label>	<input type="text" name="email" id="email" />  </p>  <p>	<label for="username">username</label>	<input type="text" name="username" id="username" />  </p>  <p>	<label for="password">password</label>	<input type="password" name="password" id="password" />  </p>  <p>######	<label for="######"></label>	<select name="######" id="######">	  <option value="male">Male</option>	  <option value="female">Female</option>	</select>  </p>  <p>	<label for="mobile">Mobile</label>	<input type="text" name="mobile" id="mobile" />  </p>  <p>	<label for="telephone">Telephone</label>	<input type="text" name="telephone" id="telephone" />  </p>  <p>	<label for="address">Address Include city n state</label>	<textarea name="address" id="address" cols="45" rows="5"></textarea>  </p>  <p>	<label for="aboutme">About you</label>	<textarea name="aboutme" id="aboutme" cols="45" rows="5"></textarea>  </p>  <p> </p>  <p>catogries</p>  <p>	<label for="catogries"></label>	<input name="catogries" type="checkbox" id="catogries" value="Science" />	<label for="catogries">Science</label>	<input name="catogries" type="checkbox" id="catogries" value="Math" />	<label for="catogries">Math</label>	<input name="catogries" type="checkbox" id="catogries" value="physics" />	<label for="catogries">Physics</label>  </p>  <p>	<input type="submit" name="send" id="send" value="Submit" />  </p></form></body></html>

Link to comment
Share on other sites

that still did create issue anyhow i fix the above code my selfnow the main code i am having the issue with

<?phpinclude 'config.php';$con = mysql_connect("$dbhost","$dbuser","$dbpass");if (!$con)  {  die('Could not connect: ' . mysql_error());  }//this will fetch the data from the form $fname = $_POST["fname"];$lname = $_POST["lname"];$email = $_POST["email"];$###### = $_POST["######"];$mobile = $_POST["mobile"];$telephone = $_POST["telephone"];$categories = $_POST["catogries"];$aboutme = $_POST["aboutme"];$address = $_POST["address"];$username = $_POST["username"];$password = $_POST["password"];$npassword = md5($password);echo $_POST['catogries'];//this will connect to database and post the info in tablesmysql_select_db("$dbname");$SQL = "INSERT INTO user (fname, lname, username, password, email, ######, mobile, telephone, catogries, message)VALUES ('$fname', '$lname', '$username', '$npassword', '$email', '$######', '$mobile', '$telephone', '$catogries', '$aboutme'))"; mysql_query ($SQL,$con);mysql_close($con);?>

the html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title></head><body><form id="form1" name="form1" method="post" action="registeruser.php">  <p>	<label for="fname">First name</label>	<input type="text" name="fname" id="fname" />  </p>  <p>	<label for="lname">Last Name</label>	<input type="text" name="lname" id="lname" />  </p>  <p>	<label for="email">email</label>	<input type="text" name="email" id="email" />  </p>  <p>	<label for="username">username</label>	<input type="text" name="username" id="username" />  </p>  <p>	<label for="password">password</label>	<input type="password" name="password" id="password" />  </p>  <p>######	<label for="######"></label>	<select name="######" id="######">	  <option value="male">Male</option>	  <option value="female">Female</option>	</select>  </p>  <p>	<label for="mobile">Mobile</label>	<input type="text" name="mobile" id="mobile" />  </p>  <p>	<label for="telephone">Telephone</label>	<input type="text" name="telephone" id="telephone" />  </p>  <p>	<label for="address">Address Include city n state</label>	<textarea name="address" id="address" cols="45" rows="5"></textarea>  </p>  <p>	<label for="aboutme">About you</label>	<textarea name="aboutme" id="aboutme" cols="45" rows="5"></textarea>  </p>  <p> </p>  <p>catogries</p>  <p>	<label for="catogries"></label>	<input name="catogries" type="checkbox" id="catogries" value="Science" />	<label for="catogries">Science</label>	<input name="catogries" type="checkbox" id="catogries" value="Math" />	<label for="catogries">Math</label>	<input name="catogries" type="checkbox" id="catogries" value="physics" />	<label for="catogries">Physics</label>  </p>  <p>	<input type="submit" name="send" id="send" value="Submit" />  </p></form></body></html>

got 2 issue with the code1- no data inserted into the table2- only 1 of 3 catogries is showing if i select 2 box or 1 but i am able to get ###### correct way

Link to comment
Share on other sites

When more than one form input has the same name, the data will be sent, but your $_POST array can only have one index by that name. So each value for that index overwrites the previous one, leaving you with the last value only.The solution is to name your checkboxes like this: name="catogries[]"This creates an autoindexing subarray named catogries. Access the data like this:$_POST['catogries'][0]$_POST['catogries'][1]$_POST['catogries'][2] If the length of $_POST['catogries'] is less than 3 (meaning, the user did not select all of them) you cannot tell what the values are without inspecting them.

Link to comment
Share on other sites

what is your current code after deirdre's dad's sugestion? can you show that?

Link to comment
Share on other sites

<?phpinclude 'config.php';$con = mysql_connect("$dbhost","$dbuser","$dbpass");if (!$con) { die('Could not connect: ' . mysql_error()); }//this will fetch the data from the form $fname = $_POST["fname"];$lname = $_POST["lname"];$email = $_POST["email"];$###### = $_POST["######"];$mobile = $_POST["mobile"];$telephone = $_POST["telephone"];$categories = $_POST['catogries'][0];$categories = $_POST['catogries'][1];$categories = $_POST['catogries'][2];$aboutme = $_POST["aboutme"];$address = $_POST["address"];$username = $_POST["username"];$password = $_POST["password"];$npassword = md5($password);echo $_POST['catogries'];echo $_POST['######'];//this will connect to database and post the info in tablesmysql_select_db("$dbname");$SQL = "INSERT INTO user (fname, lname, username, password, email, ######, mobile, telephone, catogries, message)VALUES ('$fname', '$lname', '$username', '$npassword', '$email', '$######', '$mobile', '$telephone', '$catogries', '$aboutme'))"; mysql_query ($SQL,$con);mysql_close($con);?>

Link to comment
Share on other sites

$categories = $_POST['catogries'][0];$categories = $_POST['catogries'][1];$categories = $_POST['catogries'][2];

here its everytime overwriting the variable $category. It does not matter what you had passed in the checkbox. It will always try to insert $_POST['catogries'][2]if your query is failing you can always use mysql_error() to confirm why the error is occuring.

VALUES('$fname', '$lname', '$username', '$npassword', '$email', '$######', '$mobile', '$telephone', '$catogries', '$aboutme'))";
there is a problem in the variable name $catogries. it is not defined. check the spelling
$categories = $_POST['catogries'][2];
Link to comment
Share on other sites

k updated still same issue also if the code will not work how to make it to get all the data from checkboxes?? and yes it always get last selected checkboxYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 8UPDATED THE CODE and fix 1 typo mistake now it got no typo mistake in code

<?phpinclude 'config.php';$con = mysql_connect("$dbhost","$dbuser","$dbpass");if (!$con)  {  die('Could not connect: ' . mysql_error());  }//this will fetch the data from the form $fname = $_POST["fname"];$lname = $_POST["lname"];$email = $_POST["email"];$mobile = $_POST["mobile"];$telephone = $_POST["telephone"];$categories = $_POST['categories'][0];$categories = $_POST['categories'][1];$categories = $_POST['categories'][2];$aboutme = $_POST["aboutme"];$address = $_POST["address"];$username = $_POST["username"];$password = $_POST["password"];$npassword = md5($password);echo $_POST['categories'];//this will connect to database and post the info in tablesmysql_select_db("$dbname");$SQL = "INSERT INTO user (fname, lname, username, password, email, mobile, telephone, categories, messages, address)VALUES ('$fname', '$lname', '$username', '$npassword', '$email', '$mobile', '$telephone', '$categories', '$aboutme', '$address'))"; mysql_query ($SQL,$con) or exit(mysql_error());mysql_close($con);?>

also can this work?

$categories1 = $_POST['categories1'];$categories2 = $_POST['categories2'];$categories3 = $_POST['categories3'];$categories = $categories1 + $categories2 + $categories3 ;

here values for categories1 = Science categories2 = physicscategories3 = math

Link to comment
Share on other sites

if you are using checkbox multiple option can be selected/inserted so i am not sure how did you plan to insert those. here. I am not sure your purpose so may be you need to use implode() or serialize() or extra column for storing the other categories to store the all checked data to the database.as from your code its the same as before. it will overwrite the data of $categories whatever you pass.and you have a extra bracet in $sql. removing it should fix the mysql error.

Link to comment
Share on other sites

<?phpinclude 'config.php';$con = mysql_connect("$dbhost","$dbuser","$dbpass");if (!$con) { die('Could not connect: ' . mysql_error()); }//this will fetch the data from the form $fname = $_POST["fname"];$lname = $_POST["lname"];$email = $_POST["email"];$mobile = $_POST["mobile"];$telephone = $_POST["telephone"];$categories = $_POST['categories'][0];$categories = $_POST['categories'][1];$categories = $_POST['categories'][2];$aboutme = $_POST["aboutme"];$address = $_POST["address"];$username = $_POST["username"];$password = $_POST["password"];$npassword = md5($password);echo $_POST['categories'];//this will connect to database and post the info in tablesmysql_select_db("$dbname");$SQL = "INSERT INTO user (fname, lname, username, password, email, mobile, telephone, categories, messages, addressVALUES '$fname', '$lname', '$username', '$npassword', '$email', '$mobile', '$telephone', '$categories', '$aboutme', '$address'))"; mysql_query ($SQL,$con) or exit(mysql_error());mysql_close($con);?>better?

Link to comment
Share on other sites

if you use checkboxes and they pass multiple values as man,female,notsure, (as a Array) and you useVALUES ('$fname', '$lname', '$username', '$npassword', '$email', '$######', '$mobile', '$telephone', '$catogries', '$aboutme'))";in catogries you will get something like Array showing instead. you need to use serialize(), to convert the checkbox array into a readable format for the database, and unserialize() to read back the serialize() content.$catogries=serialize($_POST['catogries']);$DB_catogries = unserialize($myrow['catogries']);

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...