PHP - Simple Timedate Problem
Ok I got this column "date_reg" on my table which has a "datetime" type.
It's giving me a value like "2012-04-20 04:28:03" The problem is, when I'm trying to insert on that column using this format Code: [Select] <?php $datenow = date('m/d/Y h:i:s a', time()); ?> it's giving me a value of "0000-00-00 00:00:00" which is suppose to be the current date and time the user add on that table. Anyone knows how I can fix this? Similar TutorialsHi, Trying to figure out a way to get a time difference between two times assuming they are in order.. For example; in the array below the days is easy.. because the time happens later, however nights it becomes a little more confusing. The method I'm using now is; if the dates are in order just stick a reference date on there, and get a difference. If they seem to be reversed, I stick a reference date on the first one and a reference date +1 days on the second and get the difference.Can you all think of a better way? I will use the assumption that the times will NEVER be more than 24 hrs apart..
Array ( [2] => Array ( [days] => Array ( [0] => 07:00:00 [1] => 15:45:00 ) [nights] => Array ( [0] => 15:30:00 [1] => 02:15:00 ) )
This is my website: www.wearenip.com/home.html This is the menu that should appear on the left hand side, but doesn't: www.wearenip.com/menu.php This is my server's output saying that php is running just fine: http://wearenip.com/phpinfo.php I'm using this code in the left side bar div: Code: [Select] <?php include("menu.php"); ?> The PHP file will not display from the HTML file no matter what I do. I've tried using every possible combination of file linking including /menu.php ./menu.php and even the full http://www.wearenip.com/menu.php etc etc etc I'm genuinely upset about this. Any help would be greatly appreciated. PS: I can't get any PHP file to properly include in any HTML file on any computer I have. Nothing displays whatsoever regardless of what is in the PHP file, even if it's just a text word. Doesn't matter if it's hosted on a PHP compatible internet server or just on a local server or just on the local machine itself. Nothing. It shouldn't be that difficult I just don't know how to do it myself. I'm using the following code for a simple navigation, i has been placed in the content of my home page, it works fine however i don't know how to set the home page. <div id="content"> <?php $page = $_GET['page']; $file = $page.".php"; if(file_exists($file)) { include($file); } else { include "error.php"; } ?> </div> SOLVED, sorry. ... but i can't work it out. all i want to do is; if ( $this_item exists within the table ) { do a } else { do b } for example, $this_item = 'john', and i want the script to do (a) if he's in the table, or (b) if he isn't. thank you! so I have an xml string the following expression $xpath = $response->xpath('/atom:feed/atom:entry/atom:content'); returns the following array SimpleXMLElement Object ( [@attributes] => Array ( [type] => application/vnd.google-earth.kml+xml ) [Placemark] => SimpleXMLElement Object ( [name] => M1 [description] => SimpleXMLElement Object ( ) [Style] => SimpleXMLElement Object ( [IconStyle] => SimpleXMLElement Object ( [Icon] => SimpleXMLElement Object ( [href] => http://maps.gstatic.com/intl/en_ALL/mapfiles/ms/micons/blue-dot.png ) ) ) [Point] => SimpleXMLElement Object ( [coordinates] => -79.395018,43.645423,0.0 ) ) ) However what I'm trying to get are the coordinates, but neither $xpath = $response->xpath('/atom:feed/atom:entry/atom:content/Placemark'); OR $xpath = $response->xpath('/atom:feed/atom:entry/atom:content/Placemark/child::*'); work I even tried just loading atom:content into an array and going from there no luck. Any ideas. Oh. BTW this might help http://code.google.com/apis/maps/documentation/mapsdata/developers_guide_protocol.html#RetrievingFeatures Hi! I am not great at using php but do use it to process forms on websites. I always use the same script and just change the relevant sections for each website. This usually works with no problems. I am writing an mailing list subscribe/unsubscribe form my website and it works fine as in I get the email sent through with all the information on it and the automated reply gets sent out etc. The problem is that once the user hits Submit instead of going to the redirect page it stays on the php page. if($from == '') {print "You have not entered an email, please go back and try again";} else { if($name == '') {print "You have not entered a company name, please go back and try again";} else { $send = mail($to, $subject, $body, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2); if($send) {header( "Location: http://www.hillsideweb.co.uk/unsubthanks.html" );} Like I say this exact script works on another site of mine perfectly well, can someone please help me solve this. The form is found on http://www.hillsideweb.co.uk/unsubscribe.html I hope this makes sense! Many thanks Swenglish hello ! .. im a newi .. and i tried for a long time to fix this , its about comparison between the <form> information about the user and the actually information in the database ... LOGIN problem everytime he redirecty me to the main_page.php here is the proccesing code : <?php require_once("includes/connection.php");?> <?php require_once("includes/functions.php");?> <?php //to redirect u if u make an error ! global $errors; $errors=array(); $fields_array=array('user_name','user_password'); foreach($fields_array as $field){ if(!isset($_POST[$field]) || empty($_POST[$field])){ $errors[]=$field; }} if(!empty($errors)){ header("Location: errors.php"); exit; } ?> <?php $user_name=mysql_prep($_POST['user_name']); $user_password=mysql_prep($_POST['user_password']); ?> <?php $result=mysql_query("SELECT * FROM users",$connection); if(!$result){ die("Database query failed: " . mysql_error());} ?> <?php while($row=mysql_fetch_array($result)){ $user_ver=array($row['user_name'],$row['user_password']); if($user_ver[0]==$user_name AND $user_ver[1]==$user_password){ header("Location: login_suc.php"); exit; }} header("Location: main_page.php"); exit; ?> <?php mysql_close($connection); ?> Hi all I am grabbing the _SERVER['REQUEST_URI'] and trying to compare it but this doesnt work $currpage = $_SERVER['REQUEST_URI'];//when i echo this i get ' / ' $home = '/'; //but this doesnt work if(strpos($currpage, $home)){echo 'test works';} PS It will work if i use if($currpage == $home){echo 'test2';} Any ideas? Thanks, Magnetica Hi -- This query seems to be problematic because the UPDATE is not being performed. Could you please take a gander and let me know what is the problem? BTW, the table "teamy" does contain 630 records. Thanks in advance! $sql = "SELECT COUNT( * ) AS records FROM teamy" ; $result = mysql_query( $sql ) ; if ( ! $result ) { die ( __line__ . "_teamy_" . mysql_error() ) ; } $a_count = mysql_fetch_assoc($result); if ( $a_count['records'] = 0 ) { echo "No records found in teamy." ; } else { /*** Update r_rost_rma ***/ $sql = "UPDATE r_rost_rma JOIN teamy ON r_rost_rma.student_id = teamy.student_id SET r_rost_rma.teachername = teamy.team WHERE RTRIM( UPPER( r_rost_rma.localcourse ) ) = 'HOMEROOM'" ; $result = mysql_query ( $sql ) ; if ( ! $result ) { die ( __line__ . "_update_r_rost_rma_" . mysql_error() ) ; } } Hello, i am trying to create a simple funtion that i can all upon to "turn off a website" i am calling the function by <?php siteonline(n); ?> and the function is function siteonline($msg){ $offlinecheck = mysql_query("SELECT * FROM acp") or die(mysql_error()); $siteoffline = mysql_fetch_array($offlinecheck); $ifsiteoffline = $siteoffline['site_offline']; $offline = $siteoffline['offline_msg']; if ($ifsiteoffline == "y") { echo("$offline"); die();} } now this will turn off the site but it shows no message what so ever and i can not figure out why can anyone help? Cheers, Im simply having a problem with structuring a directory structure for mkdir Code: [Select] mkdir("saves/".$worldname."/".$playername, 0777); The middle "/" is causing issues, if I take it out I have no problem in creating a folder name saves/worldnameplayername/ just want to add playername as a sub-dir. I have tried every combination I can think of to get it to accept the divider Any help? I have a script.. it works fine on my localhost.. now i am trying to work it with on my remote server.. the script reads the folder in my c drive and shows me the file on display here is the code <?php $main_dir ="C:\\xampp\\htdocs\\xtrajam"; $main_open = opendir($main_dir); while(($main_file = readdir($main_open)) != FALSE) { echo $main_file."<br />"; } closedir($main_open); ?> Now the thing is this works fine on local host as it can easy access the path C:\\xampp\\htdocs\\xtrajam Now i want this path to be accessed sumhow wen i try it on my remote server.. how should i do that like when i run the script online it reads the contents from my c drive directory..? is it sumhow possible? Simple for you, but I am very new to just messing around with mysql functions.
I have 1 table that tracks both the item id and the amount of views the item has.
The id column is called gId, and the views column is called gplays.
All I am trying to do is get it to show a list of the latest 100 items, but sort them as most viewed.
I've looked at online tutorials to googling the function, but can't find anything that works.
Here's my current code:
$results = $db->cachegetall(300, "SELECT gId id, gName name, gDescription descr, gThumb thumb, gplays plays FROM games ORDER BY gId DESC LIMIT 100");that just shows the latest 100. When I try ORDER BY gId DESC, gplays DESC LIMIT 100");I get nothing different. If I do ORDER BY gplays DESC LIMIT 100");I get the 100 results, but they are from all items, and I want to only get it from the latest 100 items. Can someone help me? I really have no idea what these functions are doing, other than the very basic tutorials I've read on the order by function. I am thining this will be pretty simple for someone to help me with, I have been hassling with it for several hours and really feel dumb that I can't get it to work. Here is the problem - I have one script wherein I have a form that passes a variable using Post method. I have previously assigned a value "A" to a variable $rtn the input is: <input name="Rtn" type="hidden" value="<?php echo $rtn; ?> /> In the script that I am calling I first get the value of the variable: $rtn = (_POST['Rtn']); then there is other stuff goin on and I come to an if stmt: if ($rtn == "A" { do some stuff } else { echo $rtn; } It will never get into the do some stuff - it always falls through to the else the output is \'A\' I have tried to use double quotes, single quotes, used stripslasches and addslashes funtions, trim, and various combination of all of these. Nothing I do seem to get me into the first part of the if stmt, to do some stuff. So, I'm going through a tutorial in my PHP book and we're using the code below. The page shows up and connects to the database (no error reported), but no data comes up. I'm wondering if I'm just missing something small or what? Let me know if you can help <html> <head> <title>Search Results</title> </head> <body> <h1>Book-0-Rama Search Results</h1> <?php //create short variable names $searchType=$_POST['searchType']; $searchTerm=trim($_POST['searchTerm']); if(!$searchType || !$searchTerm){ echo 'You have not entered enough information to process the search'; exit; } if(!get_magic_quotes_gpc()){ $searchType = addslashes($searchType); $searchTerm = addslashes($searchTerm); } echo $searchType; echo $searchTerm; @ $db = new mysqli('localhost','root','root'); if(mysqli_connect_errno()){ echo 'Error: Could not connect to the database man...'; exit; } $query = "SELECT * FROM books WHERE ".$searchType." LIKE '%".searchTerm."%'"; $result = mysqli_query($query); $num_results = mysqli_num_rows($result); echo "<p>Number of books found: ".$num_results."</p>"; for ($i=0;$i<$num_results;$i++){ $row = mysqli_fetch_assoc($result); echo "<p><strong>".($i+1).". Title: "; echo htmlspecialchars(stripslashes($row['title'])); echo "</strong><br/>Author: "; echo stripslashes($row['author']); echo "<br/>ISBN: "; echo stripslashes($row['isbn']); echo "<br/>Price: "; echo stripslashes($row['price']); echo "</p>"; } $result->free(); $db->close(); ?> </body> </html> heres the code... <?php mysql_connect("localhost","peter","tizer") or die("Error: ".mysqlerror()); mysql_select_db("matquant"); //replace TestTable with the name of your table //also in a real app you would get the id dynamically $idtochange=$_POST['idtochange']; $sql="select * from `quantites` where id = $idtochange"; $query=mysql_query($sql); while ($row=mysql_fetch_array($query)){ $id = $row['id']; $material = $row['material']; $quantity = $row['quantity']; $unit = $row['unit']; //we will echo these into the proper fields } mysql_free_result($query); ?> <html> <head> <title>Edit material list</title> <link href="css/quant1.css" rel="stylesheet" type="text/css"> </head> <body> <div id="leftcol"> <form "method="post"> <p><br/> <input type="text"value="1" name="idtochange" > <p> <input type="submit"value="submit changes"/> </form> <form action="changequan.php"method="post"> <p>Material Id currently active<br/> <input type="text"value="<?php echo $id;?>" name="id" disabled/> </p> <p> Enter new material name: </p> <input type="text"value="<?php echo $material;?>" name="material"/> <br/> change quantity: <input type="text"value="<?php echo $quantity;?>" name="quantity"/> <br/> unit of mesurement for quantity<br/> <input type="text"value="<?php echo $unit;?>" name="unit"/> <br/> </p> <input type="submit"value="submit changes"/> </form> </div> <div id="rightcol"><?php // make connection mysql_connect ("localhost", "peter", "tizer") or die ('I cannot connect to the database becuase: ' . mysql_error()); mysql_select_db ("matquant"); // build query $query = mysql_query("SELECT * FROM `quantites` ORDER BY `id` ASC"); // display results while ($row = mysql_fetch_array($query)) { echo "<br /> ..... " .$row ['id']. " ....... " .$row ['material']. " ...... " .$row['quantity']. " ...... " .$row['unit']. "<br />";} echo mysql_error(); ?> <a href="index.html">Home </a> <p> <a href="quanform.php">Insert new material and quantity form</a></p></div> </body> </html> I'm struggling with php. Any help anyone can give would be appreciated. Hi all, Im coding a simple script for my website which just changes the users rank. Code: [Select] <?php session_start(); include "../includes/db_connect.php"; include "../includes/functions.php"; logincheck(); ini_set ('display_errors', 1); error_reporting (E_ALL); $username=$_SESSION['username']; $get = mysql_query ("SELECT * FROM users WHERE username = '$username'"); $fetch = mysql_fetch_object($get); if ($fetch->userlevel >= "2"){ $newrank = $_POST['newrank']; $user1 = $_POST['user']; if (strip_tags($_POST['update'])){ mysql_query("UPDATE users SET `rank` = '$newrank' WHERE username='$user1'") or die (mysql_error()); echo ("You have updated $user1's rank to $newrank !"); } } else{ echo ("Your userlevel isnt high enouth to be here!"); } ?> <html> <head> <title>Change Rank</title> <link rel="stylesheet" href="../includes/in.css" type="text/css"> <style type="text/css"> .infobg { font-family: Arial; font-weight:normal; font-size:12px; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; background: URL(textbg1.png); font-weight:300; } .button { font-size: 12px; background:url(button.png); vertical-align: middle; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; color: #FFFFCC; height:23px; font-weight:300; border-radius: 10px; padding-bottom:2px; } </style> </head> <body> <form action='' method='post' name='form1'> <table width='30%' cellpadding='0' align='center' cellspacing='0' border='1' bordercolor='#000000' bgcolor='#808080' style='border-collapse: collapse'> <tr> <td background='../header.jpg' colspan='2' align='center'>Change Rank</td> <tr> <td>Username:</td><td><input type='text' name='user'></td> </tr> <tr> <td>Rank:</td><td><input type='text' name='newrank'></td> </tr> <tr> <td> </td><td><input type="submit" name="update" value="Update Rank"></td> </tr> </form> </table> </body> </html> But there seems to be something wrong with that code, which I carnt see or work out. When I click Update submit button it does nothing, but can anyone see why it does nothing? Thanks. Sorry this page is not available or has been accessed in error An error occurred in script 'C:\xampp\htdocs\public_html\login\plugins\delete_product.php' on line 45: Undefined variable: id Date/Time: 8-24-2010 00:50:10 Array ( [GLOBALS] => Array *RECURSION* [_POST] => Array ( ) [_GET] => Array ( [id] => 2 ) <?php # Script 9.2 - delete_product.php // This page is for deleting a album. require_once ('../includes/config.inc.php'); // Check for a valid product ID, through GET or POST: if ( (isset($id)) && (is_numeric($id)) ) { // From editproducts.php $id = $_GET['id']; } elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) { // Form submission. $id = $_POST['id']; } else { echo '<p class="error">Sorry this page is not available or has been accessed in error</p>'; } echo $id; require_once(MYSQL); // Check if the form has been submitted: if (isset($_POST['submitted'])) { if ($_POST['sure'] == 'Yes') { // Delete the record. // Make the query: $q = "DELETE FROM products WHERE product_id='$id' LIMIT 1"; $r = @mysqli_query ($dbc, $q); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. // Print a message: echo '<p>The Product has been deleted.</p>'; } else { // If the query did not run OK. echo '<p class="error">The Product could not be deleted due to a system error.</p>'; // Public message. echo '<p>' . mysqli_error($dbc) . '<br />Query: ' . $q . '</p>'; // Debugging message. } // Make the query: $q = "DELETE FROM photos WHERE product_id='$id'"; $r = @mysqli_query ($dbc, $q); } else { // No confirmation of deletion. echo '<p>The Product has NOT been deleted.</p>'; } } else { // Show the form. // Retrieve the albums information: $q = "SELECT name FROM products WHERE product_id='$id' Limit 1"; $r = @mysqli_query ($dbc, $q); if (mysqli_num_rows($r) == 1) { // Valid user ID, show the form. // Get the user's information: $row = mysqli_fetch_array ($r, MYSQLI_NUM); $form = $_SERVER['PHP_SELF']; // Create the form: echo '<form action="' . $form . '" method="post"> <h1>Delete ' . $row[0] . '?</h1> <p>Are you sure you want to delete ' . $row[0] . '?<br /> <p><b>Warning if you delete this album all content inside of it will be losed!</b><br /> <input type="radio" name="sure" value="Yes" /> Yes <input type="radio" name="sure" value="No" checked="checked" /> No</p> <p><input type="submit" name="submit" value="Submit" /></p> <input type="hidden" name="submitted" value="TRUE" /> <input type="hidden" name="id" value="' . $id . '" /> </form>'; } } mysqli_close($dbc); ?> Can someone explain to me whats wrong with this? <?php session_start(); // store session data $_SESSION['views']=1; ?> <html> <body> <?php //retrieve session data echo "Pageviews=". $_SESSION['views']; ?> </body> </html> The output it gives me in the browser is this: Quote Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at D:\Program Files\xampp\xampp\htdocs\sessions.php:1) in D:\Program Files\xampp\xampp\htdocs\sessions.php on line 2 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at D:\Program Files\xampp\xampp\htdocs\sessions.php:1) in D:\Program Files\xampp\xampp\htdocs\sessions.php on line 2 Pageviews=1 Explanation? Hi, This is a image tooltip from database. but I have got the problem, Not Working! How can i fix it. <a href="index.php?MD=urundetay&resimid=<?php echo $row_uruns['resimid']; ?>"><img src="urun_resim/<?php echo $row_image['image']; ?>" width="150" border="0" /></a> |