•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 361,627 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 2,193 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: 1914 | Replies: 62 | Solved
![]() |
•
•
Join Date: Dec 2007
Posts: 59
Reputation:
Rep Power: 1
Solved Threads: 0
<?php
print_r($_POST);
ini_set('display_errors','1');
$conn=mysql_connect("********************","*******","**************") or die(mysql_error());
mysql_select_db("db33717_gradsurvey") or die(mysql_error());
$query=("SELECT * FROM grads") or die(mysql_error());
$result=mysql_query($query) or die(mysql_error());
while($row=mysql_fetch_array($result)){
$userid=$row['user_id'];
$password=$row['password'];
$sql="update grads set password"or die(mysql_error());
mysql_query($sql) or die(mysql_error());
}
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++;
}
}
// done!
return $password;
}
$password=generatePassword(8);
?>
<?
echo $user_id;
echo $password;
?>I tried for almost an hour and a half and i still cant get it
I got it down to this error now
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 '' at line 1
Mind helping me? I think i just cant get this line correct
$sql="update grads set password"or die(mysql_error());
Thanks, Dani.
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 2,861
Reputation:
Rep Power: 7
Solved Threads: 205
hmm.. Ok..
This will work.
php Syntax (Toggle Plain Text)
<?php $conn=mysql_connect("********************","*******","**************") or die(mysql_error()); mysql_select_db("db33717_gradsurvey") or die(mysql_error()); 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++; } } // done! return $password; } $query=("SELECT * FROM grads") or die(mysql_error()); $result=mysql_query($query) or die(mysql_error()); while($row=mysql_fetch_array($result)){ $userid=$row['user_id']; $password=generatePassword(8); $sql="update grads set password='$password' where user_id='$userid'"; mysql_query($sql) or die(mysql_error()); echo $user_id." : ".$password; //remove this if you dont want to see the user id and password on the screen } ?>
This will work.
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*
*PM asking for help will be ignored*
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 2,861
Reputation:
Rep Power: 7
Solved Threads: 205
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 2,861
Reputation:
Rep Power: 7
Solved Threads: 205
When the user logs in, start the session, add his name to a session variable.
Eg.
Eg.
php Syntax (Toggle Plain Text)
<?php //page1.php session_start(); $_SESSION['name']="testuser"; //user name ?> <?php //page2.php session_start(); echo $_SESSION['name']; //prints testuser ?>
Last edited by nav33n : Jan 20th, 2008 at 12:56 pm. Reason: Forgot session_start() in page2.php :P
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*
*PM asking for help will be ignored*
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
bcsd bcsm blog blogging ccie certification cheating cisco cissp community competition comptia crime daniweb database defender design desktop gentoo google hacker home ipod linux magazine microsoft navigation networks news opinion php red hat research rhce salary school security social spam spyware sql survey teleworking theft virtual vista web windows work
Other Threads in the PHP Forum
- Previous Thread: My sql image links in table
- Next Thread: parse error, unexpected '<' in /data/www/tppine/camo/data/data.php



You are welcome!
Linear Mode