Jump to content

quick form help


pratkal

Recommended Posts

you can use something like this. it will concatenate each element of $_POST['category'] seprated by comma an return the string.Now you can use $categories to insert it into databse.

$categories=implode(',',$_POST['category'],);

Link to comment
Share on other sites

  • Replies 64
  • Created
  • Last Reply

lets just forget everything and pls create me the codethe html values are

<!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="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="categories1"></label>	<input name="categories1" type="checkbox" id="categories1" value="Science" />	<label for="categories1">Science</label>	<input name="categories2" type="checkbox" id="categories2" value="Math" />	<label for="categories1">Math</label>	<input name="categories3" type="checkbox" id="categories3" value="physics" />	<label for="categories1">Physics</label>  </p>  <p>	<input type="submit" name="send" id="send" value="Submit" />  </p></form></body></html>

sql username is $dbuser password is $dbpassword database host is $dbhost database name is $dbnamevale for tables are

	Field	Type	Collation	Attributes	Null	Default	Extra	Action	id	int(11)			No	None	AUTO_INCREMENT	 	 	 	 	 	 		username	varchar(25)	latin1_swedish_ci		No	None		 	 	 	 	 	 	 	password	varchar(25)	latin1_swedish_ci		No	None		 	 	 	 	 	 	 	fname	varchar(25)	latin1_swedish_ci		No	None		 	 	 	 	 	 	 	lname	varchar(25)	latin1_swedish_ci		No	None		 	 	 	 	 	 	 	mobile	int(10)			No	None		 	 	 	 	 	 		telephone	int(10)			No	None		 	 	 	 	 	 		address	varchar(100)	latin1_swedish_ci		No	None		 	 	 	 	 	 	 	email	varchar(100)	latin1_swedish_ci		No	None		 	 	 	 	 	 	 	messages	varchar(100)	latin1_swedish_ci		No	None		 	 	 	 	 	 	 	categories	varchar(100)	latin1_swedish_ci		No	None

some 1 please create me php code to feath this data and save it in mysql

Link to comment
Share on other sites

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUE '', '', '', '', '', '', '', '', '', '') ' at line 4current 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"];$aboutme = $_POST["aboutme"];$address = $_POST["address"];$username = $_POST["username"];$password = $_POST["password"];$npassword = md5($password);$catogries=serialize($_POST['catogries']);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, addressVALUE'$fname', '$lname', '$username', '$npassword', '$email', '$mobile', '$telephone', '$categories', '$aboutme', '$address'))"; mysql_query ($SQL,$con) or exit(mysql_error());mysql_close($con);?>

Link to comment
Share on other sites

you can use something like this. it will concatenate each element of $_POST['category'] seprated by comma an return the string.Now you can use $categories to insert it into databse.
$categories=implode(',',$_POST['category'],);

dreamweaver is giving syntex error for this codeerror on serverParse error: syntax error, unexpected ')' in /home/goaddwor/public_html/test/registeruser.php on line 19code error in phpmyadmin
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUE 'prateek', 'kalra', 'abcd', 'mypass', 'abcd@abcd.com', '9425093602', '251' at line 4INSERT INTO user(fname,lname,username,PASSWORD ,email,mobile,telephone,categories,messages,addressVALUE 'prateek','kalra','abcd','mypass','abcd@abcd.com','4151244','4425455822','Math','djsjdsjdjscjsj','djskdjksdjsjdjscjjcs'))

why is password is highlighted

Link to comment
Share on other sites

you are so close you can make that on your own. just stick with the previous approach.bracet sequnce wre wrong $SQL. it should work now...

$SQL = "INSERT INTO user(fname, lname, username, password, email, mobile, telephone, categories, messages, address)VALUE('$fname', '$lname', '$username', '$npassword', '$email', '$mobile', '$telephone', '$categories', '$aboutme', '$address')";

dreamweaver is giving syntex error for this codeerror on serverParse error: syntax error, unexpected ')' in /home/goaddwor/public_html/test/registeruser.php on line 19
sorry! there was a typo. it should be..
$categories=implode(',',$_POST['category']);

Link to comment
Share on other sites

your checkboxes should as below <label for="catogries"></label> <input type="checkbox" id="catogries[]" value="Science" /> <label for="catogries">Science</label> <input type="checkbox" id="catogries[]" value="Math" /> <label for="catogries">Math</label> <input type="checkbox" id="catogries[]" value="physics" /> <label for="catogries">Physics</label>

Link to comment
Share on other sites

Actually bit of mixing of label referencing here, because you are using label for each, it would be better

 <p><input type="checkbox" name="catogries[]" id="catogries1"  value="Science" /><label for="catogries1">Science</label><input type="checkbox" name="catogries[]" id="catogries2"  value="Math" /><label for="catogries2">Math</label><input type="checkbox" name="catogries[]"  id="catogries3" value="physics" /><label for="catogries3">Physics</label></p>

think this is what you meant?

Link to comment
Share on other sites

ok coded something else now ahead but got end up with an errorfirst code

<?phpinclude 'config.php';$con = mysql_connect("$dbhost","$dbuser","$dbpass");if (!$con) {	echo "Unable to connect to DB: " . mysql_error();	exit;}mysql_select_db("$dbname");if (!mysql_select_db("$dbname")) {	echo "Unable to select mydbname: " . mysql_error();	exit;}$sql = "SELECT * FROM `user` WHERE `id`";$result = mysql_query($sql) or exit . mysql_error();if (!$result) {	echo "Could not successfully run query ($sql) from DB: " . mysql_error();	exit;}$row = mysql_fetch_assoc($result);// While a row of data exists, put that row in $row as an associative array// Note: If you're expecting just one row, no need to use a loop// Note: If you put extract($row); inside the following loop, you'll//	   then create $userid, $fullname, and $userstatusmysql_free_result($result);	echo $row["id"];	echo $row["fname"];	echo $row["lname"];	echo $row["mobile"];?>

when i visit httP;//mydomain.com/id.php?id=1then result is 1prateekkalra2828832which is correctbut when i inserthttP;//mydomain.com/id.php?id=6then i get the same details again while id 6 details is not same

Link to comment
Share on other sites

it doesn't look like you're even using the id value of the query string (id=1) in your sql query at all. I'm guessing your just getting the first record (1prateekkalra2828832) by default.Note: if you are passing data via url query string, the array type you would want to use is $_GET, whereas it appears you have been using $_POST throughout your code examples. Just an FYI.

Link to comment
Share on other sites

it doesn't look like you're even using the id value of the query string (id=1) in your sql query at all. I'm guessing your just getting the first record (1prateekkalra2828832) by default.Note: if you are passing data via url query string, the array type you would want to use is $_GET, whereas it appears you have been using $_POST throughout your code examples. Just an FYI.
can u explain please i am just learning php and mysql you can be correct but i dont get a thing you said D:
Link to comment
Share on other sites

it doesn't look like you're even using the id value of the query string (id=1) in your sql query at all. I'm guessing your just getting the first record (1prateekkalra2828832) by default.Note: if you are passing data via url query string, the array type you would want to use is $_GET, whereas it appears you have been using $_POST throughout your code examples. Just an FYI.
can u explain please i am just learning php and mysql you can be correct but i dont get a thing you said D:
Link to comment
Share on other sites

well, you are making a query to database

$sql = "SELECT * FROM `user` WHERE `id`";

but you aren't passing an actual id. The point of the ID that you are passing

httP;//mydomain.com/id.php?id=6

is that you use it to identify a specific user in the table. you should be writing something like

$sql = "SELECT * FROM `user` WHERE `id` = $_GET['id']";

anyway, it seems like you should just go back through the tutorials, it seems like you're almost there though.http://www.w3schools.com/php/php_forms.asp and the next two chapters that followhttp://www.w3schools.com/php/php_mysql_where.asp

Link to comment
Share on other sites

To interpolate an array value inside double quotes, it must be surrounded by curly braces. Without them, you get the syntax error. This would be correct:$sql = "SELECT * FROM `user` WHERE `id` = {$_GET['id']}";Note also, if the data type of id is string, the value must be enclosed in quotation marks:$sql = "SELECT * FROM `user` WHERE `id` = '{$_GET['id']}'";

Link to comment
Share on other sites

To interpolate an array value inside double quotes, it must be surrounded by curly braces. Without them, you get the syntax error. This would be correct:$sql = "SELECT * FROM `user` WHERE `id` = {$_GET['id']}";Note also, if the data type of id is string, the value must be enclosed in quotation marks:$sql = "SELECT * FROM `user` WHERE `id` = '{$_GET['id']}'";
worked but i got a qi read somewhere that$_GET is used to get data from form so how it worked here???
Link to comment
Share on other sites

if your form "method" attribute is set to "get" it will be sent as "get..if "post it will be sent as "post"when you send a data to a form it will be available to the $_GET or $_POST superglobal array of php depending on the method.if you propogate data to the url like somepage.php?name=value&anothername=value the name value pair (data) will be sent as GET so it will be available in $_GET array

Link to comment
Share on other sites

few questions1- how to get data in valuei am using values to store data to sql for ex Math = 1 Science = 2Bio = 3Computers = 4now whenever i call this data i want the php to show result as the name instead of values how i do this ?????q-2 which loop is betteri have created a page i want to create a pre created search type page where i show lots of result each page contain a max 50 results but my quetion is how to loop the ids???? from 1-50 which contain specfic values for ex stream = math , science , bio , computers ( always stream will create the result )

Link to comment
Share on other sites

Q1) If only listing 4 text results, use Array or not create table with id reference to subject name, and join the two table and show, subject name from table two, whose subject_id reference equals subject id value from table user.$subject_array = array('Math', 'Science', 'Bio', 'Computers')$array_index=0;while(....){$array_index=($myrow['user_subjectid'])-1; //array index start at 0, so subtract 1 from user_subjectid valueecho $subject_array[$array_index]}q2) is more complicated, as you need to know which page you are viewing (1 of 10 or 2 of 10 etc), group of records (1 to 50, 51 to 100), and send this information, with search value, to next/prev page when you move through listed records, I have done this before, i'll try to find script.

Link to comment
Share on other sites

ok was able to do the part but script now become buggyfirst the code

<?phpinclude 'config.php';$con = mysql_connect("$dbhost","$dbuser","$dbpass");if (!$con) {	echo "Unable to connect to DB: " . mysql_error();	exit;}mysql_select_db("$dbname");if (!mysql_select_db("$dbname")) {	echo "Unable to select mydbname: " . mysql_error();	exit;}$sql = "SELECT * FROM `user` WHERE `stream` = {$_GET['stream']}";$result = mysql_query($sql) or exit . mysql_error();$row = mysql_fetch_assoc($result);$stream[0]="Math";$stream[1]="Science";$stream[2]="Physics";$stream[3]="Chemistry";$stream[4]="Computers Basic";$stream[5]="Computer laungages";$stream[6]="Computer Hardware";$stream[7]="English";$stream[8]="Hindi";$stream[9]="Sanskrit";// While a row of data exists, put that row in $row as an associative array// Note: If you're expecting just one row, no need to use a loop// Note: If you put extract($row); inside the following	 loop, you'll//	   then create $userid, $fullname, and $userstatuswhile ($row = mysql_fetch_assoc($result)) {echo $row['id'] . "<BR>";echo $row['name'] . "<BR>";echo $row['email'] . "<BR>";echo $row['Contact'] . "<BR>";echo $stream[$_GET['stream']];}mysql_close($con);?>

no metter how many entries in there for stream = 0( in the script math ) it is able to display but it fail to display for any other streams

Link to comment
Share on other sites

i am not sure about the problem....

no metter how many entries in there for stream = 0( in the script math ) it is able to display but it fail to display for any other streams
can you elaborate more?
Link to comment
Share on other sites

Archived

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


×
×
  • Create New...