Jump to content

Search the Community

Showing results for tags 'function'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

  1. hey guys, since i am so new to php and programming , i am having extreme difficulty creating a function from scratch. i understand functions if i am reading one or if watching a tutorial , but trying to create one based one what i need is proving to be a bit confusing for me. PURPOSE the purpose of the function is to grab an id from my user database , and convert that ID to an md5. i already have a while loop that is grabbing all the content from my database and then extracting it to the page. i then want to display the image id in a loops surrounded by <img> tags to show each individual persons image with the correct id from the DB. so the link would be looking like this if you were to inspect the element if you were to look in text editor it would be like <?php while ($row = mysql_fetch_assoc($content)) { extract($row); echo '<li>'; echo '<div class="profile_pic"><a href="profile.php?member=' .$member_title . '&memberid=' .$id .'"><img src="http://s3.amazonaws.com/fast-network/photos/c4ca4238a0b923820dcc509a6f75849b.jpg" width="101" height="150"></a></div>'; echo '<div class="member_about">'; echo '<div class="member_about_text">'; echo '<h1><a href="profile.php?member=' .$imdb_title . '&memberid=' .$id .'">' . $member_title . ' (2013)</a></h1>'; echo '<div class="c">Class: ' .$class_year . '</div>'; echo 'Courses:' . $_courses_taken . '<br>'; echo 'Views: <span>194526</span> (<span>176</span> votes)<br>'; echo 'Votes:' .$votes .' <br>'; echo '</div>'; echo '<div class="about_rete">'; echo '<div class="vote">'; echo '<div id="Mark">'; echo '<div id="Maro">Rating: $rating . ' </span></div>'; echo '</div>'; echo '</div>'; echo '</div>'; echo '</div>'; echo '</li>'; } ?> HERE IS WHERE I WANT TO ADD THE FUNCTION echo '<div class="profile_pic"><a href="profile.php?member=' .$member_title . '&memberid=' .$id .'"><img src="http://s3.amazonaws.com/fast-network/photos/c4ca4238a0b923820dcc509a6f75849b.jpg" width="101" height="150"></a></div>'; INSTEAD IT WOULD LOOK LIKE THIS echo '<div class="profile_pic"><a href="profile.php?member=' .$member_title . '&memberid=' .$id .'"><img src=" http://s3.amazonaws.com/fast-network/photos/display_member_image($id).jpg " width="101" height="150"></a></div>'; ultimately i would like some feedback as to how to best approach creating this function to what i need it to do .. i will be using this function anywhere i want the image to be shown.
  2. GD77

    range()

    Hello: Is their a way to format range single digits? ex: $ar1 = range (1,14); will return array(1,2,3...) I need to append 0 to single digits to have 01,02... Thanks.
  3. Hi, im still in the early learning stages, banging my head against walls looking for clues. Iv been reading the manual to no avail. im building a user log in system based on the phpAcadamy tutorial 'Register & Login'. They use mysql_connect in the tutorial, but I am using a PDO connection to mysql. 1) the function user_id_from_username should return the `user_id` entry for the posted $username. mine does not, im confused about how to simply return the entry, and i just need a little bit of guidance and explanation. 2) the login function works, BUT i need it to return $user_id if TRUE, so that i can set the session. here is my code: function user_id_from_username(PDO $db, $username) { $stmt = $db->prepare('SELECT `user_id` FROM `users` WHERE `username` = 1'); $stmt->bindParam(1, $username); $stmt->execute(); return ($stmt->fetchColumn()); } //??? I NEED THIS FUNCTION TO RETURN THE `user_id` ENTRY FOR $username function login(PDO $db, $username, $password) { $user_id = user_id_from_username($db, $username); $password = md5($password); $stmt = $db->prepare('SELECT COUNT(`user_id`) FROM `users` WHERE `username` = ? AND `password` = ?'); $stmt->bindParam(1, $username); $stmt->bindParam(2, $password); $stmt->execute(); return (bool) $stmt->fetchColumn(); } //??? I NEED THIS FUNCTION TO RETURN $user_id IF TRUE (to set session) //---------------------login.php----------------------- if (empty($_POST) === false) { $username = $_POST['username']; $password = $_POST['password']; if (empty($username) === true || empty($password) === true) { $errors[] = 'You need to enter a username and password.'; } else if (user_exists($db, $username) === false) { $errors[] = 'We can\'t find that username. Have you registered?'; } else if (user_active($db, $username) === false) { $errors[] = 'You haven\'t activated your account!'; } else { $login = login($db, $username, $password); if ($login === false) { $errors[] = 'That username/password combination is incorrect.'; } else { die($login); } } print_r($errors); } So, according to this login script, after a successful login (good username and password, and active account) it should output the $user_id integer: "die($login)". It prints the error array correctly, it logs in ok, except for this next step. Thanks in advance!
  4. Hey guys, So i have a small yet very simple question more so than an issue. I am trying to call a variable that is a field from a mysql database. i am using an extract() function so any field title just returns as a variable. i have a member page where i then list the member and want to have on the side of their name the year they are born. for ex. <h1> Name ( year ) </h1> So in my data field the year the person is born is given as a full string of text 1984-14-09 Y/dd/m. All i want is the year from this data and to remove the day/month. So i did some research , and i came up with the solution of using an explode(), creating an array, and then simple echoing the index of that data i want. Problem is that the array is then leaving the entire string as one index in the array, basically not doing what i wanted it to do, which was to split the string into parts, allowing me to then echo whatever part i wanted. my code: <h1><a href="#link"><? echo $member_name; ?> (<? $arr = explode(' ',trim($member_birth_date)); print_r($arr); ?>)</a></h1> end result: any suggestions as to how to get the result i am looking for ? would really appreciate any ideas or solutions thanks guys
  5. Good day, I've got a problem getting the value of the parameter on a function I've got this code to append on my div $(' .'+type).append(' <a href="#" id="'+type+'-'+desId+'" class="admin-managers"> <span class="admin-managers" id="'+name+'">'+name+'</span> <span id="'+desId+'" onclick="remove('+type+','+desId+')" class="remove" name="<?php echo $type; ?>"></span></a> '); that is how I append the data and it is working fine, But on the "remove(type,desId)" function on: function remove(type,id){ Alert(type); } the id is working fine, but on the type everytime I alert it it return "javascript:void(0)"> What is that happening,? ?
  6. Hey there guys ! so i have finally finished my register log-in page , and with that i have created a couple functions pages , as i am sure you can assume all the functions for logic will be called from these pages. now i have one called users , i.e for login , registration , check if active, etc.. and i have one for more general functions page called general , i.e for redirects, and input sanitation. anyway my register login page works flawless ( well i guess more 90 % done 90 % left to go ). and now when im on the index page or my main page essentially i now see a fatal error: now i see that it is telling me exactly where the error is , yet i dont understand as to why i am seeing this . im not quite sure as to how the function is being declared already , when the function is only being called once or twice on the register page. just to show you guys what im talking about my code: general.php ( FUNCTIONS ARE STORED) function email($to, $subject, $body){mail($to, $subject, $body, 'From: support@j.m.com'); } function email_to_activate($to, $subject, $body){ mail($to, $subject, $body, 'From: activate@j.m.com'); } function email_user_for_recovery($to, $subject, $body){ mail($to, $subject, $body, 'From: recovery@j.m.com'); } function logged_in_redirect(){ if (logged_in() === true ) header("Location: index.php"); } function protect_page() { // redirects if user is not logged in .. user gets no access page if (logged_in() === false ) { header('Location: no_permission.php'); exit(); } } function admin_access() { global $user_data; if (has_access($user_data['user_id'], 1) === false) { header('Location: index.php'); exit(); } } function page_redirect() { // if user not logged in redirect goes to index page if (logged_in() === false ) { header('Location: index.php'); exit(); } } function redirect(){ // redirects regardless of logged in or not header('Location: index.php'); exit(); } function array_sanitize(&$item){ $items = strip_tags(htmlentities(mysql_real_escape_string($item))); } function sanitize($data) { return strip_tags(htmlentities(mysql_real_escape_string($data))); } function output_errors($errors){ $output = array(); foreach($errors as $error){ $output[] = $error ; } return '<ul>' . implode($output) . '</ul>'; } and index.php // CORE FUNCTIONS - DATABASE CONNECT - SESSIONS & COOKIES include('include/init.php'); // HEADER INFO - META TAGS - LINKS - SCRIPTS include('include/header.php'); // LOG USER IN if (logged_in() === true){ include ('include/widgets/loggedin.php'); } else { include('include/widgets/login.php'); } // WEBSITE LOGO include('include/logo_head.php'); // NAVIGATION BAR include('include/navbar.php'); // MAIN PAGE include('include/topbanner.php'); include('include/topbanner2.php'); <----- Error shows up here and cuts off the rest of the page. include('include/mainbody.php'); // FOOTER include('include/footer.php'); as i mention in the code above, the page spits about half the output then cuts off and displays that error message. This confuses me a bit more actually. any suggestions as to why this is happening ? EDIT : to add init.php ( CORE FILE ) if(!isset($_SESSION)) { session_start(); } error_reporting(E_ALL| E_STRICT); ini_set('display_errors', 1); require ('core/database/dbconnect.php'); require ('core/functions/general.php'); require ('core/functions/users.php'); require 'core/queries/dbqueries.php'; $current_file = explode('/', $_SERVER['SCRIPT_NAME']); $current_file = end($current_file); if (logged_in() === true) { $session_user_id = $_SESSION['user_id']; $user_data = user_data($session_user_id, 'user_id', 'username', 'password', 'email', 'gender', 'country', 'month' ,'date' , 'year', 'pass_recover', 'type'); if (user_active($user_data['username']) === false){ session_destroy(); header('Location: index.php'); exit(); } if($current_file !== 'change_password.php' && $current_file !== 'logout.php' && $user_data['pass_recover'] == 1 ){ header('Location: change_password.php?force'); exit(); } } $errors = array();
  7. Hi all, I am trying to make sure that a user cannot move on unless they select a radiobutton, but unfortunately it's not working. I used same function with checkbox in my other page and it works perfect but i don't know why it is not working here Btw, this is not inside a form (as in other page I have used inside the form) PLEASE HELP echo "<td class='kooltd'><input type = 'radio' name = 'rFlight' value = '".$row['flight_id']."'></td>"; echo "<input type='submit' id='button1' name='booking' value='Make Booking for the Selected Flight' onclick='if(!this.form.rFlight.checked){alert('You must select a flight.');return false}'/></br>";
  8. Hello my beautiful freaks, i have an issue trying to create my forgot username code. i am trying to send my end user an email with their loggin info ( more specifically the username ) <? function recover($mode, $email) { $mode = sanitize($mode); $email = sanitize($email); $user_data = user_data(user_id_from_email($email),'username'); if ( $mode == 'username') { email_user_for_recovery($email, 'Your username info', " Hello, This email has been sent from http://j.justin7410.com/recover.php You have received this email because this email address" .$user_data['email'] . ", was used during the registration process of our website. There has been a request for your forgotten username, If you did not request this information plese disregard this email. You do not need to unsubscribe or take any further action. Your sign-in username is: " .$user_data['username'] . // <--- THIS VARIABLE IS NOT BEING INDEXED CORRECTLY "Thank you for using j.justin7410.com, we hope to make your experience as easy and seamless as can be. Cheers, - team j.motionempire.com "); in general the $user_data variable is not returning the values i need. i was wondering if you guys had any good way of debugging this issue ? the variables are passing fine in other instances, but when passed through it wont echo the things i need the email received is just sending everything but the data needed/ thanks guys
  9. Hey freaks, i have been working on a log in / register system for a couple days now, and i am in the process of finalizing my end users activation of a newly registered account. I was having no real issues until now, to where i am utterly confused as to why i am having such a core problem. So for the first part i had a user register, and wanted to make sure the user is not already entering an email that already exists in my Database. if (email_exists($_POST['register_email']) === true) { $errors[] = 'The email you provided is already in use. If you are having trouble remembering your user info click <a href="#">here</a>'; } the error goes to an errors array i have setup with all the errors that would display to the end user if any occur. the email_exists() is the following : function email_exists($email) { $username = sanitize($email); $query = (" SELECT COUNT(`user_id`) FROM `users` WHERE `email` = '$email' "); $results = mysql_query($query); if(mysql_error()) { echo 'MySQL Error: '. mysql_error() .'<br>'; echo 'Query: '.$query; } else if(!mysql_num_rows($results)) { //### row has not been returned } else { //### row has been returned } return (mysql_result($results, 0) == 1) ? true : false; } Now everything in the function calls correctly, and as you see in the error check, row will be returned. Yet, as you see in my IF statement in the error check above, nothing is being returned with the variable i am inputting ( yet the other IF statement all seem to work with the same variable $_POST) now this i figured was the problem to my MAIN and number one issue. Getting my user activation working. if(isset($_GET['success']) === true && empty($_GET['success']) === true){ ?> <h2> Thank you, your account has been activated</h2> <h3> You can now log in and access the site and join the disscussions in out forum !</h3> <? } else if (isset($_GET['email'], $_GET['email_code']) === true){ $email = trim($_GET['email']); $email_code = trim($_GET['email_code']); if (email_exists($email) === false ){ $errors[] = ' We have a problem, we couldn\'t find that email address !'; // THIS IS THE ERROR GIVEN TO USER } else if (activate($email, $email_code) === false) { $errors[] = ' We had a problem activating your account '; } if(empty($errors) === false){ ?> <h2>Oops...</h2> <? echo output_errors($errors); } else { header('Location: activate.php?success'); exit(); } } else { header('Location: index.php'); exit(); } Now above i have highlighted what conditional is passed, when a end user click on the return link to activate their account. as i mentioned above , i know its the email_exists function, since not only does that conditional fail . in database i can create multiple users with the same email. Please guys any help would be greatly appreciated. I am a PHP / Programming noob , but i am trying my best to debug and catch my issues. i just cant figure this one out on my own .
  10. Hey guys, I am currently trying to finalize my registration page, and i am have some issues with the header() function. i know there are certain rules like no html can be above the header. and what not but i am fairly new to this and can figure out why i am outputting an error. my code is : <?if (isset($_GET['success']) && empty($_GET['success'])) { echo '<h1> Thank you for your registration </h1>'; } else { if (empty($_POST) === false && empty($errors) === true ) { $register_data = array( 'email' => $_POST['register_email'], 'username' => $_POST['register_username'], 'password' => $_POST['password'], 'gender' => $_POST['gender'], 'month' => $_POST['month'], 'date' => $_POST['date'], 'year' => $_POST['year'], 'country' => $_POST['country'], ); user_register($register_data); header('Location: register.php?success'); exit(); } else if ( empty($errors) === false) { echo '<div class="register_errors">'; echo '<span style="color:red"><h3>'; echo output_errors($errors); echo '</h3></span>'; echo '</div>'; } } ?> All of the code works for me until i try to send send the message. The error i get is the following : it directs me to my header.php file <!DOCTYPE html> <div> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="author" content="#"> <meta name="keywords" content="#"> <meta name="description" content="#"> <meta name="robots" content="#"> <meta name="revisit-after" content="7 days"> <link href="css/style.css" rel="stylesheet" type="text/css"> <link href="css/normalize.css" rel="stylesheet" type="text/css"> <script type="text/javascript" src="jscript/sidebar.js"></script> <script type="text/javascript" src="jscript/mootools.js"></script> <body> <div class="top"> Any suggestions ? cant seem to figure this one out
  11. I have created a user defined function to return a string value function getModel($part) { $root = substr($part,0,4); $query = "SELECT Root, Model FROM tbl_Root WHERE Root = '$root'"; $result = mysql_query($query) or die ("Query Root failed: " . mysql_error()); while ($rec = mysql_fetch_array($result, MYSQL_ASSOC)) { if (in_array($root, $rec)): $Model = $rec['Model']; else: $Model = 'UNKNOWN'; endif; } return $Model; } When trying to find the attributes of several hundred part numbers, I pass them to a MySQL temp table that would then select the distinct part numbers and loop them through my functions. $query = "SELECT DISTINCT A FROM TempAttributes"; $result = mysql_query($query) or die ("Query failed: " . mysql_error()); while ($rec = mysql_fetch_array($result, MYSQL_ASSOC)) { $part = mysql_escape_string($rec['A']); $Model = getModel($part); $query = "REPLACE INTO tbl_Attributes (Part, Model) VALUES ('$part', '$Model')"; $endresult = mysql_query($query) or die ("Query Load failed: " . mysql_error()); } The line of code that stops the execution of my loop is $Model = getModel($part); I executed the loop with this line of code in and it stops after the first part number. When I comment this line of code out, my loop processes all of my part numbers, but of course not with the return values I am looking for. Why does my user defined function not process through the while loop to assign the $Model variable the return value of the getModel function? Please help!
  12. I am getting this error message, "Warning: implode() [function.implode]: Invalid arguments passed in/home/sam139/public_html/_import/functions.php on line 235" and I have no idea where I'm going wrong. The code where the issue is occurring is <p class="bline"><strong>Cast: </strong> <?= implode("<br/>", $p['cast']); ?></p> Where am I going wrong? Any help is much appreciated!
  13. I need to call a javascript or a php function from a form made in php, so that I could make change in data base on clicks. 1)I included the function on onclick event on submit but nothing happens. 2)The file name in which this code is include is view_users.php could someone hel me solve this <?php mysql_select_db("programmers") or die(mysql_error()); $data = mysql_query("SELECT * FROM user_allotment") or die(mysql_error()); while($info = mysql_fetch_array( $data )) { echo "<tr>"; echo "<td>".$info['id'] . "</td>"; echo "<td>".$info['uname'] . "</td> "; echo "<td>".$info['password'] . "</td>"; $id=$info['id']; echo "<form method="post" action="view_users.php">"; echo "<td><label><input type="button" name=/"$id/" value="edit" align="middle" onclick="edit()"/></label></td>"; echo "<td><label><input type="button" name=/"$id/" value="delete" align="middle" onclick="edit()"/></label></td>"; echo "<td><label><input type="checkbox" name=/"$id/" value="privilege" align="middle" onclick="edit()"/></label></td>"; echo "</form>"; echo "</tr>"; } ?>
  14. I have acquired a time clock script that I wanted to try and use, instead of the employees manually punching in and out, but going through it now, found that this function eregi() is old and I have tried to change it to preg_match. Here is the code: elseif (!eregi ("^([0-9]?[0-9])+[-|/|.]+([0-9]?[0-9])+[-|/|.]+(([0-9]{2})|([0-9]{4}))$", $from_date, $date_regs)) { $evil_post = '1'; if ($use_reports_password == "yes") { include '../admin/topmain.php'; } else { include 'topmain.php'; } echo "<table width=100% height=89% border=0 cellpadding=0 cellspacing=1>\n"; echo " <tr valign=top>\n"; echo " <td>\n"; echo " <table width=100% height=100% border=0 cellpadding=10 cellspacing=1>\n"; echo " <tr class=right_main_text>\n"; echo " <td valign=top>\n"; echo " <table align=center class=table_border width=60% border=0 cellpadding=0 cellspacing=3>\n"; echo " <tr>\n"; echo " <td class=table_rows width=20 align=center><img src='../images/icons/cancel.png' /></td><td class=table_rows_red> A valid From Date is required.</td></tr>\n"; echo " </table>\n"; } else { if ($calendar_style == "amer") { if (isset($date_regs)) {$from_month = $date_regs[1]; $from_day = $date_regs[2]; $from_year = $date_regs[3];} if ($from_month > 12 || $from_day > 31) { $evil_post = '1'; if ($use_reports_password == "yes") { include '../admin/topmain.php'; } else { include 'topmain.php'; } echo "<table width=100% height=89% border=0 cellpadding=0 cellspacing=1>\n"; echo " <tr valign=top>\n"; echo " <td>\n"; echo " <table width=100% height=100% border=0 cellpadding=10 cellspacing=1>\n"; echo " <tr class=right_main_text>\n"; echo " <td valign=top>\n"; echo " <table align=center class=table_border width=60% border=0 cellpadding=0 cellspacing=3>\n"; echo " <tr>\n"; echo " <td class=table_rows width=20 align=center><img src='../images/icons/cancel.png' /></td><td class=table_rows_red> A valid From Date is required.</td></tr>\n"; echo " </table>\n"; }} elseif ($calendar_style == "euro") { if (isset($date_regs)) {$from_month = $date_regs[2]; $from_day = $date_regs[1]; $from_year = $date_regs[3];} if ($from_month > 12 || $from_day > 31) { $evil_post = '1'; if ($use_reports_password == "yes") { include '../admin/topmain.php'; } else { include 'topmain.php'; } echo "<table width=100% height=89% border=0 cellpadding=0 cellspacing=1>\n"; echo " <tr valign=top>\n"; echo " <td>\n"; echo " <table width=100% height=100% border=0 cellpadding=10 cellspacing=1>\n"; echo " <tr class=right_main_text>\n"; echo " <td valign=top>\n"; echo " <table align=center class=table_border width=60% border=0 cellpadding=0 cellspacing=3>\n"; echo " <tr>\n"; echo " <td class=table_rows width=20 align=center><img src='../images/icons/cancel.png' /></td><td class=table_rows_red> A valid From Date is required.</td></tr>\n"; echo " </table>\n"; }}}} if (!isset($evil_post)) { if (empty($to_date)) { $evil_post = '1'; if ($use_reports_password == "yes") { include '../admin/topmain.php'; } else { include 'topmain.php'; } echo "<table width=100% height=89% border=0 cellpadding=0 cellspacing=1>\n"; echo " <tr valign=top>\n"; echo " <td>\n"; echo " <table width=100% height=100% border=0 cellpadding=10 cellspacing=1>\n"; echo " <tr class=right_main_text>\n"; echo " <td valign=top>\n"; echo " <table align=center class=table_border width=60% border=0 cellpadding=0 cellspacing=3>\n"; echo " <tr>\n"; echo " <td class=table_rows width=20 align=center><img src='../images/icons/cancel.png' /></td><td class=table_rows_red> A valid To Date is required.</td></tr>\n"; echo " </table>\n"; } elseif (!eregi ("^([0-9]?[0-9])+[-|/|.]+([0-9]?[0-9])+[-|/|.]+(([0-9]{2})|([0-9]{4}))$", $to_date, $date_regs)) { $evil_post = '1'; if ($use_reports_password == "yes") { include '../admin/topmain.php'; } else { include 'topmain.php'; } echo "<table width=100% height=89% border=0 cellpadding=0 cellspacing=1>\n"; echo " <tr valign=top>\n"; echo " <td>\n"; echo " <table width=100% height=100% border=0 cellpadding=10 cellspacing=1>\n"; echo " <tr class=right_main_text>\n"; echo " <td valign=top>\n"; echo " <table align=center class=table_border width=60% border=0 cellpadding=0 cellspacing=3>\n"; echo " <tr>\n"; echo " <td class=table_rows width=20 align=center><img src='../images/icons/cancel.png' /></td><td class=table_rows_red> A valid To Date is required.</td></tr>\n"; echo " </table>\n"; } else { if ($calendar_style == "amer") { if (isset($date_regs)) {$to_month = $date_regs[1]; $to_day = $date_regs[2]; $to_year = $date_regs[3];} if ($to_month > 12 || $to_day > 31) { $evil_post = '1'; if ($use_reports_password == "yes") { include '../admin/topmain.php'; } else { include 'topmain.php'; } echo "<table width=100% height=89% border=0 cellpadding=0 cellspacing=1>\n"; echo " <tr valign=top>\n"; echo " <td>\n"; echo " <table width=100% height=100% border=0 cellpadding=10 cellspacing=1>\n"; echo " <tr class=right_main_text>\n"; echo " <td valign=top>\n"; echo " <table align=center class=table_border width=60% border=0 cellpadding=0 cellspacing=3>\n"; echo " <tr>\n"; echo " <td class=table_rows width=20 align=center><img src='../images/icons/cancel.png' /></td><td class=table_rows_red> A valid To Date is required.</td></tr>\n"; echo " </table>\n"; }} elseif ($calendar_style == "euro") { if (isset($date_regs)) {$to_month = $date_regs[2]; $to_day = $date_regs[1]; $to_year = $date_regs[3];} if ($to_month > 12 || $to_day > 31) { $evil_post = '1'; if ($use_reports_password == "yes") { include '../admin/topmain.php'; } else { include 'topmain.php'; } echo "<table width=100% height=89% border=0 cellpadding=0 cellspacing=1>\n"; echo " <tr valign=top>\n"; echo " <td>\n"; echo " <table width=100% height=100% border=0 cellpadding=10 cellspacing=1>\n"; echo " <tr class=right_main_text>\n"; echo " <td valign=top>\n"; echo " <table align=center class=table_border width=60% border=0 cellpadding=0 cellspacing=3>\n"; echo " <tr>\n"; echo " <td class=table_rows width=20 align=center><img src='../images/icons/cancel.png' /></td><td class=table_rows_red> A valid To Date is required.</td></tr>\n"; echo " </table>\n"; }}}} if (isset($evil_post)) { echo " <br />\n"; echo " <form name='form' action='$self' method='post' onsubmit=\"return isFromOrToDate();\">\n"; echo " <table align=center class=table_border width=60% border=0 cellpadding=3 cellspacing=0>\n"; echo " <tr>\n"; echo " <th class=rightside_heading nowrap halign=left colspan=3><img src='../images/icons/report.png' /> Daily Time Report</th></tr>\n"; echo " <tr><td height=15></td></tr>\n"; echo " <input type='hidden' name='date_format' value='$js_datefmt'>\n"; When I change the two lines: !eregi ("^([0-9]?[0-9])+[-|/|.]+([0-9]?[0-9])+[-|/|.]+(([0-9]{2})|([0-9]{4}))$", $from_date, $date_regs) to this: !preg_match("^([0-9]?[0-9])+[-|/|.]+([0-9]?[0-9])+[-|/|.]+(([0-9]{2})|([0-9]{4}))$", $from_date, $date_regs) I get an error saying this: preg_match() [<a href='function.preg-match'>function.preg-match</a>]: No ending delimiter '^' I also get an error within it saying: A valid From Date is required. The calendar style is "amer", so you can ignore the "euro" part of the code, as I did not want to delete anything. Hopefully this is enough information.
  15. Hope this is the right topic for my problem and maybe someone can help me with this! My blog is in wordpress and when you look at the default category page it looks empty, just plain post list so i figured it would be nice to have last few category posts before the content. With the theme which I'm using silverOrchid i already have front page slider which i like so i would like to copy that slider in the category.php which i created earlier and change it to show and change latest posts per category which users are reading. Here is slider code from index.php //include slider if ( $gazpo_settings['gazpo_show_slider'] == 1 ) { get_template_part('includes/slider'); } So my question is how to change this code (if possible) to show latest posts from category which users are reading? I tried a few different forum threads but non of them seams understandable enough for me so i would appreciate help .... thanx
  16. insertion of data in database using function in php
  17. Hello I tried to move the bold section of the below code into a function getWeights() located in a m_weight.php file (I want to implement MVC pattern) <?php $get_weights_q = mysql_query (" SELECT * FROM users_weight WHERE weight_uid = '$user_id' ORDER BY weight_date DESC ", toctoc() ) or die(mysql_error() ); while ($weight = mysql_fetch_array($get_weights_q)) { ?> <li> <?php echo date( " d M-y H:i (l) " , $weight['weight_date']). ' : ' . $weight['weight'] . ' <a href="'.$_SERVER['SCRIPT_NAME'].'?del=' . $weight['weight_id'] . '">Changer</a> ' ; } ?> </li> </ul> ---------------- Here is the function: function getWeights($user_id) { $get_weights_q = mysql_query (" SELECT * FROM users_weight WHERE weight_uid = '$user_id' ORDER BY weight_date DESC ", toctoc() ) or die(mysql_error()); } The result is : Notice: Undefined variable: get_weights_q in H:\home\user\documents\DEV-H\EasyPHP-5.3.8.1\www\Food-Tribe\v_weight.php on line 44 Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in H:\home\user\documents\DEV-H\EasyPHP-5.3.8.1\www\Food-Tribe\v_weight.php on line 44 If I let the code just above the While, in procedural mode it works fine... Any idea?
  18. Hi, I'm using a preg_replace to change [menu] into Menu::makeMenu(); , but when it executes the replace, for some reason it's sending my code to the first line after the <body> tag rather than where the [menu] was in the first place. Preg Replace: function formatPage($transform){ $a = array( "/\[element=\"(.*?)\"\]/ise", "/\ /ise", "/\[menu]/ise", "/\[login-button]/ise", ); $b = array( "elementCreate(\"$1\");", "pageCreate();", "Menu::makeMenu();", "loginBtn();", ); $transform = preg_replace($a, $b, $transform); return $transform; } I can copy out the whole function and stuff for the Menu:: but I don't think it'll matter. Please help! Cheers.
  19. I have a problem when i Click the Edit button int he form, the database doesn't update, In the beginning i thought i had a problem with the query, but I did a check as a query and everything was fine. Can someone suggest something please. //this is the file - album.func.php function edit_album($album_id, $album_name, $album_description) { $album_id = ((int)$album_id); $album_name = mysql_real_escape_string($album_name); $album_description = mysql_real_escape_string($album_description); mysql_query("UPDATE `albums` SET `name`='$album_name', `description`='$album_description' WHERE `album_id`='$album_id' AND `user_id`=".$_SESSION["user_id"]); } //this is the file - edit_album.php if (!empty($errors)) { foreach ($errors as $error) echo $error; }else { edit_album($album_id, $album_name, $album_description); header('Location: index.php'); exit(); }} ?> <?php $album_id = $_GET["album_id"]; $album_data = album_data($album_id, 'name', 'description'); ?> //this is the form <form action="?album_id=<?php echo $album_id; ?>" method="post"> <p>Name:</br><input type="text" name="album_name" maxlength="55" value="<?php echo $album_data["name"]; ?>"/></p> <p>Description:</br><textarea name="album_description" rows="6" cols="35" maxlength="500"><?php echo $album_data["description"]; ?>
  20. Hi all, I'm experiencing a lot of trouble trying to create a script for my website. I'm making a database dependant menu, and I've spent a couple of days doing trial and error much to no prevail. I'm using Twitter Bootstrap if anyone is familiar with it, and creating a drop down menu. The code for each of these buttons is: <div class="btn-group"> <a class="btn btn-inverse dropdown-toggle" data-toggle="dropdown" href="#"> WOD <span class="caret"></span> </a> <ul class="dropdown-menu"> <!-- dropdown menu links --> <li><a tabindex="-1" href="http://www.google.com.au">View the WOD</a></li> <li><a tabindex="-1" href="#">WOD Archives</a></li> <li class="divider"></li> <li><a tabindex="-1" href="#">Benchmarks</a></li> </ul> </div> So, what I need to be able to do is call each menu that I have in the database, (I have 5), determine if it's a drop down, and if it is, echo the links for it inside of the <ul class="dropdown-menu"> It seems simple to me, but I cannot get it right. Please help! Cheers.
  21. All, I had someone request a function to be written. Here's what they said: can you take a list of ints and get back a list of indices that add up to a variable 'X'?? here's what they asked for (as an example)... Input: ([1,4,7,2], X=3) output: [[0,1]] I'm not quite sure I'm following it. Anyone shed some light on this for me? I'm just not getting what they want, probably because I don't have formal training in coding. Vocabs are always mismatched. thanks.
  22. Hi all, i am fairly new with php and i am running into a problem with a php function. It is very basic but i've got something wrong here. It is a function in wordpress that needs to analyze the post and extract the category. For every category another value needs to be returned. My code is: function postimage($post_id){ $category = get_the_category( $post_id ); $id = $category[0]->cat_ID; if ( $id = 45 ){ $link = 'This is category 45'; } else { $link = 'This is not category 45 '; } return $link; } There are 2 strange things happening: 1. The first statement is always true. Even if the category id is not 45 it still returns the first $link. 2. If i return the variable $id after the if statement it returns als 45. If i do it without the if statement it returns correct. The 2 problems are obviously related but i don't understand what i'm doing wrong. Please help
  23. Hello everyone, i have to say im a severe newbie. I know very little php, but im struggling to learn it. Im trying to complete a tutorial but somewhere somehow it doesnt work as intended. I have problems displaying the entries i have in my db table. They dont show up in Index.php. There are 4 short files, seperated with brackets ## http://pastebin.com/7wXGxyT4. Perhaps its the $fulldisp that doesnt play well. I would appreciate some help alot! Thank you.
  24. I have the following function, which I'm struggling to convert: /******************************************************/ function start() { global $dpath, $rb_head, $rb_foot, $siteurl; /******************************************************/ include("$dpath$rb_head"); $ip = getenv ("REMOTE_ADDR"); $urllink = getenv("HTTP_REFERER"); if (!ereg("$siteurl", "$urllink")) { $urllink2 = "$siteurl"; //echo "<br /><b>Page being Referred</b>: <a href=$urllink2>$urllink2</a>\n"; } else { $urllink2 = "$urllink"; //echo "<br /><b>Page being Referred</b>: <a href=$urllink2>$urllink2</a>\n"; } include("rb_form.php"); crkdo(); include("$dpath$rb_foot"); } Any help would be appreciated. Duncan
  25. Hi Guys, From what I can tell, there is no other similar inquiry around... I'm completing my Higher School Certificate (final year of high school in New South Wales Australia) and I'm creating a web system for a major. Part of it requires me to have fully dynamic pages for my clients purpose, and I'm using database elements - so basically there is a BB Code site editor that translates [element=menu] to <?php elementCreate("menu"); ?> What I'm finding for some reason I can't contemplate, is that it's just blatantly not working! And when I use view source the <?php elementCreate("menu"); ?> is green as if it's a comment? function bbElement($transform){ $a = array( "/\[element=\"(.*?)\"\]/is", ); $b = array( "<?php echo elementCreate($1); ?>", ); $transform = preg_replace($a, $b, $transform); return $transform; } function elementCreate($element){ $element_fetch = mysql_query("SELECT * FROM `elements` WHERE `element_name` = '".$element."'")or die(mysql_error()); while($element_info = mysql_fetch_array($element_fetch, MYSQL_ASSOC)){ $econt = $element_info['content']; } return $econt; } It's quiet likely I've missed something simple - but all help is appreciated! Cheers.
×
×
  • 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.