nav33n 472 Purple hazed! Team Colleague Featured Poster

Yep. You are wrong in writing the query.

<?
$host = "localhost";
$user = "myuser";
$pass = "mypassword";
$dbname = "voters";

$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
$dbname = "voters";
mysql_select_db($dbname);

$lname=$_POST['lname'];
$fname=$_POST['fname'];
$dob=$_POST['dob'];

$query= "select * from voters where lname='$lname' AND
fname='$fname' AND dob='$dob'"; 
echo $query;

$result= mysql_query($query);
$num_results = mysql_num_rows($result);

while ($row = mysql_fetch_array($result)) {
echo "<p>",$row['lname'], ": ",$row['fname'], ": ",$row['dob'];
}

?>

Check this. Don't you think this is much easier than using $_POST in your query ? I do it this way. I first assign the values of the $_POST to a php variable, then use that php variable(in this case, $fname,$lname and $dob). And, you shouldn't end your query (with a semicolon) after every condition.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Well, you can have a condition to check if the submit button was pressed.

if(isset($_POST['submit'])){
$message="This is the body of this mail. blah blah blah..........some more text... ";
mail("test@gmail.com","test mail",$message,"from: someone@gmail.com");
}

you can send all the data in the message part of the mail.

nav33n 472 Purple hazed! Team Colleague Featured Poster

You can use mail function.
Eg. mail("to address","subject","message contents","from: from address");

nav33n 472 Purple hazed! Team Colleague Featured Poster

y

:S Dude! is everything ok ? This is the 2nd time you are saying something which doesn't make any sense.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Say, for example, the user enters 10 in the first screen. On the next screen, you can do something like,

$textboxes_number=$_POST['number']; //the number of textboxes the user wants
$textboxes_number=10; //say user enters 10 in the previous screen
echo "<form name=form method=post action=somepage.php>";
for($i=0;$i<$textboxes_number;$i++){
echo "<input type='text' name=txt$i>";
}

echo "<input type='submit' name='submit' value='submit'>";
echo "</form>";

This will generate 10 textboxes with different names.

Cheers,
Naveen

nav33n 472 Purple hazed! Team Colleague Featured Poster
CREATE TABLE test (
id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
name VARCHAR( 100 ) NOT NULL ,
address VARCHAR( 100 ) NOT NULL
) ENGINE = InnoDB

If that's my table, and I have a form with 2 fields name and address, this is how I would be inserting the values to the table test. This should get you started.(I hope!)

<?php
if(isset($_POST['submit'])){
$conn=mysql_connect("localhost","root");
mysql_select_db("exact");
$name=$_POST['name'];
$address=$_POST['address'];
$query="INSERT INTO TEST (ID,NAME,ADDRESS) VALUES ('','$name','$address')";
mysql_query($query);
}
?>
<html>
<body>
<form method="post" action="insert_example.php">
Enter Name: <input type="text" name="name"><br />
Enter Address: <textarea rows="10" cols="20" name="address"></textarea>
<br />
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

Cheers,
Nav

nav33n 472 Purple hazed! Team Colleague Featured Poster

I would validate on both client side and server side(because sometimes, the user might have disabled the javascript!)

nav33n 472 Purple hazed! Team Colleague Featured Poster

If you are using firefox, you can use Error console. Error console lists all the errors(javascript & css) encountered in your page.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Umm.. Change “ ” to " ". Put data.txt in the same folder where you have the ajax script. I don't know much of ajax, but, the following code worked for me without any errors.

<html>
<head>
<title>Ajax at work</title>
<script language = "javascript">
var XMLHttpRequestObject = false;
if (window.XMLHttpRequest) {
XMLHttpRequestObject = new XMLHttpRequest();
} else if (window.ActiveXObject) {
XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}
function getData(dataSource, divID)
{
if(XMLHttpRequestObject) {
var obj = document.getElementById(divID);
XMLHttpRequestObject.open("GET", dataSource);
XMLHttpRequestObject.onreadystatechange = function()
{
if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200 ) { 
	obj.innerHTML = XMLHttpRequestObject.responseText;
}
}
XMLHttpRequestObject.send(null);
}
}
</script>
</head>
<body>
<H1>Fetching data with Ajax</H1>
<form>
<input type = "button" value = "Display Message"
onclick = "javascript: getData('data.txt',
'targetDiv')">
</form>
<div id="targetDiv">
<p>The fetched data will go here.</p>
</div>
</body>
</html>

Cheers,
Naveen

Edit: SOS, you beat me by a minute :P

nav33n 472 Purple hazed! Team Colleague Featured Poster

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.

nav33n 472 Purple hazed! Team Colleague Featured Poster

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

dani190 commented: Great Job with help +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

First check the file type you are trying to upload. You can get the filetype of the file you are trying to upload by using $_FILES. I guess you are uploading a different file type(and checking for a different filetype).

if($_FILES['file']['type'] == "image/pjpeg" || $_FILES['file']['type']=="image/jpeg" || $_FILES['file']['type']=="image/gif") {
   //do something
} else {
  //wrong extension
}
nav33n 472 Purple hazed! Team Colleague Featured Poster

You are welcome! And yep, you can use both AND and && .

nav33n 472 Purple hazed! Team Colleague Featured Poster
<?php
	if(isset($_POST['submit'])) {
		for($i=0;$i<count($_FILES['fileupload']);$i++) {
			print $_FILES['fileupload']['name'][$i]."<br />";
		}
	}
	?>
<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="file" name="fileupload[]">
</td></tr>
<tr><td>
<input type="file" name="fileupload[]">
</td></tr>
<tr><td>
<input type="file" name="fileupload[]">
</td></tr>
<tr><td>
<input type="submit" name="submit">
</td></tr>
</table>
</form>
</body>
</html>

This works for me! :)

OmniX commented: Gave me a working example +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Can you show us your script ? What is the error that you are getting ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

Have 3 textboxes in your form. Call it firstname, lastname and date_of_birth. The page submits to 'somepage.php'. In somepage.php, you can access the form variables like,

$firstname = $_POST['firstname']; 
$lastname = $_POST['lastname'];
....

Then in your query, you can use these posted form variables. $query="select * from users where firstname='$firstname' AND lastname='$lastname'"; :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

* 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>
nav33n 472 Purple hazed! Team Colleague Featured Poster

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

nav33n 472 Purple hazed! Team Colleague Featured Poster

ok.. That's not a problem!

<?php print_r($_POST); ?>

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

nav33n 472 Purple hazed! Team Colleague Featured Poster

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();

:)

nav33n 472 Purple hazed! Team Colleague Featured Poster

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

Sulley's Boo commented: jug jug jiyo =D +4
nav33n 472 Purple hazed! Team Colleague Featured Poster

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.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Ok. Try running this update_query in phpmyadmin. If you had any problem with the query, die(mysql_error()) would have given relevant error. But since its not giving you any error, I am clueless about where exactly you have your error. Oh, btw, did you do what I asked you to do ? Did you add a hidden field with the name id ?

I have the id being passed... and I can populate my form with data.

That's because, in your other window, you are passing id in the query string and here, you are accessing it like $id=$_GET; Can you post your latest edit.php ? I am still having doubts that you can access the variable id.

nav33n 472 Purple hazed! Team Colleague Featured Poster

My suggestion would be to echo the query you are using to update the table. I believe the id is not being passed to the query.

$query="update greenslip set date_completed='$date_completed', location='$location', person_reporting='$person_reporting', solution='$solution'
where id='$id'";
echo $query;

Try to echo the query first. You will know the problem with your query. But I strongly believe that its because id is not being passed.

nav33n 472 Purple hazed! Team Colleague Featured Poster

I wanted to do the same thing some time ago. But its simply not possible. You can have multiple <input type="file"> tags though.

nav33n 472 Purple hazed! Team Colleague Featured Poster

$id=$_POST;

You have this in your script. But where are you passing the id value ? I dont see any hidden variable where you are passing the value of id ! Put

<input type="hidden" name="id" value="<?php echo $row['id']; ?>">

this after you start the form and tell me if it works !

Cheers,
Nav

nav33n 472 Purple hazed! Team Colleague Featured Poster

Try this.

mysql_query("update greenslip set date_completed='$date_completed', location='$location',  person_reporting='$person_reporting', solution='$solution' 
 where id='$id'") or die(mysql_error());

It will show you why its not updating. Then let us know, cuz, I don't see any error in your script.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Calling switch statement is fine. But Say for example you have 2 textboxes with the same name. While requesting the values, dont you think the value of 1 textbox will be overwritten by the other ? But anyway, coming back to your question. If you want a function to detect any integer value, you can make use of is_int.

nav33n 472 Purple hazed! Team Colleague Featured Poster

You can access the value of the submit button using $_POST. You can then use it in a switch statement or a if loop. :confused:

How can you have input buttons with same name ? For example, If there are 2 buttons with the same name, how can you validate if that particular button was clicked ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

I cant figure out what code to construct and use to check if one of the numbers has been selected (apart from the obvious 1-20 which is not an option).

What exactly do you mean by that ? Do you want to access the value of $variable when submit button is clicked ? If thats the case, then the simplest method would be to assign the value of $variable to a hidden form variable(using the onclick event).

nav33n 472 Purple hazed! Team Colleague Featured Poster

You are trying to access the checkbox controls with wrong name. Its not

<b>Batata Harra Plate $3.00	= </b> '.$_POST['Batata Harra Plate $3.00'].'<br />
<b>Moutabel Plate $3.00	= </b> '.$_POST['Moutabel Plate $3.00'].'<br />
<b>Warak Piece $.50		= </b> '.$_POST['Warak Piece $.50'].'<br />
<b>Loubieh Bzeit Plate $3.00	= </b> '.$_POST['Loubieh Bzeit Plate $3.00'].'<br />

It has to be, $_POST,$_POST and so on.

I would suggest you to call you html page as order.php and at the top, print the posted form variables. Then you will know the names and values that are being passed. Here, check this out. Fill in the details and click submit. I hope you can understand what I am talking about.

<?php
print "<pre>";
print_r($_POST);
print "</pre>";
?>
<!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=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.box1 {font-family: tahoma;
font-size: 11px;
color: #5B5C5C;
text-decoration: none;
border: 1px solid #B9B9B9;
}
-->
</style>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {font-size: 16px}
-->
</style>
</head>

<body><a href="../css"></a>
<table width="841" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="841" height="90" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="841" height="90">&nbsp;</td>
</tr>
</table> </td>
</tr>
<tr>
<td height="27">&nbsp;</td>
</tr>
<tr>
<td height="890" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="841" height="890" valign="top"><p>&nbsp;</p>
<form action="order.php" method="post" name="frm_email" id="frm_email">
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<!--DWLayoutTable-->
<tr>
<td width="26%" height="24" class="textbrwon"><div align="right"><span class="bodytext">First Name </span> : </div></td>
<td width="1%">&nbsp;</td>
<td colspan="6"><input name="name" type="text" class="box1" …
nav33n 472 Purple hazed! Team Colleague Featured Poster

Can you show us your html part ? Here's one simple example form.

<?php  //mail.php
$message="";
$email = $_POST['email'];
$checkbox1=$_POST['checkbox1'];
$checkbox2=$_POST['checkbox2'];
$message.="<b>$email $checkbox1 $checkbox2</b>";
echo $message;
$to="some_email@email.com";
$subject="test mail";
$from="From: someone@email.com";
mail($to,$subject,$message,$from);
?>
<html>
<body>
<form name="test" action="mail.php" method="post">
Enter email address: <input type="text" name="email"><br />
<input type="checkbox" name="checkbox1" value=10> 20 &nbsp;
<input type="checkbox" name="checkbox2" value=20> 10 &nbsp;<br />
<input type="submit" name="submit" value="sendmail">
</form>
</body>
</html>
nav33n 472 Purple hazed! Team Colleague Featured Poster

Welcome :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

$checkboxvalue = $_POST['checkboxname'] is how you get the value of a checkbox. For example, if you have <input type=checkbox name=checkbox value=10> in your form, on submitting, you access the value (only if the checkbox is checked) as, $checkbox = $_POST['checkbox']; So, $checkbox has the value 10.

Cheers,
Nav

nav33n 472 Purple hazed! Team Colleague Featured Poster

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 …

nav33n 472 Purple hazed! Team Colleague Featured Poster

You can't use C or C++ to create a web application. You need a server side scripting language for a web application (or a dynamic web page, Eg, registration form, login form, etc). php, asp, jsp, asp.net etc are some server side scripting languages. If your site is static, which has no user interaction, then start it by using html.

Learning php is very easy. You can start right away here. To work with php, you need apache, mysql and ofcourse php, which are all free. You can download a combined pack [php, mysql,apache] here. Just download and install. Check w3schools and start learning!
Cheers,
Nav

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yep, possible. Use nl2br ! Eg.

<?php
print nl2br($_POST['textarea']);
?>
<html>
<body>
<form method=post action=test.php>
<textarea name=textarea cols=20 rows=20></textarea>
<input type=submit name=submit value=submit>
</body>
</html>

Cheers,
Nav

nav33n 472 Purple hazed! Team Colleague Featured Poster

Welcome to Daniweb Tim. But this isn't the right forum to post your question ! Try here.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Simple. By using fgetcsv.

iamthwee commented: I approve! +13
nav33n 472 Purple hazed! Team Colleague Featured Poster
<html>
<body>
<form name="form" method="post" action="test.php">
Number: <input type="text" name="number"><br />
<input type="submit" name="add" value="+"><input type="submit" name="subtract" value="-">
</form>
</body>
</html>
<?php
$conn=mysql_connect("localhost","username","password");
mysql_select_db("dbname");
if(isset($_POST['add'])){
	$add=$_POST['number'];
	$query="update goods set stock=stock+$add where id=1";
	mysql_query($query) or die("Cannot update");
}
if(isset($_POST['subtract'])){
	$subtract=$_POST['number'];
	$query="update goods set stock=stock-$subtract where id=1";
	mysql_query($query) or die("Cannot subtract");
}
?>

Umm.. you forgot to put your code in [ c o d e ] [ / c o d e ] tags. Anyways, I hope this helps.

nav33n 472 Purple hazed! Team Colleague Featured Poster

just add another condition ! SELECT * from attend where (day1 between '$from' and '$to') and spid='$id' :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Ok. I see the error. Its your select_db string. mysql_select_db("kishou_website", $connect);/ Its after your query. Put it above the query. :) This should fix it.

kishou commented: just keeps on helping! +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

That means there are many records with the same spid. You can change the above query to, select email from personal where spid IN (select spid from applyleave where leaveid IN (select leaveid from viewleave where leaveid="specify your leaveid here")) Cheers.

nav33n 472 Purple hazed! Team Colleague Featured Poster

yea dont copy it though. please.

Dude! I can write my own script.. :D Anyway, here is the error.. $res=mysql_query("SELECT * FROM mailing_list where Email=$_POST[email]"); This should have been $res=mysql_query("SELECT * FROM mailing_list where Email='".$_POST[email]."'"); You should put your variable name in single quote if its a string.

Cheers,
Nav

nav33n 472 Purple hazed! Team Colleague Featured Poster

Can you show us your script ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

thanks dude! So then it would look like this?

$res=mysql_query("SELECT * FROM registered_members=$_POST['Username']");
if (mysql_num_rows($res)>0)
{
echo "Username is already taken!";
}
else
{

ok then i get this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource.

Thats because, you have your query wrong. Its missing a where clause. $res=mysql_query("SELECT * FROM registered_members where username=$_POST['Username']");

nav33n 472 Purple hazed! Team Colleague Featured Poster

select email from personal where spid=(select spid from applyleave where leaveid=(select leaveid from viewleave where leaveid="specify your leaveid here")) Hi.. Try this and let me know if this works..

nav33n 472 Purple hazed! Team Colleague Featured Poster

Well, you are doing it wrong then. Because,
distance ^2 = (24-36)^2 + (15-8)^2
distance ^ 2 = (-12)^2 + (7)^2
distance ^ 2 = 144 + 49
distance ^ 2 = 193.
distance = sqrt ( 193)
distance = 13.89...

nav33n 472 Purple hazed! Team Colleague Featured Poster

finding the distance from these points (15,20) and (45,70) Considering 15 as x1, 20 as y1, 45 as x2 and 70 as y2, if we apply the formula, it is, sqrt((45 - 15)^2 + (70-20)^2) = 58.3095189485 :-/

<?php
$A=45;
$B=15;
$C=($A-$B);
$D=($C*$C);
$E=70;
$F=20;
$G=($E-$F);
$H=($G*$G);
$I=sqrt($D+$H);
echo "The distance is: $I";
?>

The above program also gives the same output !

nav33n 472 Purple hazed! Team Colleague Featured Poster

Shouldn't it be sqrt((x2-x1)^2+(y2-y1)^2)=distance ? You are just taking the sqrt of $H and not $H + $D.