User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 374,166 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,281 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2020 | Replies: 62 | Solved
Reply
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,042
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 227
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: survey for school grads... Another question

  #31  
Jan 17th, 2008
Great!
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Dec 2007
Posts: 59
Reputation: dani190 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
dani190 dani190 is offline Offline
Junior Poster in Training

Re: survey for school grads... Another question

  #32  
Jan 17th, 2008
ok fixed it,

Now i have the passwords left...
But i never really understood how i will run the password script you gave me so it inserts the password into each users password field?

So basically i have the table Grads, then i have for each user_id the password field.

hopefully you can give me a hand with this

Never saw how to do this in my book yet.


EDIT: and this is what i fixed


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

both rows werent showing user_id thats y it wasnt querying it like u said so....


Whats that other thing u told me to change?

I also cant get this welcome script to work not that it really matters but i think its showing me that something isn't right...

and 1 last thing dealing with the security. How am i going to stop people from bypassing the login script and not just going to the survey? or you think cus its only being used by high school students and no one will know the structure it should be fine?


EDIT EDIT:

Also when i do the submit it is only taking the first name for some bizarre reason

Here is the top of the code incase u want it

<?php
print_r($_POST);
$conn=mysql_connect("********************","*******","**********"); 
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['user_id'].">".$row['user_id']."</option>";    
}
if(isset($_POST['submit'])) {
$query="UPDATE TABLE SET VOTE_STATUS = 1 WHERE USER_ID ='".$_POST['user_id']."'";	
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>


<?php
// Welcome the user
echo '<h2>Welcome';
if (isset($_SESSION['agent'])) {
	echo ", {$_SESSION['agent']}!";
}
echo '</h2>';







// Mail Script
if(isset($_POST['submit'])){
$selection=$_POST['style'];
$a=$_POST['priceisright'];
$b=$_POST['millionaire'];
$c=$_POST['loosepassport'];
$d=$_POST['vanriver'];
$e=$_POST['spusecheat'];
$f=$_POST['marrymoney'];
$g=$_POST['5divorces'];
$h=$_POST['primeminister'];
$i=$_POST['teacheci'];
$j=$_POST['40yearoldvirgin'];
$k=$_POST['livewparents'];
$l=$_POST['dieholdingcell'];
$m=$_POST['damagedliver'];
$n=$_POST['jail'];
$q=$_POST['plasticsurgery'];
$r=$_POST['adoptchildren'];
$s=$_POST['buyfriends'];
$t=$_POST['Dictionary'];
$u=$_POST['guitarhero'];
$v=$_POST['convent'];
$w=$_POST['souljaboywedding'];
$x=$_POST['nobelpeace'];
$y=$_POST['huggerenvironment'];
$z=$_POST['mack'];
$aa=$_POST['ego'];
$ab=$_POST['partier'];
$ac=$_POST['cougar'];
$ad=$_POST['awkward'];
$ae=$_POST['dramtic'];
$af=$_POST['gossip'];
$ag=$_POST['cluts'];
$ah=$_POST['car'];
$ai=$_POST['style'];
$aj=$_POST['hair'];
$ak=$_POST['cutestcouple'];
$al=$_POST['hottestparents'];
$am=$_POST['playboygirl'];
$an=$_POST['kingswaymd'];
$aq=$_POST['funniest'];
$ar=$_POST['athletic'];

$message = "Price is right: $a";
mail("****l@anblickstudios.com","Grad Survey 08",$message,"from: *****@anblickstudios.com");
}

// Mail Script
if(isset($_POST['submit'])){
$selection=$_POST['style'];
$message = "Thank you for registering with our site!\nYour selection was $selection.\n\nSincerely,\nUs";
mail("******@anblickstudios.com","Grad Survey 08",$message,"from: *******@anblickstudios.com");
}
?>

and this was the exact welcome code....

<?php
// Welcome the user
echo '<h2>Welcome';
if (isset($_SESSION['agent'])) {
	echo ", {$_SESSION['agent']}!";
}
echo '</h2>';
Last edited by dani190 : Jan 17th, 2008 at 9:19 pm.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,042
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 227
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: survey for school grads... Another question

  #33  
Jan 17th, 2008
Earlier in your query, you were using $row['grad'] as value. So I asked you to change the query. Since you have changed the value to $row['user_id'] it should work fine. Its passing first name because (I think) you are storing first name in user_id column. Because, when I asked you to show what's in <option value=''>..</option>, it showed me the first name.
  1. <?php
  2. // Welcome the user
  3. echo '<h2>Welcome';
  4. if (isset($_SESSION['agent'])) {
  5. echo ", {$_SESSION['agent']}!";
  6. }
  7. echo '</h2>';
That doesnt work since you are not setting $_SESSION['agent'] anywhere. First check if $_SESSION['agent'] is not set. If its not set, set agent name. Then this will work.
And about the password generation. Well, the link that I gave you was a function. You just have to copy that function in your script and call that function whenever you want to generate a new password. And this is how you call that function.
  1. $pass=generatePassword($length); //length of the password.. by default it takes 8 if you don't specify any.
Last edited by nav33n : Jan 17th, 2008 at 11:13 pm.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Dec 2007
Posts: 59
Reputation: dani190 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
dani190 dani190 is offline Offline
Junior Poster in Training

Re: survey for school grads... Another question

  #34  
Jan 17th, 2008
so i would be using that function in the sql?

I just don't get how i am doing this...

Am i generating say 500 passwords and then running a mysql script to insert them all into the database?
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,042
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 227
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: survey for school grads... Another question

  #35  
Jan 18th, 2008
  1. $query="select user_id from table";
  2. $result=mysql_query($query);
  3. while($row=mysql_fetch_array($result)){
  4. $x=generatePassword($length);
  5. $userid=$row['user_id'];
  6. $sql="update table set password='$x' where user_id='$user_id'";
  7. mysql_query($sql);
  8. }

Simple.
Last edited by nav33n : Jan 18th, 2008 at 1:12 am.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Dec 2007
Posts: 59
Reputation: dani190 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
dani190 dani190 is offline Offline
Junior Poster in Training

Re: survey for school grads... Another question

  #36  
Jan 18th, 2008
Ok here is what i have now...

<?php
print_r($_POST);
$conn=mysql_connect("i**********","*************","***********"); 
mysql_select_db("db33717_gradsurvey");
$query="select password from grads";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)){
$x=generatePassword($length);
$userid=$row['user_id'];
$sql="update table set password='$x' where user_id='$user_id'";
mysql_query($sql);
}

function generatePassword ($length = 8)
{

  // start with a blank password
  $password = "";

  // define possible characters
  $possible = "0123456789bcdfghjkmnpqrstvwxyz"; 
    
  // set up a counter
  $i = 0; 
    
  // add random characters to $password until $length is reached
  while ($i < $length) { 

    // pick a random character from the possible ones
    $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
        
    // we don't want this character if it's already in the password
    if (!strstr($password, $char)) { 
      $password .= $char;
      $i++;
    }

  }
  $pass=generatePassword($length); //length of the password.. by default it takes 8 if you don't specify any.

  // done!
  return $password;

}

?>

So now this is what i get... Array ( )

Thats all and nothing gets into the database.

Any ideas?
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,042
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 227
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: survey for school grads... Another question

  #37  
Jan 18th, 2008
remove print_r($_POST); and then debug yourself. I think I have helped you enough and you are in a state where you can solve your bugs.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Dec 2007
Posts: 59
Reputation: dani190 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
dani190 dani190 is offline Offline
Junior Poster in Training

Re: survey for school grads... Another question

  #38  
Jan 18th, 2008
oh removing the print will allow me to view bugs? Ok il give it a shot.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,042
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 227
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: survey for school grads... Another question

  #39  
Jan 18th, 2008
Nope. print_r($_POST); is for debugging. I asked you to remove it because, once your code is up and running, you dont need those debug information. But anyway, unless you dont debug your code yourself, you wont learn anything. Spoon feeding is not good either. So good luck!
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,042
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 227
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: survey for school grads... Another question

  #40  
Jan 18th, 2008
I guess you dont know how a function works ! Am I correct ? The function call should be outside the function and not within itself. It will enter an infinite loop.
$pass=generatePassword($length);

should be outside. And it should be something like $x=generatePassword(8);
I hope here on, you will debug on your own.
Last edited by nav33n : Jan 18th, 2008 at 7:55 pm.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 4:09 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC