PHP - Moved: Best Method For This?
This topic has been moved to MySQL Help.
http://www.phpfreaks.com/forums/index.php?topic=353752.0 Similar TutorialsThis topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=356745.0 This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=343970.0 This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=320508.0 This topic has been moved to Application Frameworks. http://www.phpfreaks.com/forums/index.php?topic=326397.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=321957.0
My script has 3 classes (that are relevant to this discussion): DB, User and Validate. They are all in independent files and loaded automatically, when required, by an autoloader.
The error messages I am getting a Any pointers as to what I am doing wrong, or what I should be doing, would be most welcome. The following query code works correctly, however, I'm trying to figure out which is best when working with themes, templates, content pages. My themes are my different versions of the main site designs. As of right now I have the following code plus the database structure. site_themes - id, theme_name, status_id (only one theme can have a value of 1(active) at any given time) site_templates - id, template_name, header_code, footer_code, status_id (any can have a value of 1(active) at any given time, Code: [Select] <?php require("kowmanager/config/database.php"); $site_variables_query = "SELECT * FROM site_variables WHERE id = '1'"; $site_variables_result = mysqli_query($dbc, $site_variables_query); $row = mysqli_fetch_array($site_variables_result, MYSQLI_ASSOC); $site_theme_query = "SELECT * FROM site_themes WHERE status_id = '1'"; $site_theme_result = mysqli_query($dbc, $site_theme_query); $row2 = mysqli_fetch_array($site_theme_result, MYSQLI_ASSOC); if ($row['site_is_down'] == 'Yes') { } else { echo "site is up"; } ?> Hi there, I want to allow the ability for DJ's to turn on and off radio requests. Now obviously I've encorporated a check box and submit button within a PHP login. But I was wanting to know if this can be done with PHP or is a database required as the option will need to be remembered for a period of time. I'd probably look to do it by making it display on a page 'requests enabled' if enabled and a blank page if disabled. therefore I could encorporate: <?php if(!empty($requests)) { //requests template } else { //radio requests disabled template } ?> What's the best method for this? Thanks I am trying to insert the current Date/Time into mysql database using the following code. I do not understand how $submitDate & $submitTime are to be set. Will this work as coded? Code: [Select] <?php class SubmitDateRecord { const DB_TABLE = 'timesheet'; const DB_FIELD_SUBMIT_TIME = 'submit_time'; private $submitDate; private $submitTime; public function setSubmitDate($submitDate) { $this->submitDate = $submitDate; } public function getSubmitDate() { return $this->submitDate; } public function setSubmitTime($submitTime) { $this->submitTime = $submitTime; } public function getSubmitTime() { return $this->submitTime; } public function addRecord() { $insertTable = "`".self::DB_TABLE."`"; $insertFields[] = "`".self::DB_FIELD_SUBMIT_TIME."`"; $insertValues[] = "'{$this->submitDate} {$this->submitTime}'"; $sqlBuilder = new SQLQBuilder(); $query = $sqlBuilder->simpleInsert($insertTable, $insertValues, $insertFields); $dbConnection = new DMLFunctions(); $result = $dbConnection->executeQuery($query); if ($result) { return true; } else { return false; } } private function _buildRecordObjects($result) { while ($row = mysql_fetch_array($result)) { $submitdateObj = new SubmitDateRecord(); $submitdateObj->setAttendanceId($row['attendance_id']); $submitdateObj->setEmployeeId($row['employee_id']); /* $row['submit_time'] comes in '0000-00-00 00:00:00' format. * We want date in '0000-00-00' format and time in '00:00' format. */ $tmpArr = explode(' ', $row['submit_time']); $submitdateObj->setSubmitDate($tmpArr[0]); $submitdateObj->setSubmitTime(substr($tmpArr[1], 0, 5)); // Omiting 'seconds' part is ok since it is always zero $submitdateObj->setStatus($row['status']); $submitdateArr[] = $submitdateObj; } return $submitdateArr; } } Hi, I have a problem and can't seem to figure out how to do it.. Basically i have these 2 tables: Quote People Pid Pname Pdateadded Pdeleted And.. Quote Quote: PeopleCon PCid Pid PCorder Pdateadded Pdeleted Now, currently i insert the data into a table "People".. like you guys have helped me with.. But what i need to do is, first check to see if the author already exists in the People table, if so then just INSERT into PeopleCon, ELSE INSERT into both People and PeopleCon... Also if there are 4 authors, and 2 exist in People, and 2 do not. What needs to happen is the first 2 are simply inserted into PeopleCon, but the last 2 are INSERTED into both People and PeopleCon. When the authors are inserted into PeopleCon, the PCorder row needs to increment by the number of authors byt order of author. So this is the logic: Multiple authors are entered in textboxes Fire the script Check to see if author already exists in "People" table IF it does exist, INSERT into PeopleCon table ELSE do the insert into the People AND PeopleCon table, first it will INSERT into the People, and GET the MAX (ID) and insert into the PeopleCon So i currently have this, but as 3 separate methods: class People { public function checkNameExists(){ $query = "SELECT * FROM People WHERE Pname = '". mysql_real_escape_string($_POST['author'])."'"; $result = mysql_query($query); if(mysql_num_rows($result) > 0): $row = mysql_fetch_array($result); return true; else: return false; endif; } public function insertAuthor(){ $callback = create_function('$author','return "(\'".mysql_real_escape_string($author)."\',NOW(),0)";'); $sql = sprintf( 'INSERT INTO People (Pname, Pdateadded, Pdeleted) VALUES %s' ,implode(',',array_map($callback,$_POST['author'])) ); $result = mysql_query($sql); return "Successfully added NEW author"; } public function insertAuthorCon(){ $sql = "INSERT INTO PeopleCon (Pid, PCorder, PCdateadded, PCdeleted) VALUES ( 'MAX ID WILL GO HERE', 'INCREMENT OF ORDER GOES HERE', now(), 0 )"; $result = mysql_query($sql); return "Successfully added existing author"; } But obviously i need to combine these together into one method to match what i am trying to achieve.. Can anyone point me in the right direction? Thanks again... here is what i am trying to do. i have a url in my browser like this: http://localhost/jmla/index.php?option=com_content&view=article&id=1295:sovereign-a-country-risk-workshop as usuall we get elements form the url using the $_GET method, but here when i try to get id from the above url. i can get 1295:sovereign-a-country-risk-workshop. whereas the id is only 1295 and the other part is alias which i want to get seperately. is there a way to do so? I know I'm posting this inside the PHP coding board but I'm curious on how most handle this situation. I have a page that uses php to retrieve data from my database and I want to have it place a | in between each of the returned data which it does but it still places one after the last returned row. I'm wondering if I should do this with jquery load and then have it place that character in between each of the data or if there's a way to do it with php or what? Any ideas? Code: [Select] <?php require ("../header.php"); ?> <div id="titlehistory" class="content"> <h1 class="pageheading">Title History</h1> <?php $titlesQuery =" SELECT titles.titleName, titles.shortName FROM titles WHERE titles.statusID = 1 ORDER BY titles.ID"; $titlesResult = mysqli_query($dbc,$titlesQuery); ?> <p><span class="minilinks"> <?php while ( $row = mysqli_fetch_array ( $titlesResult, MYSQLI_ASSOC ) ) { $fieldarray=array('titleName','shortName'); foreach ($fieldarray as $fieldlabel) { ${$fieldlabel} = $row[$fieldlabel]; } echo '<a href="/titlehistory/'.$shortName.'">'.$titleName.'</a> |'; } ?> </span></p> <p class="nohistory">Please select a title to view.</p> </div> <?php require ("../footer.php"); ?> Hi There, I am trying to implement a facebook plugin into my website. When the user posts a link to my site on their wall it will redirect them back to my page with some GET info in the URL eg. www.example.com/download.php?post_id=43221. I don't need to know the Post Id number, I just need to know if they went to the facebook page. So my question is, how would I make it s that if there is a Post ID number it displays the page and if not it directs them to another page? Please help me with this, i'm totally stumped. Thanks George Bates Hi all, What is the maximum size of data that we can pass through GET Method? And can we increase its size ? I have a restricted page for members of a website. This restricted area is within a directory called 'download.' There is a login form on two pages (home and support pages, found in the main menu). These pages are on the site root directory. When the user successfully logs in they are taken inside the download directory to index.php. This index.php has a different look to the site root design. I have since redesigned this page to have the same structure as the site root pages. I would love for the user to able to navigate around the main site if they wanted, and when they clicked support in the menu they would have all the download files there on the page, instead of a login form. My question is how would I implement this login so that when the user logs in the support page changes from the login page to the page with the files. I don't want to to duplicate the site within the download directory, I was hoping for an efficient method, but I am unsure how to go about it. I found class on the net, and i am having a bit of a problem to understand how does update method works. Here is the code: Code: [Select] public function update() { global $database; // Don't forget your SQL syntax and good habits: // - UPDATE table SET key='value', key='value' WHERE condition // - single-quotes around all values // - escape all values to prevent SQL injection $attributes = $this->sanitized_attributes(); $attribute_pairs = array(); foreach($attributes as $key => $value) { $attribute_pairs[] = "{$key}='{$value}'"; } $sql = "UPDATE ".self::$table_name." SET "; $sql .= join(", ", $attribute_pairs); $sql .= " WHERE id=". $database->escape_value($this->id); $database->query($sql); return ($database->affected_rows() == 1) ? true : false; } I have form like this to deal with update: Code: [Select] <form action="index.php?page=languages" enctype="multipart/form-data" method="POST"> <?php foreach($language as $lang){ ?> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size; ?>" /> <label>Jezik</label><input type="text" size="50" name="language" value="<?php echo $lang->lang; ?>" /><br> <input type="hidden" name="id_lang" value="<?php echo $lang->id_lang; ?>" /> <label>Slika</label><input type="file" name="image"><?php echo "<img src=\"../images/"; echo $lang->image; echo "\">"; ?> <br> <label>Pozicija</label><input type="text" name="pozicija" value="<?php echo $lang->pozicija; ?>" size="2" /></p> <br> <input type="submit" name="submit_update" value="Unesi"> <?php } ?> </form> and code to start the function: Code: [Select] if(isset($_POST['submit_update'])) { $language = new Jezik(); $language->update(); } What next??? I have foreach method. This displays the choices that are selected and the value inside them as 1. The method is shown below. I am printing these with the name(choice1, choice2, choice3, choic4) and the value. If there is a value then it prints 1. Now my problem is I want to INSERT them into my database. if it prints choice1, choice2 then value 1 must be entered into choice1 and choice2 inside the database. I am not sure how to do this. can someone help me. Code: [Select] foreach ($_POST["choice"] as $question => $answer) { if($answer == NULL) { $val=0; } else{ $val = 1; } echo "choice id: $question. value: $val <br />"; Hi, I'm want to be able to change small site contents by using links like: site.com/?radio1, site.com/?radio2, but i want an easier way of making small bits of text change, for example, at the moment, i'm using: Autofresh is: <?php $link ='hits.php?on'; if (isset($_GET['on'])) echo "Enabled |<a href=\"?off\"> Disable?</a>" ?> <?php $link ='hits.php?on'; if (isset($_GET['off'])) echo "Disabled |<a href=\"?on\"> Enable?</a>" ?> Is it possible to do that with only one <?php $link ='hits.php?on'; if (isset($_GET['off'])) echo "Disabled |<a href=\"?on\"> Enable?</a>" ?> So i can have multiple echo's and assign which echo i want to use, for example: <?php $link ='hits.php?on'; if (isset($_GET['off'])) echo1 "Disabled |<a href=\"?on\"> Enable?</a>" echo2 "Enabled |<a href=\"?off\"> Disable?</a>" ?> <?php include echo2 ?> i know that wont work, but since im new to php, i need to explain what i mean. THANKS James Hi I am having this error while running my php script using ajax. Everything seems to be fine but I do not know why it is giving this error. Code: [Select] <br /> <b>Notice</b>: Undefined index: amount in <b>C:\wamp\www\...\add_bid.php</b> on line <b>3</b><br /> {"error":"yes","fieldErrors":null} Here is my code here is .php code which contains the form Code: [Select] <?php session_start(); $auctionid = $_POST['auction_id']; include "design/header.php"; include "DB/db.php"; ?> <div class="contents" id="bid_contents"> <?php $q = "SELECT * FROM bids WHERE productid='$auctionid' ORDER BY bidid DESC LIMIT 0,1"; $query = mysql_query($q) or mysql_error(); //echo $q; $row = mysql_fetch_assoc($query) or mysql_error(); $current_bid = $row['current_bid']; $thumbnail = mysql_query("SELECT * FROM products WHERE productid='$auctionid'"); $row_thumb = mysql_fetch_assoc($thumbnail); $thumb = $row_thumb['thumbnail']; $title = $row_thumb['product_title']; ?> <div id="thumb"> <img src='<?php echo $thumb ?>' border='none' /><br /> <?php echo $title."<br />"; echo "<b>Current Bid:</b> Eur ".$current_bid; ?> <form name="bid_form" id="bid_form"> <input type="text" name="amount" size="5" /> <input type="button" name="place_bid_btn" id="bid_btn" value="Place Bid" /> <div id="message"></div> </form> </div><!-- thumb --> </div> <?php include "design/footer.php" ?> here is .js file for ajax Code: [Select] $(function() { $('#bid_btn').click(function() { var url = 'add_bid.php'; var query = $('#bid_form').serialize(); alert(query); $.ajax({ type: 'POST', url: url, query: query, dataType: 'json', success: function(data) { if(data.error == 'no') { $('#message').css('display','none'); } else { $('#message').html(data.fieldErrors).css('display','block'); } } }); }); }); and here is where i get data from previous .php file and the problem seems to be in this page. I guess. Name of this page is add_bid.php Code: [Select] <?php session_start(); $bid = $_POST['amount']; $error = 'yes'; $msg = $bid; $JSON_array = array('error' => $error, 'fieldErrors' => $msg); $JSON_response = json_encode($JSON_array); header('Content-type: application/json'); echo $JSON_response; ?> I am adding jquery library and javascript file in my header.php file so it is fine. Please help |