nav33n 472 Purple hazed! Team Colleague Featured Poster

by the way you usually save my ass adding to my reputation points, rashakil fool needs to wait a week to deduce your one contribution.

Stop calling him Rashakil fool, maybe he will stop the 'war of words' too! ;)

nav33n 472 Purple hazed! Team Colleague Featured Poster
$result = mysql_query("select * from table where bookingid='blahblah'");
if(mysql_num_rows($result) > 0) {
//delete booking id
} else {
 //booking id doesn't exist
}
nav33n 472 Purple hazed! Team Colleague Featured Poster

The simplest way to validate username and password is to query the table with both username and password and see how many rows it returns. For example,

$query = "select * from table where username='$username' and password='$password'";
$result = mysql_query($query);
if(mysql_num_rows($result) == 1) {
 //echo valid user
} else {
 //echo invalid user
}

In your script, I don't see a need why you need a while loop. Since the usernames are unique and 1 username returns only 1 record, there is no need for a while loop. The rest of the script looks okay..

nav33n 472 Purple hazed! Team Colleague Featured Poster

GAH! Just realized how old this thread is, how did it get resurrected?!:-O

;) Someone read the Book of the dead I suppose !

nav33n 472 Purple hazed! Team Colleague Featured Poster

Pretty simple. Check this example.

<?php
if(isset($_POST['submit'])) {
	$string = nl2br($_POST['textarea']);
	echo $string."<br />";
	echo substr_count($string, "<br />");
}
?>
<html>
<body>
<form method='POST'>
<textarea rows="30" cols="30" name='textarea'>
</textarea>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

I am using nl2br function to convert newline to <br />. Then I am counting how many <br />'s are present in the sting. This would give the count of the "Enter" pressed by the user.
Cheers!

nav33n 472 Purple hazed! Team Colleague Featured Poster

Without submitting the page, You can't get the selected option's value in php. However, in Javascript, you can access it.

nav33n 472 Purple hazed! Team Colleague Featured Poster

My first post was in Community Introduction forum. :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Thats awesome! Cheers!

nav33n 472 Purple hazed! Team Colleague Featured Poster

[tex]

:)

nav33n 472 Purple hazed! Team Colleague Featured Poster

@Kevin wood, Your script seems fine.
Try this.

$query = "SELECT email FROM emails";
	$result = mysql_query($query) or die(mysql_error());

	while($row = mysql_fetch_array($result)) {
	
	$emailaddress[] = $row['email'];
	}


	// Contacts
	//$replyName = $merc_replyId;
	//$replyEmail = $merc_replyAddress;
	$i=0;
	foreach($emailaddress as $contactemail) {
	$replyName = "PiPonliine";
	$replyEmail = "info@piponline.info";

	$contactname = "";
	

	// Subject
	$subject = "Website Update";

	// Headers
	$headers = "MIME-Version: 1.0" . PHP_EOL;
	$headers .= "Content-type: text/html; charset=iso-8859-1" . PHP_EOL;
	$headers .= "From: ".$replyName." <".$replyEmail.">" . PHP_EOL;
	$headers .= "BCC: ".$contactname." <".$contactemail.">\r\n" . PHP_EOL;
	

	mail($contactemail, $subject, $message, $headers);
	$i++;
	}
  echo "$contactemail"; //this will print only 1 email address, which is the last one
  echo "<h2>Email notification sent</h2>";
  echo "<h2>".$i." mails sent</h2>";

This definitely works. (I tried with 3 email addresses)

kevin wood commented: very helpfull +2
nav33n 472 Purple hazed! Team Colleague Featured Poster

Yep! You are right.. Notices are important. They make you a better programmer :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

The way you are doing it is wrong.
Try this.

$qa = mysql_query("SELECT DATE(DATE_SUB(now() , INTERVAL 31 DAY))  as actual_date");
while ($row = mysql_fetch_array($qa)) { 
	$a = $row[actual_date]; 
}
$qb = mysql_query("SELECT CURDATE();");
while ($row = mysql_fetch_array($qb)) { 
	$b = $row[0]; 
}
mysql_query("SELECT * from $vtable WHERE (trxdate >= '$a') and (trxdate <= '$b') " );
nav33n 472 Purple hazed! Team Colleague Featured Poster

Here are my 2 cents. You can disable those notices by using error_reporting(E_ALL ^ E_NOTICE); on top of your script. If you don't want to disable it but still want to fix the notices, initialize a variable to 0 (or null if its a string). ie.,
$i = 0;
$string = "";
That would fix the error(Notice).
You can learn more on error reporting here. http://in2.php.net/error_reporting

nav33n 472 Purple hazed! Team Colleague Featured Poster

You cannot access $_POST in action2.php . Its only available in action.php since it is posted from form.php to action.php . In order to make it available in action2.php (which is a hyperlink), you have to pass it in the query string like this.

echo "<a href=action2.php?startdate=".$_POST['startdate'].">Click here to go to action2.php </a>";
//You can then access startdate in action2.php as $_GET['startdate']

If you don't want to pass it in the query string, you can use sessions (But I think using sessions only for this particular variable is useless).

nav33n 472 Purple hazed! Team Colleague Featured Poster
header("location: index.php?variable1=".$variable1."&variable2=".$variable2);

:)

OmniX commented: Thanks as always nav ;) +2
nav33n 472 Purple hazed! Team Colleague Featured Poster

But im just wondering if I can do the same thing using headers header("Location: index.php?variable=1")

Yes you can. Then you can acess the 'variable' in index.php just like how you do it using $_GET.

nav33n 472 Purple hazed! Team Colleague Featured Poster

table = mysql reserve keyword.

Use `table` instead.

kevin wood commented: always very helpfull and gives good answers +2
nav33n 472 Purple hazed! Team Colleague Featured Poster

$result will have a result resource. You need a loop to get all the result. mysql_fetch_array() will fetch only 1 record at a time.

while($row = mysql_fetch_array($result,MYSQL_NUM)) {
print "<pre>";
 print_r($row);
print "</pre>";
}
nav33n 472 Purple hazed! Team Colleague Featured Poster

So we got two solutions to one problem. Thats what I call a good days work.
(pfiuuh.. its been 36 hours since sleep so I'm outta here, thanks for a nice quiz/problem. It will come in handy for sure.)

Yeah.. 1 solution, good. 2 solutions, better :)

Get some sleep dude! Cheers!

nav33n 472 Purple hazed! Team Colleague Featured Poster

@Dickersonka, I have been advised on so many occasions not to use joins. Joins are relatively slower compared to subqueries. This is what I have read.

nav33n 472 Purple hazed! Team Colleague Featured Poster

YAAAA... Knew it would be doable with a subquery...
I just tested this...

select `fn`,`ln`, (select count(`orderid`) from `order` where `client`.`username`=`order`.`username`) AS `xcnt` FROM `client`
 WHERE `client`.`active`='1'
 GROUP BY `username`;

It returns a count of orders per client and sets the xcnt = 0 where no orders occurred, but shows first name and last name per client
who is active in the system

Subqueries are even better.. :)

select `user_id`, (select count(`comment`) from `comments_table` where `comments_table`.`user_id`=`users_table`.`user_id`) AS `xcnt` FROM `users_table`
 GROUP BY `user_id`;

I edited your query and it works ! Eureka ;)

nav33n 472 Purple hazed! Team Colleague Featured Poster

I modified your query a little bit and I don't know why it doesn't return users who have post = 0.

SELECT COUNT(
COMMENT ) AS `post_count` , (

SELECT `user_id`
FROM `users_table` u
WHERE `comments_table`.`user_id` = `u`.`user_id`
) AS `ugrp`
FROM `comments_table`
GROUP BY `ugrp`
ORDER BY `post_count` DESC
LIMIT 0 , 30;

Another query.

SELECT u.user_id, count( * ) AS post_count
FROM users_table u, comments_table p
WHERE u.user_id = p.user_id
GROUP BY u.user_id
LIMIT 0 , 30

Both returns the same result.


Edit: @Dickersonka, Your query works like a charm! Great job! :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Nice queries.. But still, that wouldn't solve what OP is looking for.. The still doesn't return the count as 0, if a user doesn't have any posts. I created dummy tables to create the same scenario and I am also clueless ! :S

nav33n 472 Purple hazed! Team Colleague Featured Poster

Okay.. This is a sloppy example, just to give you an idea.

<?php
if(isset($_POST['submit'])) {
	print "<pre>";
	print "Id array => <br />";
	print_r($_POST['id']);
	print "Order no array => <br />";
	print_r($_POST['orderno']);
	print "</pre>";
       for($i=0;$i< count($_POST['orderno']); $i++) { //there will be equal number of elements in both id array and orderno array. 
		echo $_POST['id'][$i]." -> ".$_POST['orderno'][$i]."<br />";
	}
}
?>
<html>
<body>
<form method="post">
<?php 
for($i=0;$i<5;$i++) {
?>
<input type='hidden' name='id[]' value='<?php echo $i; ?>'> 
Order <?php echo $i; ?>:<input type="text" name="orderno[]"><br />
<?php 
}
?>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

Instead of for loop, you will have while($row = mysql_fetch_array($result)) . Instead of assigning $i as value to the hidden field, you will have the counter/id field of the table.
You can then map the values of the array entered by the user in the orderno field to id field.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yeah, possible. Have a hidden field in the form to store the id. When the user clicks submit, update the table :)

update table set orderno='".$_POST['orderno']."' where id='".$_POST['id']."'";
nav33n 472 Purple hazed! Team Colleague Featured Poster

:) You are welcome!

nav33n 472 Purple hazed! Team Colleague Featured Poster

You can set up a cron job to run every day (or night) and have this query. If you can't have crons, you can run this script whenever the main page is loaded.

DELETE FROM Table
WHERE datecolumn < DATE(DATE_SUB(now() , INTERVAL 15 DAY))
nav33n 472 Purple hazed! Team Colleague Featured Poster

:) You are welcome!

nav33n 472 Purple hazed! Team Colleague Featured Poster

sorry people - i thought i did use the tags but anyway thank you all for your replies - will play with it tomorrow

@phpNewbie, We aren't talking about you. Vinothkumarc didn't use [code] tags. Infact, I appreciate you for using code tags. :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Hmm.. There was a little mistake in that query. Here, this works fine.

select * from images where fbid IN (
select fbid
from rating
group by fbid
HAVING count( fbid ) > 150
)

Cheers!

nav33n 472 Purple hazed! Team Colleague Featured Poster

Simply use double quotes.
ie., $num="0024"; Adding 0 before a number forces php to consider this as a octal number.
http://us3.php.net/int

nav33n 472 Purple hazed! Team Colleague Featured Poster

hey... y u copied... and pasted without any comments (my code)

:icon_rolleyes:

nav33n 472 Purple hazed! Team Colleague Featured Poster

start quote:

<html>
    <head>
    </head>
    <body>
        <?php
            // MySQL Connection Information
            $server = "localhost";
            $username = "sharlene";
            $password = "";
            $dbname = "baby_names";

            // MySQL Connect String
            $connection = mysql_connect($server,$username,$password) or die("Can't Connect to Mysql Server: 

".mysql_error());

            // Select the database
            mysql_select_db($dbname) or die("Can't connect to database: ".mysql_error());

            $gender = mysql_real_escape_string($_POST['gender']);
            $meaning = mysql_real_escape_string($_POST['meaning']);
            $name = mysql_real_escape_string($_POST['name']);
            $origin = mysql_real_escape_string($_POST['origin']);
      if($gender) {
        $whereArr[] = "gender = '" . $gender . "' ";
      }
      if($name) {
        $whereArr[] = "name LIKE '" . $name . "%'";
      }
      if($meaning) {
        $whereArr[] = "meaning LIKE '%" . $meaning . "%'";
      }
      if($origin) {
        $whereArr[] = "origin = '" . $origin . "' ";
      }
      if(count($whereArr)) {
        $where = @implode(" AND ", $whereArr);
        $where = ' WHERE '.$where;
      }

$sql = "SELECT * FROM names $where";

/*
if ($gender == 'both') { // no specific gender
  if ($origin == 'any') { // no specific origin
    $sql = 'select * from names';
  else { // an origin was specified
    $sql = "select * from names where origin = '".$origin."'"; 
  }

else { // a gender was specified

  if ($origin == 'any') { // no specific origin
    $sql = "select * from names where gender ='".$gender."'";
  else { // an origin was also specified
    $sql = "select * from names where origin = '".$origin."' and  gender ='".$gender."'"; 
}
/**/

            //execute SQL query and get result
            $sql_result = mysql_query($sql, $connection) or die(mysql_error());

        ?>
            <table border="0" align="center">
                <tr>
                    <th style="background: #ffd" >Name</th>
                    <th style="background: #efe">Gender</th>
                    <th style="background: …
nav33n 472 Purple hazed! Team Colleague Featured Poster
select * from images where fbid IN (select fbid from ratings HAVING count(fbid) > 150 group by fbid)

The subquery returns fbid of all the records which has a count of 150+ . The main query returns all the records which matches these fbid.
Read more about having clause here.. http://www.techonthenet.com/sql/having.php

Not sure if this will work. If it doesn't, we ll try some other way :)
Cheers!

nav33n 472 Purple hazed! Team Colleague Featured Poster

What does your query do ? Query the table 'photos' and for every photo, You are again querying the table 'ratings' if that photo's fbid has a count > 150 ?
I didn't get the question or what you actually want. Do these 2 tables have any common 'linking' field ? What is fbid ?

nav33n 472 Purple hazed! Team Colleague Featured Poster
$services = implode(",",$_POST['service']);
//This will combine the array $_POST['service'] and form a string
Use it in $msg. 
$msg = $services." are the services which are checked\n";

Clear enough ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

After

$result = mysql_query("SELECT * FROM clients WHERE clientID=$_POST[bookingID]");

Use

if(mysql_num_rows($result) > 0 ) {
// record exists.. Do whatever you want to do with that record
} else {
echo "<a href='backpage.php'>Click here to go back and change your booking id.. </a>";
}
nav33n 472 Purple hazed! Team Colleague Featured Poster

Use mysql_num_rows($result) For example,

$query = "select *from table where id='".$_POST['id']."'";
$result = mysql_query($query);
if(mysql_num_rows($result) > 0 ) {
//record exists
} else {
//record doesnt exit
}
nav33n 472 Purple hazed! Team Colleague Featured Poster

Emm.. You can mark this thread as solved if all your questions have been answered. If you are extremely happy with Maxmumford's help, you can add to his reputation. Click on 'Add to MaxMumford's Reputation', click on 'I approve', type your comment and Click the button!

nav33n 472 Purple hazed! Team Colleague Featured Poster

First of all, this question belongs to Javascript forum. Its a javascript related question. 2nd, Post your code and tell us what is not working. We aren't 24/7 free coding service to provide you with ready made code when you say "Please help me asap", or, "Its urgentttt".

nav33n 472 Purple hazed! Team Colleague Featured Poster

Hi
So how can we apply this to my query if you think it’s going to work?
Regards
HB25

It wont. You have to save it in varchar datatype, which again would cause you problems. For example, you can't sort the fields on date. You can't calculate the difference (or add) x number of days to this date field , etc.
Why do you want to store it in that format anyway ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

My suggestion is, store date in YYYY-mm-dd format itself. You can change the format using php's date function. As maxmumford has already mentioned, you can convert that date to unixtimestamp and use it in whatever format you want.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Hmm.. Okay! From what I have read so far, this is what STR_TO_DATE do.

STR_TO_DATE(date_string, format);

STR_TO_DATE function will format string and insert it to the date column. The second parameter 'format' is just to let mysql know in what format is the first parameter 'date_string' is in.

insert into table123 (reg_date) values (STR_TO_DATE('31/2004/04', '%d/%Y/%m'))

In the above example, date_string is 31/2004/04. I am asking mysql to insert this value to the table and the format in which I have given the date is, %d/%Y/%m. ie., date/Year/month .

nav33n 472 Purple hazed! Team Colleague Featured Poster
print "<pre>";
print_r($_POST['checkbox_element_name'];
print "</pre>";

Does it print anything ? There is nothing wrong in your code except the checkbox name may be wrong :)

Edit: And a thumbs up for using [code] tags in your first post You should close the tag correctly next time. :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

echo your query. Execute it in phpmyadmin. See what's the exact error.
P.S. I tried to work with str_to_date and I simply can't get it to work ! :-/

nav33n 472 Purple hazed! Team Colleague Featured Poster
<?php

// open database connection code and then my code as follows

$sql="UPDATE bookings SET startdate ='$_POST[startdate]',enddate='$_POST[enddate]',adults='$_POST[adults]',children='$_POST[children]',roomtype='$_POST[roomtype]', requirements='$_POST[requirements]'
WHERE bookingID = '$_POST[bookingID]'";
 
if (!mysql_query($sql,$con))
  {
  die('Error:  ' . mysql_error());
  } 

  print "Your booking ID ".$bookingID;
  
  echo "    has been changed";


$result = mysql_query("SELECT * FROM bookings WHERE bookingID='".$_POST['bookingID']."'");
if(mysql_num_rows($result) > 0 ) { 
 //only print this if there is atleast 1 row. This will avoid a lot of problems which could arise from mysql_fetch_array if there are no rows in the table
//I would also declare the table headers when I am sure at least 1 record exist. If there aren't any records, it wont print the html table 
echo '<table border=1>
<tr><td>Start Date</td><td>End Date</td><td>Adults</td><td>Children</td><td>Roomtype</td><td>Requirements</td></tr>';
$result_array = mysql_fetch_array($result);

echo '<td>'.$result_array['startdate'].'</td>';
echo '<td>'.$result_array['enddate'].'</td>';
echo '<td>'.$result_array['adults'].'</td>';
echo '<td>'.$result_array['children'].'</td>';
echo '<td>'.$result_array['roomtype'].'</td>';
echo '<td>'.$result_array['requirements'].'</td>';
echo '</tr>';
echo '</table>'; // this way it looks more neat
}
mysql_close($con);
?>

Also, mysql stores date in the default format yyyy-mm-dd . If you want to change this, you have to specify the column datatype as varchar. I don't recommend it since you can do so many date functions if the column is of date datatype.
Also, php's date function is so vast, you can modify any of your date format to whatever format you want.
Check here.
http://in.php.net/date

nav33n 472 Purple hazed! Team Colleague Featured Poster

How does your code look like ?


P.S. I will be out of town for 3 days, so, If not me, someone else will help you with your problem :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Dude!

For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

http://in.php.net/function.mysql-query
It will return false on error. There is no error in your query. Since there is no error, it will always return TRUE !!! Its better you use mysql_affected_rows.

God! Why did it take so long to realise this :D Yeah alright! I can sleep peacefully now.

Edit:

(@mysql_affected_rows($sql)==1) {

Thats not the correct syntax. mysql_affected_row takes only 1 parameter and thats the connection link identifier).

if(mysql_affected_row() == 1) { // if you are sure it affects only 1 row or else if(mysql_affected_rows() > 0 ) {
   echo "Updated...";
} else {
  echo "Not updated..";
}
nav33n 472 Purple hazed! Team Colleague Featured Poster

Yep. Since it doesn't update anything, no rows are affected.

http://in.php.net/mysql_affected_rows

When using UPDATE, MySQL will not update columns where the new value is the same as the old value. This creates the possibility that mysql_affected_rows() may not actually equal the number of rows matched, only the number of rows that were literally affected by the query.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Okay ! Found it.
Even though mysql_query returns a boolean value, you can't compare its value as

if($run === TRUE)

It has to be

if($run === "TRUE")  //or in lower case. It doesnt matter!

I am sure this will fix it.
Its 3.40 in the morning and I need to get my sleep :D