nav33n 472 Purple hazed! Team Colleague Featured Poster

Awesome!

nav33n 472 Purple hazed! Team Colleague Featured Poster

I said it in the other thread, have an onchange event to submit the page when you select a value from the dropdown list. When the page is submitted, you can know which option was selected from the dropdown list. ($val = $_POST; ) Then query the table with this value as condition and retrieve the data.

OmniX commented: awesome as usual ;) +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Yes. Possible.

<?php
if($_POST['metode'] == "Authorname") {
//if the user selects authorname from the list then use this query
$query = "select * from tablename where firstname like '%$searchtext%' or lastname like '%$searchtext%'";
} else {
   // else use other query 
}
dottomm commented: Fantastic!!!! +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Umm.. you are passing the id as a parameter. Why are you trying to assign the value of $id to t (in javascript function) ?

<html>
<head>
<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
<!--
function login(t) {
alert(t);
}
-->
</SCRIPT>
</head>
<body> 
<?php
$id=$_GET['id'];
print "<input type='button' name='button' value='button' onClick=login('$id')>";
?>
</body>
</html>

This works just fine !

peter_budo commented: Another great snippet +7
nav33n 472 Purple hazed! Team Colleague Featured Poster

document.formName.task.value=='del';

Should be document.formName.task.value='del';

Venom Rush commented: helped alot ;) +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Then you can truncate the table instead of dropping it and creating a new one ! mysql_query("Truncate table tablename"); will do the trick !

kevin wood commented: if you need help with php/mysql he is your man +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

if (isset($_POST)) {

is open and not closed.

jino commented: thx u very much +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Whenever a user opens a page, add page's name to the session variable. Since you are adding it to the session, If he opens another window for the same page, redirect him to error page.
Eg.

//This is main.php which has link to page1.php
<a href="page1.php">Page 1</a>

This is page1.php

<?php
session_start();
if($_SESSION['page']=="page1"){
 header("location: error.php");
} else {
	$_SESSION['page']="page1";
}
echo "Hi";
?>

Now, right click on the page1.php and open it in a new page. It displays "Hi". Do the same again and you will be redirected to error.php.

Cheers,
Naveen

carobee commented: Great mind always at work +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Do you have these files on a server so that we can check the output ? Because, I don't understand what exactly is the problem..

kevin wood commented: very good at what he does. +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Yes. It is possible to store the path of the file. The datatype is varchar as you have mentioned. Store the path, then display the image by retrieving the path from the table and use it in the image tag.

$query = "select path from table";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
$path = $row['image_path'];
echo "<img src = '$path'>"; //list all the images 
}
kevin wood commented: is very helpful and gives good feedback +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

And you don't have that syntax error anymore. Right ? Now, if that solves your problem, well and good. If it doesn't, you need to be specific about your problem.

kevin wood commented: he is very helpful all the time +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

You can use is_int
Eg.

if(is_int($letter2)){
$letter3="#";
} else {
 $letter3=$letter2;
}
Scottmandoo commented: Thanks +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Print out your query, execute it in phpmyadmin/ mysql console and see if it works. You can also give "die" to check if your query is working or not.
ie.,

$query = mysql_query("your query") or die(mysql_error())";
justted commented: Very helpful :O) +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

You dont need <?= because you are already echoing something ! You can do this.

echo "<form name=\"tsgh_add\" method=\"post\"  action=".$_SERVER['PHP_SELF']." onSubmit=\"return checkWholeForm(this);\">";
Venom Rush commented: Rocking! I initially thought of that myself but because my submit button's type was wrong I thought that I was wrong :P +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

When the user clicks apply for the first time, get his username (and password ?) from the table. Add it to the session variable. Then check if the session variable exists. If it does, then don't ask him for username and password. If session variable doesn't exist, ask him for username and password and add it to the session.

jino commented: Simple and comprehend +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

http://www.w3schools.com/php/php_mysql_select.asp Check this. Instead of echoing $row and $row in the example, assign it to a variable and use it as the 'value' of the textbox. <input type="text" name="firstname" value="<?php echo $firstname; ?>">

karthik_ppts commented: helpful post +5
nav33n 472 Purple hazed! Team Colleague Featured Poster

And

$result = mysql_query("SELECT * FROM images WHERE 'Broad1'='$thumb_name'");

Should be

$result = mysql_query("SELECT * FROM images WHERE Broad1='$thumb_name'");

No quotes around Broad1.

Ah! correct.. I couldn't spot that one!

kevin wood commented: very helpful +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

It displays thrice because its looping three times. You can do it this way.

<?php
mysql_connect("localhost", "root", "1234") or die(mysql_error());
mysql_select_db("userlist") or die(mysql_error());
$name=$_POST['name'];
$password=$_POST['password'];
$query = "SELECT * FROM user where username='$name' && password='$password'"; 
$result = mysql_query($query) or die(mysql_error());
if(mysql_num_rows($result) > 0){
	echo "Success!";
}
else
{
	echo "Sorry! Wrong name!!";
}
?>
nav33n 472 Purple hazed! Team Colleague Featured Poster

There is NO default config.php and database.class in php. :)

Sulley's Boo commented: eyse hee -_- meri marzi mote .. +5
nav33n 472 Purple hazed! Team Colleague Featured Poster

No. $x="person".$number."male";
echo $$x will print the value stored in $person1male. (considering $number has the value 1 in it!)

OmniX commented: Once again helped me with another php problem, thanks ;) +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Yep. Or you can write the comments to a file and then display the contents of that file.

whoisit commented: Always willing to help. +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Line 179. $result = mysql_query->($sql); should be $result = mysql_query($sql); :)

Suetan commented: Good advice for debugging PHP script... thanks Nav33n +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

oh..hmm ! If the user has uploaded the images, there will be an entry for every uploaded images in the database. (ie., the path of the 5 images.) Get all the records for that particular user and then delete them. for example, if the user with userid 3 has uploaded 5 images. There will be 5 entries in the table image_upload(which contains the path of the images).

$q="select * from image_upload where userid='5'";
$result=mysql_query($q); //the query returns 5 records 
while($row=mysql_fetch_array($result)){
  $imagepath=$row['path']; //$imagepath will have the path of the uploaded image. 
unlink($imagepath);//delete the file
//then delete the directory. I hope you are saving the images into the directory which is named after userid.
}
rmdir(5); //remove the directory with userid 5. 
?>
Sulley's Boo commented: *grabs nav33n by the ear* i (((DONNOT))) wear glasses anymore! +4
nav33n 472 Purple hazed! Team Colleague Featured Poster

username is root by default.

mysql_connect("localhost","root","")

Grr! I got beaten by a few seconds again ! :P

Sulley's Boo commented: mote, LOL, jaldi bhaaga karr :P +4
nav33n 472 Purple hazed! Team Colleague Featured Poster

hmm! okay !

scorpionz commented: Naveen is a Great Guy ... With Great Knowledge +2
nav33n 472 Purple hazed! Team Colleague Featured Poster

:) lol.. congrats ! finally the problem is solved!

nav33n 472 Purple hazed! Team Colleague Featured Poster

Then code please !

nav33n 472 Purple hazed! Team Colleague Featured Poster

Why do you need the stuff in red?

In php, if we want to echo something, its done like this. echo "Welcome...";

Sulley's Boo commented: "You don't have to" ..... give me a rep back whenever i give you one :P mote me tera khoooooon bahaadungiiiii baliiii ke bakre. AND, Slapping is fun. +4
iamthwee commented: Boo is right, you take what she says toooo seriously. She was just being playful. Lighten up. +13
nav33n 472 Purple hazed! Team Colleague Featured Poster

Lunch.

Php or Java ?

Sulley's Boo commented: You don't have to. +4
nav33n 472 Purple hazed! Team Colleague Featured Poster

oops i didnt notice the extra 0 there.

Dude! you noticed an extra 0 there :P

Btw, Congrats ShawnCplus!

Sulley's Boo commented: he meant that he didn't notice the extra zero he typed by mistake in his reply <_< *slaps* +4
nav33n 472 Purple hazed! Team Colleague Featured Poster

Something is in the works regarding this but those of you without access to Area 51 will have to wait and be surprised.

Wow! I can't wait to be surprised :P

iamthwee commented: You don't have to wait, just look in the mirror and you will be so surprised you'll sh*t yourself. +13
~s.o.s~ commented: Don't mind thwee, he is speaking from personal experience methinks. +20
nav33n 472 Purple hazed! Team Colleague Featured Poster

yep! once in a while! ;)

Mild seven

Ferrari or Mc laren ?

Sulley's Boo commented: Fish is healthier <_< +4
nav33n 472 Purple hazed! Team Colleague Featured Poster
$i=0;
while($row=mysql_fetch_array($result)){
$photo=$row['photo'];
if($i==0) { //initially, i is 0, so it inserts a new tr. 
   echo "<tr>";
}
$i++;
echo "<td>$photo</td>"; //add the photo
if($i==4){ //adds 4 photos, once its done, make i as 0 to insert a new <tr>, end the existing <tr>.
  $i=0; 
  echo "</tr>"; 
}
}

Cheers,
Naveen

Morty222 commented: Awesome!!! +1
nav33n 472 Purple hazed! Team Colleague Featured Poster
<?php
//connection
//select db
$selected_id=$_POST['select'];
$query="Select * from table";
$result=mysql_query($query);
$options="";
while($row=mysql_fetch_array($result)){
   $name=$row['name'];
   $id=$row['id'];
   if($selected_id==$id){ 
          $selected="selected": 
    }
   else {
      $selected=""; 
   }
   $options.="<option value='$id' $selected>$name</option>";
}
?>
<html>
<body>
<form method="post" action="test.php">
Select something: <select name="select">
<?php echo $options; ?>
</select><br />
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

Cheers,
Naveen

Morty222 commented: Great answers. +1
nav33n 472 Purple hazed! Team Colleague Featured Poster
<?php
$handle = fopen('somefile.csv', 'r');
if ($handle)
{
  
    //the top line is the field names
    $fields = fgetcsv($handle, 4096, ',');
   
    //loop through one row at a time
    while (($data = fgetcsv($handle, 4096, ',')) !== FALSE)
    {
        $name=$data[0];
        $address=$data[1];
        $bday=$data[2]; //considering name will be in the first field, address in the second and bday in the third field.
        // Get all the fields from the csv file
       $query="insert into table (name,address,birthday) values ('$name',$address','$bday')";
       mysql_query($query);
    }

    fclose($handle);
}
?>

That's how you do it.

Venom Rush commented: Always adding to your rep ;) Such a great help +1
nav33n 472 Purple hazed! Team Colleague Featured Poster
<?php
if(isset($_POST['team']))
{
	foreach($_POST['team'] as $value){
		$insert=mysql_query("INSERT INTO team('team') VALUES ('$value')");
	}
}
?>
<html>
<body>
<form method="post" action="chk123.php">
<input type="checkbox" name="team[]" value="AG"> Argentina <br />
<input type="checkbox" name="team[]" value="GE"> Germany <br />
<input type="checkbox" name="team[]" value="BR"> Brazil <br />
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

There! That will work :)

Cheers,
Naveen

Edit: The error was because, you had opened php tag but you opened it again.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Okay.. The simplest way is, put whatever you want in a variable and print that variable whereever you want. For example,

<?php
$text1="This is some random text ! blah blah blah..<br />I just added a break.";
$text2="One more test.. ";
?>
<html>
<body>
<table>
<tr>
<td>
<?php echo $text1; ?>
</td>
</tr>
<tr>
<td>
<?php echo $text2; ?>
</td>
</tr>
</table>
</body>
</html>

This is just an example. You can do it this way.
Hope that helps.
Cheers,
Naveen

TaoistTotty commented: Great Help +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

Okay ! after much head scratching and testing, this is what I found. (I hope the div class will remain the same! :S)

<?php
$url = 'http://www.directcosmetics.com/results/products.cfm?ctype=ME&range=Hummer&code=34744';
$html = file_get_contents($url);
$reg = '/<div class=\"value\">(.*)<font size="3">(.*)<\/font><\/div>/s';
preg_match($reg,$html,$matches);
print str_replace("&pound;","",$matches[1]);                                       
?>

Hope that helps ! :)

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
mysql_connect('localhost','root');
mysql_query("CREATE DATABASE IF NOT EXISTS employees");
mysql_query("USE employees");
mysql_query("DROP TABLE IF EXISTS employees");
mysql_query("CREATE TABLE employees (
SSN varchar (30) NOT NULL,
firstName varchar (30) NOT NULL,
lastName varchar (30) NOT NULL,
birthday date NOT NULL,
employeeType varchar (30) NOT NULL,
departmentName varchar (30) NOT NULL,
PRIMARY KEY (SSN)
) TYPE=INNODB");
echo "Database and table created successfully...";
?>

You can do it this way..

Cheers,
Naveen

peter_budo commented: Very nice example +7
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

nl2br function!

Venom Rush commented: Helpful response as always +1
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

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

Well, as the error says, the columns specified in the insert query doesn't match with the values you are passing. Make sure that you have all the columns(in your table) ! insert into table (col1,col2) values (val1) and insert into table (col1) values (val1,val2) both would generate same error.

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

:(

LOL.. i know.. you have already given me reps for a php question(and you can give reps only once per day!)

Sulley's Boo commented: ro matt mere shair :P ye le rep! +4
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
$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