Hey guys, i just registered here. I have always read posts here but never thought to register.

Anyways, i am looking for some help with this script. So i have about 300 students that all need to be placed in option statements (html). I need these names then put into a drop down menu for students to choose. The issue is, i have maybe 30 questions, which means that i have a hell of a long script. Is there anyway using mysql to import these names whenever i need them into a drop down menu? Also i plan to get the script to submit to a mysql database, what is the easiest way to do that and will allow me to extract the choices the easiest?

And last thing i need to know how from those names i submit into the database to use them also in my verification script. I would liek to generate random passwords for all the users then have them printed out and handed out to the students for them to login. How can i get that done? Also how do i hook it up to a login page?

Thanks so much, Dani.

well i can make one for you please do let me know by email my email is info[at]kmwsoftech.com

is there no one here that can give me some help with this?

I don't wish to have the program written for me.....

Member Avatar for r4ccoon

its a basic php operation, you can learn it by your self..
first is create student table, after that create question table
and in your application you can loop the student in dropdown menu, and you can figure something

ok so basically i am making a questions table and a name table. Then running code to take that info and export to the survey. Any good places to learn this stuff?

So i have about 300 students that all need to be placed in option statements (html). I need these names then put into a drop down menu for students to choose.

If you have these 300 students info in a table, then just fetch their info by using loops. Say, for example, you have student table with their info. You get the dropdown by doing something like this.

<?php
$conn=mysql_connect($host,$username,$pass);
mysql_select_db($dbname);
$query="select student_name from student";
$result=mysql_query($query);
echo "<select name=\"student_name\">";
while($row=mysql_fetch_array($result)){
   echo "<option value=".$row['student_name'].">".$row['student_name']."</option>";    
}
....

This will put all the student names in the select box.

The issue is, i have maybe 30 questions, which means that i have a hell of a long script. Is there anyway using mysql to import these names whenever i need them into a drop down menu?

30 questions ? What 30 questions ? About your second question, yes, you can write a function and whenever you need values from the table, you can call that function.

Also i plan to get the script to submit to a mysql database, what is the easiest way to do that and will allow me to extract the choices the easiest?

If you want to submit the user's input to a table, you do it using an insert statement. When the user submits the page, the form variables are accessed as $_POST or $_GET depending upon the method you want.

And last thing i need to know how from those names i submit into the database to use them also in my verification script. I would liek to generate random passwords for all the users then have them printed out and handed out to the students for them to login. How can i get that done? Also how do i hook it up to a login page?

You will find a lot of scripts on the net to generate random password. If you want a simplest random password generator, have an array of alphanumerics. (a-z A-Z 0-9). Generate a random number and fetch that array element.

Cheers,
Nav

hi dan maybe u can check php.net theres a good resources to learn it, and u can download php manual there ....

If you have these 300 students info in a table, then just fetch their info by using loops. Say, for example, you have student table with their info. You get the dropdown by doing something like this.

<?php
$conn=mysql_connect($host,$username,$pass);
mysql_select_db($dbname);
$query="select student_name from student";
$result=mysql_query($query);
echo "<select name=\"student_name\">";
while($row=mysql_fetch_array($result)){
   echo "<option value=".$row['student_name'].">".$row['student_name']."</option>";    
}
....

This will put all the student names in the select box.


30 questions ? What 30 questions ? About your second question, yes, you can write a function and whenever you need values from the table, you can call that function.

If you want to submit the user's input to a table, you do it using an insert statement. When the user submits the page, the form variables are accessed as $_POST or $_GET depending upon the method you want.

You will find a lot of scripts on the net to generate random password. If you want a simplest random password generator, have an array of alphanumerics. (a-z A-Z 0-9). Generate a random number and fetch that array element.

Cheers,
Nav

Ok so about this i made the table and entered all the data. Its in a table called grads and there are rows called user_id. I want to retrieve user_id for the drop down menu.

also how do i now generate random passwords for everyone? I made a field called password in the mysql just i don't know how to generate the random password

Replace student_name with user_id in the query that I have given above. Then change, $row to $row.

As I said earlier, generating random password is easy. Check this site. Use that function in your script.

<!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>Etobicoke Collegiate Institute's Grad Survey 2008</title>
</head>

<body>
<form action="handle.php" method="post">

<fieldset><legend>Please complete the following questions. Thanks!</legend>

<label>1. Be on the price is right</label><br />
<select name="priceisright">
  <option value="">Please Choose One Person</option>
  <option value="">Not Voting</option>
  <?php
$conn=mysql_connect($host,$username,$pass);
mysql_select_db($dbname);
$query="select user_id from student";
$result=mysql_query($query);
echo "<select name=\"student_name\">";
while($row=mysql_fetch_array($result)){
   echo "<option value=".$row['user_id'].">".$row['student_name']."</option>";    
}

?>

</select>
<br />


</body>
</html>

But it doesnt seem to work. Sorry i am bugging you so much but i am quite new to php

I presume that you don't have much knowledge on php. You can go to w3schools and start learning the basics. But anyway, here is the script that you want. Make sure you enter the username and password correctly for your mysql connection,give the correct database name and specify the correct columns in the query.

<?php
$conn=mysql_connect("localhost","username","password"); 
mysql_select_db("student");
$query="select user_id,student_name from student";
$result=mysql_query($query);
$option="";
while($row=mysql_fetch_array($result)){
   $option.="<option value=".$row['user_id'].">".$row['student_name']."</option>";    
}
?>
<!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>Etobicoke Collegiate Institute's Grad Survey 2008</title>
</head>
<body>
<form action="handle.php" method="post">
<fieldset><legend>Please complete the following questions. Thanks!</legend>

<label>1. Be on the price is right</label><br />
<select name="priceisright">
  <option value="">Please Choose One Person</option>
  <option value="">Not Voting</option>
	<?php echo $option; ?>
</select>
<br />


</body>
</html>

Edit: If you encounter any errors, let me know.

Cheers,
Naveen

commented: jug jug jiyo =D +4

omg thats sick, thank you so much.

Now i need to put in the submit buttons and the login page.

So now, if i want to put the submit button, i want it to send back the info and that info would be an ip address using this script http://www.laughing-buddha.net/jon/php/remoteip/,

and i want it to fill in the value vote_status (the table is grads and the row is vote_Status) all i need is a simple change from the current 0 to a 1
so i can see who has voted and who hasn't.

How is that done?

Also if i have all the users and i need the passwords for them before they login, how do i get those generated using that script you showed me....

thanks again

EDIT: I fixed the 1 error i got so don't worry about that

In handle.php just add print_r($_POST); at the top. You will get all the values passed from the form. You can then update your table by setting 1 for that particular person. And, the password generation script is a function. You just call the function, assign the return value to a variable, use that variable. Eg. $pass=functionname();

:)

In handle.php just add print_r($_POST); at the top. You will get all the values passed from the form. You can then update your table by setting 1 for that particular person. And, the password generation script is a function. You just call the function, assign the return value to a variable, use that variable. Eg. $pass=functionname();

:)

But i don't have a handle.php yet :( :P

ok.. That's not a problem!

<?php print_r($_POST); ?>

call that handle.php. This will print all the form variables :D !

will that record the choices and add a 1 to the vote status
?

Nope. It will show all the form variables that are passed. You can then use it to record the choices.

well i tried that and all i get is Array ( [priceisright] => )


The code i have now is

<?php
$conn=mysql_connect("localhost.anblickstudios.com","bullseye","6cr39a.c"); 
mysql_select_db("gradsurvey");
$query="select user_id from grads";
$result=mysql_query($query);
$option="";
while($row=mysql_fetch_array($result)){
   $option.="<option value=".$row['grads'].">".$row['user_id']."</option>";    
}
?>
<!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>Etobicoke Collegiate Institute's Grad Survey 2008</title>
</head>
<body>
<form action="handle.php" method="post">
<fieldset><legend>Please complete the following questions. Thanks!</legend>

<label>1. Be on the price is right</label><br />
<select name="priceisright">
  <option value="">Please Choose One Person</option>
  <option value="">Not Voting</option>
	<?php echo $option; ?>
</select>
<br />
<input type="submit">


</body>
</html>

and handle.php is

<?php 
print_r($_POST); 
?>

so how would i get this working... as i said i really don't know much about php and mysql

* Do NOT display the host,username and password while posting in a public forum(Unless you want your database to be hacked!).
* You aren't closing your form.

Anyway, I think you should learn php and mysql first. Here is the script. Name it vote.php and run it. Change table name and the column names.

<?php
$conn=mysql_connect("localhost","username","password"); 
mysql_select_db("dbname");
$query="select user_id from grads";
$result=mysql_query($query);
$option="";
while($row=mysql_fetch_array($result)) {
   $option.="<option value=".$row['user_id'].">".$row['user_id']."</option>";    
}
if(isset($_POST['submit'])) {
$query="UPDATE TABLE SET VOTE = 1 WHERE USER_ID ='".$_POST['priceisright']."'";	
mysql_query($query);
}
?>
<!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>Etobicoke Collegiate Institute's Grad Survey 2008</title>
</head>
<body>
<form action="vote.php" method="post">
<fieldset><legend>Please complete the following questions. Thanks!</legend>

<label>1. Be on the price is right</label><br />
<select name="priceisright">
  <option value="">Please Choose One Person</option>
  <option value="">Not Voting</option>
	<?php echo $option; ?>
</select>
<br />
<input name="submit" value="submit" type="submit">
</form>
</body>
</html>

ok, so now that i have that, how do i add in a login page? Basically i just want the person to enter their user_id which is their name, and then i want them to enter their password which i will randomly generate....

also quick question with this part

<?php
$conn=mysql_connect("localhost","username","password"); 
mysql_select_db("dbname");
$query="select user_id from grads";
$result=mysql_query($query);
$option="";
while($row=mysql_fetch_array($result)) {
   $option.="<option value=".$row['user_id'].">".$row['user_id']."</option>";    
}
if(isset($_POST['submit'])) {
$query="UPDATE TABLE SET VOTE = 1 WHERE USER_ID ='".$_POST['priceisright']."'";	
mysql_query($query);
}
?>

Specifically this part

$option.="<option value=".$row['user_id'].">".$row['user_id']."</option>";

The row values what are they supposed to be? If my table is grads and the row is user_id is that all correct?

And i need to know the stuff i said in the previous post about the logins and such.

Also when trying to learn php what is the best way to be doing it? I really do want to learn it but i find whenever i try its really hard... I am using a visual quick pro book on php and mysql right now....

Thanks a lot, Dani

$row here is the recordset returned by the query, $query="select user_id from grads"; In this case, we are putting the values of user_id in a dropdown list.
To learn the basics of php and mysql, I would suggest you to visit this site.
Php is very easy to learn. Once you learn it, I am sure you can make your own login script.

commented: Great Job with help +1

its just i need to finish this asap do you mind helping me this time?

Why don't you hire someone ? I even gave you the link to a function to generate random passwords. I can't write anymore scripts for you. Sorry.

May be you can check php.net its agreat resource

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.