nav33n 472 Purple hazed! Team Colleague Featured Poster

On line 23, mysql_select_db($database, $administration); What are you trying to do ?
If administration is the database name, you should give, mysql_select_db('administration'); Read more on mysql_select_db here.

nav33n 472 Purple hazed! Team Colleague Featured Poster

LOL, I'm actually supriced he replayed as the original post is 2 years old now

:P Prolly he came back today after a long break !

nav33n 472 Purple hazed! Team Colleague Featured Poster

As far as I know, you can't have insert and update in the same query. The only case where you can have insert and update in the same query is when you use on duplicate clause . If you are using php to insert values to the table, you can do it without any problem.

$insert_query="insert into puppybasket (number_of_puppies,color) values ('val1','val2')"; //val1 has the number and val2 has the color
mysql_query($insert_query);
$update_query="update basket set total=total+'val1' where condition"; // total will be updated to total+number of new puppies added.
mysql_query($update_query);

Cheers,
Naveen

Venom Rush commented: Exactly what I needed to know ;) +1
nav33n 472 Purple hazed! Team Colleague Featured Poster
<?php
$conn=mysql_connect("localhost","root");
mysql_select_db("test");
echo "Select a name: <select name='name'>";
$query="select name from users";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)){
$name=$row['name'];
echo "<option value='$name'>$name</option>":
}
echo "</select>";
?>

This will show all the names of table users in a dropdown box.
If this isnt what you were looking for, can you be more specific and show us your code ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

and why should I waste my time explaining how I fixed it when NO-ONE on this forum gave me even the slightest help?

- Courtesy works both ways... not just one!

Well, people might not be knowing the answer for your question. You can't expect them to know the answer for everything. Can you ? And If you had posted your 'fix', it would have helped others who might have encountered the same problem. If your attitude is, 'why should I waste my time explaining blah blah blah', why do you expect help from others ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

You are welcome! :)
Btw, If your problem is solved, you can mark this thread as solved.

nav33n 472 Purple hazed! Team Colleague Featured Poster

:S oh!

nav33n 472 Purple hazed! Team Colleague Featured Poster

Check this link. I dunno if this will solve your problem. But you can give it a try!

nav33n 472 Purple hazed! Team Colleague Featured Poster

As you can see, theres a difference in style and font. As far as I know, most people dont use it !

<b>Note:</b> These tags are often used to display computer/programming code.

Ref: The example in the link provided by you.
Maybe they use it in code examples that you see in many books.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Okay! I checked this and even this works. Select * from tables where CREATE_TIME > "2008-02-01" and CREATE_TIME < "2008-02-08" Cheers,
Naveen

nav33n 472 Purple hazed! Team Colleague Featured Poster

when in doubt check out the mysql manual...

http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html

umm..nowhere in the manual says how to fetch only those records which lies between 2 dates ! :S

nav33n 472 Purple hazed! Team Colleague Featured Poster

I have not checked your query. But this will work.

$query="select * from table where date_column between "2001-01-05" and "2001-01-10";

This will print all the records where the date_column value lies between the first date and the second date.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Your validation is fine. And you can use the same for all 3 files that you want to read.

nav33n 472 Purple hazed! Team Colleague Featured Poster

You are welcome!

nav33n 472 Purple hazed! Team Colleague Featured Poster

Welcome to Daniweb Jane. I guess the problem is with the harddisk. Bad sectors maybe! Cant boot from a disc ? Have you changed the boot order in the bios ? Check this link. . This might be of some help to you !

Cheers,
Naveen

nav33n 472 Purple hazed! Team Colleague Featured Poster
<?php
echo "<table border=1>";
echo "<th bgcolor=\"red\">test</th>";
echo "</table>";
?>

Hope that helps.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Glad that you solved your problem. But still it isnt safe :( Anyways, All the best!

nav33n 472 Purple hazed! Team Colleague Featured Poster
<?php
if(isset($_POST['submit'])){
  print_r($_POST);
}
?>
<html>
<body>
<form method="post" action="test.php">
<input type="text" name="name"><br />
<input type="text" name="email"><br />
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

Click on "toggle plain text" and then copy the code. :) And I meant [ code=php] [ /code] ! < without the whitespace.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yep. You should have an extension .php for your scripts if you want apache to parse php. Can you show us the script you are using ? (because the code example that I gave you shouldn't give this error!)

nav33n 472 Purple hazed! Team Colleague Featured Poster

hmm. Try this script. Tellme if it works.

<?php
if(isset($_POST['submit'])){
  print_r($_POST);
}
?>
<html>
<body>
<form method="post" action="test.php">
<input type="text" name="name"><br />
<input type="text" name="email"><br />
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

Call this test.php, put it on your server. Tellme if it works.

nav33n 472 Purple hazed! Team Colleague Featured Poster

No. What I am asking you is, how do you execute your script ? Are you double clicking the file or are you typing the path in the address bar ?
Well, If you want to learn the basics of php, w3schools is the best site to start off.

nav33n 472 Purple hazed! Team Colleague Featured Poster

umm.. I hope you have started apache service and you are executing your script like, http://localhost/yourfilename.php ? When are you getting that error ? After you submit the page ? What is your url ?
PS. Next time you post your code, please wrap it within [ code=php] [ /code] tags.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Welcome to Daniweb Amanda!

nav33n 472 Purple hazed! Team Colleague Featured Poster

try action="<?php echo $_SERVER; ?>"

nav33n 472 Purple hazed! Team Colleague Featured Poster

'm not sure if this would be the best way to do it...

Exactly. Its not the best way. Its not safe. And, btw, file_put_contents only works if your php version is >= 5. Even I suggest you to use mysql database. But, if you can't have a database, then you can use a text file(or xml) as a 'database'.

nav33n 472 Purple hazed! Team Colleague Featured Poster

you are welcome :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Try this.

This lists all the images in the specified folder.

<?php
$jpgdir = "./uploads/jpg/";

$dh = opendir($jpgdir);
echo "JPG FILES";

print("<table border=2>");
while (($file = readdir($dh)) !== false) {
	if($file!='.' && $file!='..')
	{
		print( "<tr><td>");
		print("<form name=del method=post action=\"del.php\">");
		echo "<A HREF=\"$jpgdir/$file\"><IMG src=\"$jpgdir/$file\"/ height=70 width=70></A><BR>\n";
		echo "<input type=\"hidden\" name=\"path\" value=\"$jpgdir/$file\">";
		print("</td><td>");
		echo "<input type=\"submit\" name=\"del\" value=\"Delete\">";
		print("</td></tr>");
		print("</form>");
	}
}
print("</table>");
closedir($dh);
?>

This code deletes that image and sends the user back to the image listing page.

<?php
$jpgdir = "./uploads/jpg/";;
$file=$_REQUEST['path'];

// Open a known directory, and proceed to read its contents
if (is_dir($jpgdir)) {
   if ($dh = opendir($jpgdir)) {
              unlink($file);
       closedir($dh);
   }
}
header("location: jpgview.php");
?>

This works.

Cheers,
Naveen

nav33n 472 Purple hazed! Team Colleague Featured Poster

umm.. He wants to count the number of child entries for a particular parent. For example, for mainid=1(description John), there are 2 entries in child. He wants to calculate the entries of each parent, put it in the first column named Total child. Then the sum of Is_important in the second column and the sum of has_been_used in the 3rd column. He wants this to be returned as one resultset !

Edit: Zadj, If you could show us what/how you have achieved this, we can try to debug/find errors in it.

nav33n 472 Purple hazed! Team Colleague Featured Poster

SELECT * FROM Customers where EmailAddress like '%" @ "%'"

Why do we need double quotes around @ ? ("@")
PS. I tried it and it gave me an error.
We can use SELECT * FROM customers where emailaddresses like '%@%';

Jade_me commented: :P +1
nav33n 472 Purple hazed! Team Colleague Featured Poster
<?
$file = isset($_POST['file']) ? $_POST['file']:"testfile.php";
$newstring = '<!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>Untitled Document</title>
</head>
<body>
<form action="newfile.php" method="post" name="new">';
echo $file;
$newstring.='<input name="file" type="text" size="30" maxlength="60" /><input name="" type="submit" value="CREATE FILE" />
</form>
</body>
</html>';
$newfile = fopen($file, "w+") or die ("could not create file.");
fclose($newfile);
$myfile = @fopen($file, "w+") or die ("could not open file.");
@fwrite($myfile, $newstring) or die ("could not write to file");
fclose($myfile);
$msg = "<p>File created <a href='$file'>$file</a> and it has stuff in it</p>";
echo $msg;
?>

There. This should work! You were using php tags in a variable which was already in a php script.

Cheers,
Naveen

sagedavis commented: This worked out great, thanks +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Oh, Well, first of all, you are not fetching the record from the table. What you are doing is, checking if a row exists in the table with the provided details. If yes, then print the "input values". But you should do something like this.

<?php
.....blah blah blah.....
$query="select * from table where firstname='$fname' && lastname='$lastname' && date_of_birth='$dob'";
$result=mysql_query($query);
$row=mysql_fetch_array($result); //if you are sure that the query returns only 1 row. If you are not sure, then use the while loop. while($row=mysql_fetch_array($result)){
}
//$row will have all the information. You can then use the columnname as the index.
echo "Welcome". $row['fname']."  ".$row['lastname']." Your date of birth is". $row['date_of_birth']." and your registration number is ". $row['reg_num'];

mysql_num_rows returns only the number of rows returned by that query.
:) Hope it helps.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Thats because, reg_num variable is null. Where is reg_num coming from ? From a previous page ? You can use print_r($_POST) for debugging purpose. This will print all the variables that are posted from page1 to page2.(PS. You should write print_r($_POST); in page 2.) Try that and tell me if you are posting reg_num !

nav33n 472 Purple hazed! Team Colleague Featured Poster

You can do that using css.

<html>
<body>
<a href="http://www.example.com" style="text-decoration: none;">click here</a>
</body>
</html>

To apply the same style to all hyperlinks, use this.

<html>
<head>
<style type="text/css">
a {
text-decoration: none; 
}
</style>
</head>
<body>
<a href="http://www.example.com">Click here</a>
</body>
</html>

This will take off the underline from all a href links.

nav33n 472 Purple hazed! Team Colleague Featured Poster

You need to write style for that (using css ie.,) Check this out.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Lol.. great idea though !

nav33n 472 Purple hazed! Team Colleague Featured Poster

hmm.. I would use confirm box too. But if you want to have custom buttons, thats the only way, a popup.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yep. Or put the above code in a javascript function, and call that function with onclick event.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Well, I write my own page with 2 buttons to do required operation. Then I call that page using the following.

window.open(url,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width="300", height="200")

Here, url is the page that I want as popup.

nav33n 472 Purple hazed! Team Colleague Featured Poster

also how am i going to modify my whole login script to use tihs now? I have it verifying the first name and then the last name... Then i use that and create a session variable to use later on so i know whos voting.

how can i do that now?

Don't you have a separate username/loginname field ? Umm.. My suggestion is to change the table structure itself. But if you want to use the same table, then you can ask the user to enter his firstname and password, and then compare it with the values in the table for that first name and password.

dani190 commented: awesome help yet again! Well done +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

ok it works but now the firstname and lastname come up all bunched into 1 word, hows a space added there.

Add a white space in the concat function.

nav33n 472 Purple hazed! Team Colleague Featured Poster

try it out ! :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Well, If you dont have an id field, what/how do you plan to update the table ? because, there can be people with same first name and same last name. You need to have an id field. Anyway, you can make use of concat function in mysql to join those 2 fields.
Eg. select concat(firstname,lastname) as name from table;

nav33n 472 Purple hazed! Team Colleague Featured Poster

I guess you didn't see my example ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

;)

nav33n 472 Purple hazed! Team Colleague Featured Poster

never print or echo anything after using header.

After using header ? Are you sure ? You can print anything you want after calling header function. You shouldn't print anything before header. :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Nope. You should write your own popup for that (with 2 buttons ie.,)

nav33n 472 Purple hazed! Team Colleague Featured Poster

My suggestion is, always use integer values if you are are updating a table based on the choice made. Because, it ll be easy for you to update.
But I guess your table structure is not that good.. Do you have an autoincrement field(id or counter or anything like that ?). If you do, then you can fetch first name, last name and id of every users, put id for option value.
Eg. say you have id, firstname, lastname in your table.

<?php
//connect
//select db
$query="select id,firstname,lastname from table";
$result=mysql_query($query);
$option="";
while($row=mysql_fetch_array($result)){
$name=$row['firstname']." ".$row['lastname'];
$id=$row['id'];
  $option.="<option value=$id>$name</option>";
}
?>

This will show the first name and last name as a choice, but when selected, it sends the id of that user.

Cheers,
Naveen

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yeah. Its for debugging. And I have no clue why your query doesn't work..

dani190 commented: Awesome help, helped me through the creation of a program. Allowed me to learn a lot also... +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Yep.. well, you use die to print out the message on failure. mysql_query($query) or die("your own message..."); This will execute your query. If it encounters any error, it will stop the terminate the execution of the script and print the message of die function.

nav33n 472 Purple hazed! Team Colleague Featured Poster
$query="UPDATE grads SET vote_status = 1 WHERE USER_ID ='".$_POST['user_id']."'" or die(mysql_error());

You should have "die" function while using mysql functions and not in query itself.