nav33n 472 Purple hazed! Team Colleague Featured Poster

I can't think of anything else. It should work then.

nav33n 472 Purple hazed! Team Colleague Featured Poster

print the query. Check if $_POST has any value. You can you die function to check if your query is working fine! mysql_query($query) or die(mysql_error());

nav33n 472 Purple hazed! Team Colleague Featured Poster

have another column in the table. call it "voted" or something, with default value 0. Whenever a user votes, while updating the column vote_status, also update the column "voted" by setting to 1. So, if it is 0, then that particular user has not voted. If its 1, then he has already voted.
And I don't know what's wrong with your query. Looks fine to me.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Great! :) Read more, Learn more!

nav33n 472 Purple hazed! Team Colleague Featured Poster

When the user logs in, start the session, add his name to a session variable.
Eg.

<?php    //page1.php
session_start();
$_SESSION['name']="testuser"; //user name
?>

<?php //page2.php
session_start();
echo $_SESSION['name']; //prints testuser
?>
nav33n 472 Purple hazed! Team Colleague Featured Poster

umm.. If its selecting the database, then why did you get that error

Warning: Cannot modify header information - headers already sent by
(output started at C:\inetpub\wwwroot\cms\core\db.php:13) in C:\inetpub\wwwroot\cms\index.php on line 20

Why don't you try a simple example ?

<?php
$username='username';
$password='pword';
$hostname='host';
$databasename='db_name';
$create='off';
$prefix='';

//database conection

$connection = mysql_connect($hostname, $username, $password) or die("<p>Unable to connect to the database server at this time.</p>". mysql_error());
$x=mysql_select_db($databasename) or die("<p>Unable to locate the [". $databasename ."] at this time</p>". mysql_error());
echo $x;
?>

Just execute this code and tellme if it returns 1.


Edit: Hey ! remove ob_start and ob_flush.

<?php
$username='username';
$password='pword';
$hostname='host';
$databasename='db_name';
$create='off';
$prefix='';$connection = @mysql_connect($hostname, $username, $password) or die("<p>Unable to connect to the database server at this time.</p>". mysql_error());
@mysql_select_db($databasename) or die("<p>Unable to locate the [". $databasename ."] at this time</p>". mysql_error());
?>

Replace your db.php with this one (or remove //database conection) and try again !

nav33n 472 Purple hazed! Team Colleague Featured Poster

Did you check whether its selecting the database ? I think you got a problem there.

nav33n 472 Purple hazed! Team Colleague Featured Poster
$connection = @mysql_connect($hostname, $username, $password) or die("<p>Unable to connect to the database server at this time.</p>". mysql_error());
@mysql_select_db($databasename) or die("<p>Unable to locate the [". $databasename ."] at this time</p>". mysql_error());

Remove @ before mysql queries. I guess your script is having problems selecting the database. C:\inetpub\wwwroot\cms\core\db.php:13 << That says, line 13 has started outputting already. You either buffer up the output by using ob_start() as the first line of your code, right after <?php and as the last line, have ob_flush(). Most people wont do this because its an unnecessary server load. Do these things.
Remove @ in db.php . Check if its selecting the database. Secondly, (as i said in my earlier post) don't output anything before header function.

nav33n 472 Purple hazed! Team Colleague Featured Poster

You forgot to post index.php. But anyway, here is a suggestion for you. Dont have any html tags, or echo statements (not even a blank space) before calling header function or before starting a session. I guess, in index.php, you are echoing something or you have html tags in it.

P.S: Next time you post your code, please use [/code ] tags.[code ] [/code ] tags.

nav33n 472 Purple hazed! Team Colleague Featured Poster

:) You are welcome!

nav33n 472 Purple hazed! Team Colleague Featured Poster

You are welcome! :)

nav33n 472 Purple hazed! Team Colleague Featured Poster
<?php
//connect
//select db
$arrData=array();
$query="SELECT SUM(RAW_AMOUNT) as TotalRawAmount, SUM(FG_AMOUNT) as TotalFGAmount, SUM(WIP) as TotalWIPAmount, UPLOAD_DATE FROM raw_fg_sum GROUP by UPLOAD_DATE";
$result=mysql_query($query);
$arrData[0][0] ="";
$arrData[1][0] = "TotalRawAmount";
$arrData[2][0] = "TotalFgAmount";
$arrData[3][0] = "TotalWIPAmount";
$i=1;
while($row=mysql_fetch_array($result)){
	$arrData[0][$i]=$row['UPLOAD_DATE'];
	$arrData[1][$i]=$row['TotalRawAmount'];
	$arrData[2][$i]=$row['TotalFgAmount'];
	$arrData[3][$i]=$row['TotalWIPAmount'];
        $i++;
}
print_r($arrData); //$arrData will have the array in the format you have specified.
?>

Hope that helps.
Nav

nav33n 472 Purple hazed! Team Colleague Featured Poster

hmm.. Ok..

<?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.

nav33n 472 Purple hazed! Team Colleague Featured Poster

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.

nav33n 472 Purple hazed! Team Colleague Featured Poster

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! :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

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. :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

err.. You have using getElementById("favorite"), But, you have exp as the id for the textbox.

<html>
<head>
<script type="text/javascript">
function explain(value){
	if(document.getElementById("list01").value=="burn")
	{
		document.getElementById("exp").value="This burns their crops"
	}
	if(document.getElementById("list01").value=="pillage")
	{
		document.getElementById("exp").value="Kill women and children"
	}
	if(document.getElementById("list01").value=="court")
	{
		document.getElementById("exp").value="huh"
	}
}
</script>
</head>
<body>
<form id="myform" method="post">	how would you like to attack <? echo $attuser; ?>, you can:<br /><br />
<select id="list01" name="atk" class="but" onChange="explain(this)">
<option value="burn">burn crops</option>
<option value="pillage">pillage</option>
<option value="court">court women</option>
</select>
<input id="exp" value="" disabled="disabled" class="but" size="50" />
<input type="submit" name="attack" value="Attack!!" class="but" />
</form><br />
</body>
</html>

This works :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

ob_start buffers all the output. But, if your page has a lot of data, make sure that you don't use ob_start since it acts on the server load.

nav33n 472 Purple hazed! Team Colleague Featured Poster
<?php
if(isset($_POST['submit'])) {
		if($_FILES['fileupload']['name']==""){
			echo "Empty"; //no file was uploaded
		}
		//continue with rest of the operation..
}
	?>
<html>
<body>
<form name="upload" method="post" action="upload.php" enctype="multipart/form-data">
<table>
<tr><td>
<input type="file" name="fileupload">
</td></tr>
<tr><td>
<input type="submit" name="submit">
</td></tr>
</table>
</form>
</body>
</html>

This will do.. :)

Venom Rush commented: helped me a lot. Where would I be without nav33n :P +1
nav33n 472 Purple hazed! Team Colleague Featured Poster
$query="select user_id from table";
$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);
}

:) Simple.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Earlier in your query, you were using $row as value. So I asked you to change the query. Since you have changed the value to $row 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.

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

That doesnt work since you are not setting $_SESSION anywhere. First check if $_SESSION 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.

$pass=generatePassword($length); //length of the password.. by default it takes 8 if you don't specify any.
nav33n 472 Purple hazed! Team Colleague Featured Poster

Uploading images to a table ? 99% of the people who upload an image wouldn't upload it to the table. Instead, they upload the image to the filesystem and insert the path of the image to the table. Fetching the blob data from the database just adds on to the server load. But if you want to insert an image to a table, you can check this site.

nav33n 472 Purple hazed! Team Colleague Featured Poster

umm.. I guess you didn't see what I posted in my previous post ? :S

nav33n 472 Purple hazed! Team Colleague Featured Poster

:) Great!

nav33n 472 Purple hazed! Team Colleague Featured Poster

$city')"; This should have been '$city')" ;

nav33n 472 Purple hazed! Team Colleague Featured Poster

See! I told you. Values are not being assigned to the option :) ! This should have been,

<option value=Jacob Anderson>Jacob Anderson</option><option value=Mohammed Abbas>Mohammed Abbas</option><option value=Hiroaki Abe>Hiroaki Abe</option>

:)


Edit: Change $query="select user_id from grads"; to $query="select user_id,grads from grads"; It should work.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Ok. What is the error now ? Print out the query. (print $sql; ) . Where are you assigning the tablename ($tbl_name) ? and NEVER display your host, username and password :S !

nav33n 472 Purple hazed! Team Colleague Featured Poster

And put commas. :)

Edit: I didn't see shawnCplus edit his post!

nav33n 472 Purple hazed! Team Colleague Featured Poster

The problem is with the file db.php . When you are using header() function, you shouldn't output anything to the browser. ie., you shouldn't echo anything before header function. You shouldn't even have html tags. Check your db.php.

Cheers,
Nav

nav33n 472 Purple hazed! Team Colleague Featured Poster

huh! Right click on your page and click on view source. Check if the value for <option value=''> is being set. Check if its not null. Then select some dropdown list values and check again. When you submit, if you get something like, array([priceisright]=>your choice,......) , then your code has no problem!

nav33n 472 Purple hazed! Team Colleague Featured Poster

Weird. This script is running fine on my system. Print out the message! I get,

Thank you for registering with our site! Your selection was naveen2. Sincerely, Us

. Also check if you are populating the dropdown list! Or, I think you probably selected either "Please Choose One Person" or "Not Voting". Assign some value to these options and test.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Well, you need to post your script then.

nav33n 472 Purple hazed! Team Colleague Featured Poster

comment out mail(...) line in your script and on top of the script, right after <?php put this line. print_r($_POST); Then fill out the form once again, click on submit. Check If any value assigned to .

nav33n 472 Purple hazed! Team Colleague Featured Poster

ok..Then the problem is not with smtp.. Check if $_POST is sending a value.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Try out a sample mail first to your own id. If you get it, then the problem is with your script. If you dont get a mail, then probably, your smtp is not configured properly.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yep. What you have done is correct.

$x=$_POST['field1'];
$y=$_POST['field2'];
$z=$_POST['field3'];
....

//In case you want to concat them, you can do it this way. 
$string = $x." ".$y." ".$z; //This will concat all the three variables separated by a space.
...

:) Hope that helps.

nav33n 472 Purple hazed! Team Colleague Featured Poster

no problemo! :)


Instead of {$_POST}, you can assign that to a variable and use that variable. Its little confusing for starters on how php handles strings.

// 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");
}
?>

You can do that.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Simple. You do it this way.

<?php
.....
if($row_rsFrontPage['ImagePath']=="") { 
  $class="noclass";
} else { 
   $class="applyclass"; 
}
?>
<p class="<?php echo $class; ?>">blah blah blah... </p>

Hope that helps.
Naveen

nav33n 472 Purple hazed! Team Colleague Featured Poster

On submitting the page, if the user has selected a value from the select box, it will be in $_POST. So, you can do something like $x=$_POST. $x will have his selection.

nav33n 472 Purple hazed! Team Colleague Featured Poster

:@ I want my reps! lol..

You are welcome ;)

nav33n 472 Purple hazed! Team Colleague Featured Poster
SELECT eid, title, SUBSTRING(content, 1, 200), thumb_image FROM diary ORDER BY eid DESC LIMIT 3

:) Now, gimme my virtual high five!

Venom Rush commented: Extremely helpful post ;) +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

code ?

nav33n 472 Purple hazed! Team Colleague Featured Poster
$result=mysql_query($query);
$found=mysql_num_rows($result);
if($found > 0 ){
echo "Record found";
} else {
echo "Record not found.";
}

That will do.

rickarro commented: A great help and very understanding to us newbie's. +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

You should have your connection string before any sql operation. So, it would be like,

$connection=mysql_connect($host,$user,$pass);
if(!$conn) {
 echo "Error connecting.";
} else {
 echo "Connected.";
}

Instead of using if and else, you can use die function with mysql_error function to know the error in your mysql statement. die ends the execution of the script. (Its an alias of exit). $connection = mysql_connect($host,$user,$pass) or die(mysql_error()); :) Cheers,
Naveen

nav33n 472 Purple hazed! Team Colleague Featured Poster

lol.. echo is used to output something to the screen :P . It should work in all browsers. http://localhost/filename.php should work fine in any browser. :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

You are welcome! Check your php.ini (c:\php\php.ini or c:\wamp\apache2\bin\php.ini, if you are using Wamp) file for the line short_open_tag. If it is off, turn it On. If short open tags are turned off and if you have short open tags in your script, it will print the script. Thats why its always better to use <?php instead of <? !

And yep, You will learn in no time. Php is really easy ! :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Umm.. I am not sure about preg_replace. But you can do the same with str_replace!

<?php
$txt="' is a single quote \" is a double quote.I want to replace ' with \' and \" with \" ";
echo "Actual text: " .$txt."<br />";
$x=str_replace('"','\"',str_replace("'","\'",$txt));
echo "Replaced text: ". $x;
?>

Hope it helps!
Naveen

Venom Rush commented: Helpful as always ;) +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Have a hidden field to pass the number of textboxes. In the next page, use a for loop to get the values entered in those textboxes.

for($i=0;$<$number_of_textboxes;$i++){
 $txtboxname=$txt.$i;
$textbox_value=$_POST[$txtboxname];
print $textbox_value;
}

:)

nav33n 472 Purple hazed! Team Colleague Featured Poster

hmm.. Its showing the query because you are printing it (echo $query; ). I don't see anything wrong with the query or the script. The problem might be with your php configuration.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yep. Get all the form information, align it as you want. Put it in the 'message' part of the mail.