Jump to content

craygo

Staff Alumni
  • Posts

    1,972
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by craygo

  1. There is a TimeZone setting in php.ini. But I am not sure if it will help. You may have to set up your own function to do it. Ray
  2. I see what it is doing now. Since it is only a check no need to return the row, just a true of false will be fine <?php function getalliancename($alliance){ $qc="SELECT `alliance` FROM `alliances` WHERE `alliance` = '$alliance'"; $r=@mysql_query($qc) or trigger_error("Query: $qc\n<br />MySQL Error: " . mysql_error); $found = mysql_num_rows($r); if($found > 0){ return TRUE; } else { return FALSE; } } ?> Now this should work fine. <?php if ($cgi['submit']) { if (!$cgi['name']){ $echo= 'Please enter an alliance name'; }elseif (getalliancename($cgi['name'])){ $echo= "That alliance name is already taken"; }else{ $alliance = trim(addslashes($cgi['name'])); ?> Ray
  3. if you want to secure a section of a web app you are better off having an html login page and holding login information in a mysql database. otherwise you would have to have a login script on every page. Ray
  4. problem is you are using a bunch of queries then putting a break in. Why not use 1 query. <?php $s = array(33,34,35,36); $values = implode("', '", $s); $query="SELECT * FROM $tbl_name WHERE id IN ('$values')"; $result=mysql_query($query); while ($row = mysql_fetch_array($result)) { echo '<h5>', ($row['rem1']), '</h5>'; } mysql_free_result($result); ?><br /> Ray
  5. try this function days($date1, $date2){ $month1 = date("m", strtotime($date1)); $day1 = date("d", strtotime($date1)); $year1 = date("Y", strtotime($date1)); $month2 = date("m", strtotime($date2)); $day2 = date("d", strtotime($date2)); $year2 = date("Y", strtotime($date2)); $first = gregoriantojd($month1, $day1, $year1); $second = gregoriantojd($month2, $day2, $year2); $diff = abs($first-$second); return $diff; } Now you can use your dates from the database $days = days($date1, $date2); Ray
  6. Why not just share a folder and browse to it?? If the file is really big you could have issues with php timing out. In order to do it with PHP you would have to set up an ftp server on the computer downstairs that way your computer can connect to it and send the file. PHP will not work well with file shares across a network. Filezilla is a free ftp client/server google it. Ray
  7. If you want to remove more that one line you have to look for multiple line breaks then replace with one <?php $text = $_POST['tarea']; $array = array("\r\n\r\n", "\n\n", "\r\r"); $replace = "\r\n"; $newtext = str_replace($array, $replace, $text); echo nl2br($newtext); ?> Ray
  8. You will have to keep track of the visits either in some kind of text file of in a mysql database. but this will give you the ip address of the computer $ip = $_SERVER['REMOTE_ADDR']; then you will have to write the address to the preferred file or database Ray
  9. where is $user->ID being set?? Also, if you are querying the table to see if the alliance name exist, then you should put a check in to see if it is found. also you need to return the alliance name not echo it. <?php function getalliancename(){ global $alliance; $qc="SELECT `alliance` FROM `alliances` WHERE `alliance` = '$alliance'"; echo "$qc<br>"; $r=@mysql_query($qc) or trigger_error("Query: $qc\n<br />MySQL Error: " . mysql_error); $found = mysql_num_rows($r); if($found > 0){ $al = mysql_fetch_assoc($r); return $al['alliance']; } else { return FALSE; } } ?> your code is kind of confusing, you may want to post the whole class or page script to get some help on this. Ray
  10. if you want to write php code then use single quotes not double quotes. Single quotes will write things just as they are.
  11. Or you can divide the current with by the output width, get a ratio and multiply the height by the same ratio. If you want to keep your pics their original aspect ratio, you are better off just using a max size and resize the picture accordingly. there is an example in the FAQ/code snippet section of the forum. Ray
  12. add error checking at the end $query = mysql_query('SELECT Staff FROM biographies ORDER BY username ASC') or die(mysql_error()); Ray
  13. <?php $errors = ''; $res = @mysql_query($sql); if(!$res){ $errors .= "there is a problem with your query. Error: ".mysql_error();."<br>\n"; } echo $errors; ?> now you can gather all errors or even gather successful queries with an else. <?php $results = '';$res = @mysql_query($sql); if(!$res){ $results .= "there is a problem with your query. Error: ".mysql_error();."<br>\n"; } else { $results .= "Query $sql was run successfully<br>\n"; } echo $results; ?> Ray
  14. <?php $classes_arr[1] = array( // Adds a class at 12pm (1200 hours) 1200 => array( "html" => "<b>Hello</b><br>Solo", // Display 'Phsychology: Room 404' "style" => "background-color: #FFCC00", // use style property to change the background color "interval" => 0 // set the interval for 2hrs ), ?> Ray EDIT: damn phone calls
  15. Not sure I get what you want. Do you want a certain part of the array to be assigned to $classes_arr or just one values from the $echovalue array?? Ray
  16. $sql = "INSERT INTO `tablename` (`label`) VALUES ('labelname')"; $res = mysql_query($sql) or die(mysql_error()); $id = mysql_insert_id(); $update = "UPDATE `tablename` SET `c_id` = '$id' WHERE `id` = '$id'"; $ures = mysql_query($update) or die(mysql_error()); Ray
  17. 1. You have not passed $alliance on to your function. I am not sure if this is a class or not but you need to declare the variable $alliance for your first query. Either pass it to the function or set is globally. <?php function getalliancename(){ global $alliance; $qc="SELECT `alliance` FROM `alliances` WHERE alliance='$alliance'"; echo "$qc<br>"; $r=@mysql_query($qc) or trigger_error("Query: $qc\n<br />MySQL Error: " . mysql_error); } $fdr = $user->userName; // Gets username $mid = $user->ID; // Gets userID if ($cgi['submit']) { if (!$cgi['name']){ $echo= 'Please enter an alliance name'; }elseif (getalliancename($cgi['name'])){ $echo= "That alliance name is already taken"; }else{ $alliance = trim(addslashes($cgi['name'])); if ($alliance){ $q="INSERT INTO `alliances` (`alliance`, `mid`, `founder`, `members`) VALUES ('$alliance', '$mid', '$fdr', '1')"; echo "$q"; $r=@mysql_query($q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysql_error); }}} ?> 2.You can always use the same code on one page, then in the url, or post value you can set which table to use. Example: http://mydomain.com/alliance.php?page=alliances Now you can use a switch to query the correct table and view the data 3.number_format() is your friend '.number_format($row['members'], 0, '.', ',').' 4. Here is a function to display the difference in 2 dates. It is a little long but I made it to calculate ages for birthdays and such. <?php function datediff($date1, $date2){ if($date1 > $date2){ $month1 = date("m", $date1); $day1 = date("d", $date1); $year1 = date("Y", $date1); $hour1 = date("G", $date1); $min1 = date("i", $date1); $sec1 = date("s", $date1); $month2 = date("m", $date2); $day2 = date("d", $date2); $year2 = date("Y", $date2); $hour2 = date("G", $date2); $min2 = date("i", $date2); $sec2 = date("s", $date2); } else { $month1 = date("m", $date2); $day1 = date("d", $date2); $year1 = date("Y", $date2); $hour1 = date("G", $date2); $min1 = date("i", $date2); $sec1 = date("s", $date2); $month2 = date("m", $date1); $day2 = date("d", $date1); $year2 = date("Y", $date1); $hour2 = date("G", $date1); $min2 = date("i", $date1); $sec2 = date("s", $date1); } //seconds if($sec1 < $sec2){ $secdiff = ($sec1+60)-$sec2; $min1--;; } else { $secdiff = $sec1-$sec2; } // minutes if($min1 < $min2){ $mindiff = ($min1+60) - $min2; $hour1--; } else { $mindiff = $min1 - $min2; } // hours if($hour1 < $hour2){ $hourdiff = ($hour1+24) - $hour2; $day1--; } else { $hourdiff = $hour1 - $hour2; } $amountdays = date("t", $month1); // day if($day1 < $day2){ $daydiff = ($day1+$amountdays) - $day2; $month1--; } else { $daydiff = $day1 - $day2; } // months if($month1 < $month2){ $monthdiff = ($month1+12) - $month2; $year1--; } else { $monthdiff = $month1 - $month2; } // years $yeardiff = $year1 - $year2; // Edit below to show just the values you want $datediff = $yeardiff."Yrs ".$monthdiff."Mon ".$daydiff."Days ".$hourdiff."Hrs ".$mindiff."Min ".$secdiff."Sec "; return $datediff; } /* Uncomment below to use your uorrent form */ $date1 = mktime('16', '20', '15', '12', '14', '2008'); $date2 = mktime('18', '30', '30', '1', '2', '2008'); echo datediff($date1, $date2)." Since last logon"; ?> 5. Here is some code I use to mail an activation code to someone. you can add in the username and password to the email by just editing the $message. I made this with phpmailer. <?php if(isset($_POST['username']) && isset($_POST['password'])){ foreach($_POST as $f => $v){ if($f == "password"){ $fd[] = $f; $va[] = md5($v); } else { $fd[] = $f; $va[] = $v; } } $fd[] = "ip"; $va[] = $_SERVER['REMOTE_ADDR']; $fd[] = "regdate"; $va[] = date("Y-m-d H:i:s"); $fd[] = "activation_key"; $code = md5(rand(100, 10000)); $va[] = $code; $fields = implode("`, `", $fd); $values = implode("', '", $va); $sql = "INSERT INTO `users` (`$fields`) VALUES ('$values')"; // change this to match your table $res = mysql_query($sql) or die(mysql_error()); if($res){ include('class.phpmailer.php'); // change this to point to the phpmailer class $mail = new PHPMailer(); $mail->IsSMTP(); // set mailer to use SMTP $mail->Host = "smtp.1and1.com"; // specify main and backup server $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = "xxxxxxx"; // SMTP username $mail->Password = "xxxxxxx"; // SMTP password //$mail->SMTPDebug = 2; $mail->SetLanguage('en', $_SERVER['DOCUMENT_ROOT'].'/phpmailer/language/'); $message = "please click the link below to activate your account\n"; $message .= "<a href=\"http://mydomain.com/index.php?do=activate&code=".$code."\" />http://mydomain.com/index.php?do=activate&code=".$code."</a>\n"; $mail->From = "myemail@mydomain.com"; // edit the from e-mail address $mail->FromName = "Support"; // Edit the name $mail->Subject = "Your account with Automarket.ro"; //edit the subject $mail->IsHTML(true); $mail->AddAddress($_POST['email']); $mail->Body = $message; $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; if(!$mail->Send()){ echo "Confirmation e-mail cannot be sent. Error: ".$mail->ErrorInfo; } else { echo "A confirmation e-mail has been sent to {$_POST['email']}"; } } else { echo "You application cannot be completed"; } } else { // show the form to register below } ?> Ray
  18. just set the auto-increment field as the primary key so you have at least one field indexed. You can set a field as auto-increment but phpmyadmin will let you save it without a primary key. Ray
  19. look into using mysql_insert_id(). Run your insert query, then use mysql_insert_id() to get the id then run an update query to set the id in the c_id field. Ray
  20. the problem is you named your table order. Order is a reserved word in mysql so you have to surround the table name with ticks. $sql = "INSERT INTO `order` (`user_id`, `item_id`) VALUES ('".$r['user_id']."', '".$r['item_id']."')"; Same thing goes for other error. Ray
  21. you can just select the rows and insert them in the loop <?php $userid = $_POST['userid']; $sql = "SELECT id, user_id, item_id FROM pre_order WHERE user_id = '$userid'"; $res = mysql_query($sql) or die(mysql_error()); $error = "0"; while($r = mysql_fetch_assoc($res)){ $insert = "INSERT INTO order_db (`user_id`, `item_id`) VALUES ('".$r['user_id']."', '".$r['item_id']."')"; $ires = mysql_query($ires); if(!$ires){ $error .= "Could not move row ".$r['id']." Error: ".mysql_error()."<br />"; } // track the id's of the new inserts $insert_ids[] = mysql_insert_id(); } if($error){ echo $error; // remove any rows that HAVE been inserted from the pre_order table $ids = implode("', '", $insert_ids); $remove = "DELETE FROM order_db WHERE id IN ('$ids')"; $dres = mysql_query($remove); if($dres){ echo "pre_order items have been removed from order_db"; } else { echo "Could not remove pre_order items from order_db Error: ".mysql_error(); } } else { $pre_del = "DELETE FROM pre_order WHERE user_id = '$userid'"; $pres = mysql_query($pre_del); if($pres){ echo "Pre_order table has been cleared for user $userid"; } else { echo "Could not remove pre_order items for user $userid Error: ".mysql_error(); } } ?> Hope I didn't forget anything. Just put this together quick Ray
  22. If you include files then you may want to make sure they are being included correctly. May need to use absolute paths for the includes. Ray
  23. Some code may help to see what you have.
  24. Well the die is telling you your not connected to the database. If your using sessions just check to see if the user is logged in, if they are then include the connection.
  25. The code i post works fine just change the number of columns you want.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.