PHP - Crazy Php Problem! - Explination With Lots Of Pics
I am having a problem I have encounted like no other. I am running a MySQL query from PHP and for some bizarre reason, its just not working... Ok, that sounds really general. lol
To start off, here is my database: http://i56.tinypic.com/2hh0up1.png I am writing my own user interface with HTML/PHP/MySQL for every day catalog management: http://i54.tinypic.com/axxsb7.png To catalog a product is done from here (this page works): http://i51.tinypic.com/2e0qs7s.png ETC ... <FORM action="result.html" enctype="multipart/form-data" method="post"> ... ETC ETC ... Name: <INPUT name="name" type="text"> <BR> Brand: <INPUT name="brand" type="text"> <BR> Country of origin: <INPUT name="country" type="text"> <BR> Material: <INPUT name="material" type="text"> <BR> Primary colour: <INPUT name="primarycolour" type="text"> ... ETC result.html: ETC ... $query = "INSERT INTO products(name, brand, country, material, primarycolour) VALUES('".$_POST['name']."', '".$_POST['brand']."', '".$_POST['country']."', '".$_POST['material']."', '".$_POST['primarycolour']."')"; ... ETC To alter a product, you enter in a product ID: http://i56.tinypic.com/2lcsqch.png Code: [Select] <FORM action="dataentry.html" method="post"> <DIV class="drop">Alter product ID: <INPUT name="id" type="text">    <INPUT type="submit" value="Submit"></DIV> The data entry page pulls all the values from the MySQL database and populates them into the INPUT fields, so the user does not have to write them all again: http://i56.tinypic.com/2zh0hgn.png ... ETC echo '<FORM action="result.html" enctype="multipart/form-data" method="post">'; ETC ... ... ETC echo 'Name:'; $query = "select name from products where id=".$_POST['id'].""; $result = mysql_query($query); $row = mysql_fetch_array($result); echo ' <INPUT name="name" type="text" value="'.$row['name'].'">'; echo $query; ETC ... I will now change the value of "Name" from 'a' to 'c' and submit the changes: http://i55.tinypic.com/dzi9hc.png http://i54.tinypic.com/ab5lyg.png Now, you would think the result has been inserted into my database yeah? It failed... but when I enter the same command directly into MySQL. Success! http://i51.tinypic.com/29z5y5x.png Why the F is this happening?! Similar TutorialsI'm trying to get a remote html page but I'm having a really weird problem. I'm using curl for that and I'm getting the page url from an rss item using simpelpie. Code: [Select] $url = $item->get_permalink();//simplepie function echo "<p>Getting $url. </p>"; $options = array( CURLOPT_RETURNTRANSFER => true, // return web page CURLOPT_HEADER => false, // don't return headers CURLOPT_ENCODING => "", // handle all encodings CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect CURLOPT_TIMEOUT => 120, // timeout on response CURLOPT_MAXREDIRS => 10, // stop after 10 redirects ); $ch = curl_init( $url ); curl_setopt_array( $ch, $options ); $content = curl_exec( $ch ); $err = curl_errno( $ch ); $errmsg = curl_error( $ch ); $header = curl_getinfo( $ch ); curl_close( $ch ); $header['errno'] = $err; $header['errmsg'] = $errmsg; $header['content'] = $content; if($err != 0) echo " $err : $errmsg</p>"; echo $header['content']; My problem is that although the page is loading fine ( no curl errors ) , some tags are missing (and particularly the tags that containing the article content of that page). When I'm hardcoding the url then everything is fine. I tried to print the url that simpepie gets from rss and it's identical with the one that I'm harcoding. So, Code: [Select] $url = $item->get_permalink(); not working Code: [Select] $url = "http://www.the_same_url.com" working. Any help whould be really appreciated. Thanks in advance. Okay here's the simple thing I'm trying to do. I have a time in a db on my server .. let's say its March 1st 2011 at 12:00AM. This time is dynamically set by the server, so it's on server time. Now, lets say today is Feb 28th 2011 at 12:00AM on the server. I'm trying to write a dynamic script that will count down that time .. in this case I would want to show 23:59:59. Every count down script i've found online gives me an option to use local time (browser) or server time. Each time i plug in server time it is always set to my browse time ... I echo everything out and I basically get this: Server time: Feb 28th 2011 at 12:00AM My browser time: Feb 28th 2011 at 2:00AM Script time remaining: 21:59:59 So why does this keep happening? When I echo the date() from the server it's always 2 hours ahead of my time but the script never adjusts. Any ideas or does anyone know of a good working script? I'm on eastern time and the server is on pacific. Here's my last try, you'll see I place the php date into this towards the bottom but I've also tried jquery and SSI methods too. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <script language="JavaScript"> TargetDate = "2/1/2011 12:00 AM"; BackColor = "palegreen"; ForeColor = "navy"; CountActive = true; CountStepper = -1; LeadingZero = true; DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds."; FinishMessage = "It is finally here!"; </script> <script language="JavaScript" src="http://scripts.hashemian.com/js/countdown.js"> */ function calcage(secs, num1, num2) { s = ((Math.floor(secs/num1))%num2).toString(); if (LeadingZero && s.length < 2) s = "0" + s; return "<b>" + s + "</b>"; } function CountBack(secs) { if (secs < 0) { document.getElementById("cntdwn").innerHTML = FinishMessage; return; } DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000)); DisplayStr = DisplayStr.replace(/%%H%%/g, calcage(secs,3600,24)); DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs,60,60)); DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs,1,60)); document.getElementById("cntdwn").innerHTML = DisplayStr; if (CountActive) setTimeout("CountBack(" + (secs+CountStepper) + ")", SetTimeOutPeriod); } function putspan(backcolor, forecolor) { document.write("<span id='cntdwn' style='background-color:" + backcolor + "; color:" + forecolor + "'></span>"); } if (typeof(BackColor)=="undefined") BackColor = "white"; if (typeof(ForeColor)=="undefined") ForeColor= "black"; if (typeof(TargetDate)=="undefined") TargetDate = "12/31/2020 5:00 AM"; if (typeof(DisplayFormat)=="undefined") DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds."; if (typeof(CountActive)=="undefined") CountActive = true; if (typeof(FinishMessage)=="undefined") FinishMessage = ""; if (typeof(CountStepper)!="number") CountStepper = -1; if (typeof(LeadingZero)=="undefined") LeadingZero = true; CountStepper = Math.ceil(CountStepper); if (CountStepper == 0) CountActive = false; var SetTimeOutPeriod = (Math.abs(CountStepper)-1)*1000 + 990; putspan(BackColor, ForeColor); var dthen = new Date(TargetDate); var dnow = new Date("<!--config timefmt='%c' --><!--echo var='DATE_LOCAL' -->"); if(CountStepper>0) ddiff = new Date(dnow-dthen); else ddiff = new Date(dthen-dnow); gsecs = Math.floor(ddiff.valueOf()/1000); CountBack(gsecs); </script> <br /> <?php $now = new DateTime(); echo $now->format("M j, Y H:i:s O")."\n"; ?> </body> </html> Hey guys! im currently learning javascript, PHP and SQL. I have a pretty solid understanding of HTML and CSS. I want to make a site similar to facebook (a good facebook). this is going to be a big project and i plan on moving to a bigger server system in a year or so to keep up with demands.
Heres how the site will function:
1. Basic registration/splash page. I understand that the finished form is sent to a php file on the server side, correct? (ill change my server name files of course)
2. after the registration page, while the user is logged in with their new account, there are 3 pages after that that explain what the website is all about and how to use it. the last page allows the user to setup their profile information, ask friends to join, and asks what type of things they like. After the last page, it sends the user to their main control panel, where social media feed can be seen, friends and online chats, news, advertisements, links, pages and groups (think facebook and linkedin)
3. the user will have the ability to look at their profile (not the control panel), and of course switch back to their control panel. social media, friends, groups and ads will also be on their individual profile page as well.
4. i want the site to have two views: a standard view and an enhanced view. the enhanced view will reposition divs and all that stuff so they can see a background image (either stock or one they uploaded) this image will eventually change to an animated image of a 3d environment.
5. the site is going to be heavily social media based. This means social media feeds, image uploading, a structured comment system, a friend system, search functions and targeted advertising.
This is obviously a lot to ask, but since their is so much to learn related to PHP and SQL, can someone point me to the right tutorials on how to get these things done? I am currently learning javascript, PHP and SQL on lynda.com. Expect me to be on this forum a lot and asking a lot of questions. Thanks for any help.
Edited by PHPlearner32, 10 January 2015 - 11:19 PM. First, I gotta say I am new to JavaScript, but not new to languages like PHP/C++.
I am working on a large huge JS file that has a lot of things and I have a feeling that it can be made better. How is where I am at a loss. If it was PHP, I'd split that JS file into probably 20 other smaller JS files, aka "classes", and it may or may not be the right thing to do, but let me focus on one particular aspect for now, and maybe deal with others later.
Here is the piece of code that bugs the me most (truncated for clarity):
if (selection[index].selected) { result += '<TABLE class="list_grey" style="float: left; margin-left: 20px;">'; result += '<TR>'; result += '<TH colspan="2">Data</TH>'; result += '</TR>'; var flag = "All"; if (selection[index].flag == 'P') flag = "Premium"; result += '<TR>'; result += '<TD>Flag</TD>'; result += '<TD>' + flag + '</TD>'; result += '</TR>'; result += '</TABLE>'; } else { result += '<TABLE class="list_grey" style="float: left; margin-left: 20px;">'; result += '<TR>'; result += '<TH colspan="2">Frame</TH>'; result += '</TR>'; result += '<TR>'; result += '<TD>Frame</TD>'; result += '<TD>' + selection[index].frame + '</TD>'; result += '</TR>'; result += '</TABLE>'; }So what it does is this: 1. it gets "selection" var with eval() from a DIV block of HTML page, where that DIV has a looooong prepared-by-PHP JSON string with all the options prepopulated from various sources accessible to PHP. var selection = eval("(" + document.getElementById("result").innerHTML + ")");2. It then dynamically constructs and populates further HTML using logic and data found in "selection" var. 3. This particular JS implements a selection algorithm, where basically user clicking buttons can navigate "selection" var forwards and backwards, and as user does, the dynamic portion of HTML updates per behavior defined in the JS file. My Problem / Question: I have a feeling that putting HTML the way it is done here in JS file is not proper separation of concerns and not good way to code. HTML should be. .. in HTML, when possible, but being new to JS I don't know if there is a better way. Is there a more recommended way to code what I have now ? I am trying to get more than one row from a database at once, then explode each value into a seperate variable. is there a way of doing this? hi, I am building a web app and need all my php on one page and links posting to same page etc, at the moment, I am linking to my townpubs.php page see code below: townpubs.php Code: [Select] <!doctype html> <?php include "../config.php"; $loggedIn = (isset($_COOKIE['loggedin']) && $_COOKIE['loggedin'] == 'true')?true:false; $town = $_REQUEST['RSTOWN']; $towns = mysql_query("SELECT * FROM pubs WHERE RSTOWN = '".$town."' ORDER BY RSTOWN ASC"); ?> <html> <head> <meta charset="UTF-8" /> <title>My Pub Space v1.0 β</title> <style type="text/css" media="screen">@import "jqtouch/jqtouch.min.css";</style> <style type="text/css" media="screen">@import "themes/jqt/theme.min.css";</style> <script src="jqtouch/jquery.1.3.2.min.js" type="text/javascript" charset="utf-8"></script> <script src="jqtouch/jqtouch.min.js" type="application/x-javascript" charset="utf-8"></script> <script type="text/javascript" charset="utf-8"> var jQT = new $.jQTouch({ icon: 'jqtouch.png', addGlossToIcon: false, startupScreen: 'jqt_startup.png', statusBar: 'black', preloadImages: [ 'themes/jqt/img/back_button.png', 'themes/jqt/img/back_button_clicked.png', 'themes/jqt/img/button_clicked.png', 'themes/jqt/img/grayButton.png', 'themes/jqt/img/whiteButton.png', 'themes/jqt/img/loading.gif' ] }); </script> </head> <body> <!-- TOWNS --> <div id="towns" class="current"> <div class="toolbar"> <h1>View Pubs</h1> <a class="back" href="index.php" rel="external">Home</a> </div> <h2>Pubs in <?php echo $town ?></h2> <ul class="plastic"> <?php while($row1 = mysql_fetch_array($towns)) { echo '<li class="arrow"><a href="pubinfo.php?PUBID='.$row1['PUBID'].'" rel="external">'.$row1['rsPubName'].'</a></li>'; } ?> </ul> </div> </body> </html> I would like to have this on my index.php page: index.php Code: [Select] <!doctype html> <?php include "../config.php"; $loggedIn = (isset($_COOKIE['loggedin']) && $_COOKIE['loggedin'] == 'true')?true:false; $query1 = "SELECT DISTINCT rsTown FROM pubs ORDER BY rsTown asc"; $result = mysql_query($query1); $towns = mysql_query("SELECT DISTINCT RSTOWN, COUNT(PUBID) As PubCount FROM pubs GROUP BY RSTOWN ORDER BY RSTOWN ASC"); $counties = mysql_query("SELECT DISTINCT RSCOUNTY, COUNT(PUBID) As PubCount1 FROM pubs GROUP BY RSCOUNTY ORDER BY RSCOUNTY ASC"); if ($loggedin == 'true'){ $locals = mysql_query("SELECT * FROM pubs INNER JOIN favepub_copy ON pubs.PUBID=favepub_copy.PUBID WHERE USERID='".$_SESSION['USERID']."' ORDER BY rsPubName asc"); } ?> <html> <head> <meta charset="UTF-8" /> <title>My Pub Space v1.0 β</title> <style type="text/css" media="screen">@import "jqtouch/jqtouch.min.css";</style> <style type="text/css" media="screen">@import "themes/jqt/theme.min.css";</style> <script src="jqtouch/jquery.1.3.2.min.js" type="text/javascript" charset="utf-8"></script> <script src="jqtouch/jqtouch.min.js" type="application/x-javascript" charset="utf-8"></script> <script type="text/javascript" charset="utf-8"> var jQT = new $.jQTouch({ icon: 'jqtouch.png', addGlossToIcon: false, startupScreen: 'jqt_startup.png', statusBar: 'black', preloadImages: [ 'themes/jqt/img/back_button.png', 'themes/jqt/img/back_button_clicked.png', 'themes/jqt/img/button_clicked.png', 'themes/jqt/img/grayButton.png', 'themes/jqt/img/whiteButton.png', 'themes/jqt/img/loading.gif' ] }); </script> </head> <body> <div id="about" class="selectable"> <p><img src="jqtouch.png" /></p> <p><strong>My Pub Space</strong><br />Version 1.0 beta<br /> <a href="http://www.jbiddulph.com" target="_blank">By John Biddulph</a></p> <p><em>Mobile Web Development</em></p> <p><a href="mailto:john.mbiddulph@gmail.com" target="_blank">E-mail</a></p> <p><a href="http://twitter.com/#!/jmbiddulph" target="_blank">@jmbiddulph on Twitter</a></p> <p><br /><br /><a href="#" class="grayButton goback">Close</a></p> </div> <div id="home" class="current"> <?php if (!$loggedIn){ ?> <div class="toolbar"> <h1>My Pub Space</h1> <a href="#about" id="infoButton" class="button slideup">About</a> </div> <ul class="rounded"> <li class="forward"><a href="#signup">Register an account</a></li> <li class="forward"><a href="#login">Login</a></li> <li class="forward"><a href="#towns">View pubs by town</a></li> <li class="forward"><a href="#counties">View pubs by county</a></li> </ul> <div class="info"> <p>All Rights Reserved © 2011 mypubspace.com Created by: jbiddulph.com</p> </div> <?php } else { ?> <div class="toolbar"> <h1>Hi <?php echo $_SESSION['s_username'];?></h1> <a href="dologoff.php" rel="external" class="button">Logout</a> </div> <ul class="rounded"> <li class="forward"><a href="#locals">View Locals</a></li> <li class="forward"><a href="#towns">View Towns</a></li> <li class="forward"><a href="#counties">View Counties</a></li> </ul> <div class="info"> <p>All Rights Reserved © 2011 mypubspace.com Created by: jbiddulph.com</p> </div> <?php } ?> </div> <!-- LOCALS --> <div id="locals"> <div class="toolbar"> <h1>My Locals</h1> <a class="back" href="#home">Back</a> </div> <ul class="plastic"> <?php while($row1 = mysql_fetch_array($locals)) { echo '<li class="arrow"><a href="pubinfo.php?PUBID='.$row1['PUBID'].'" rel="external">'.$row1['rsPubName'].', '.$row1['rsTown'].'</a></li>'; } ?> </ul> </div> <!-- TOWNS --> <div id="towns"> <div class="toolbar"> <h1>View Towns</h1> <a class="back" href="#home">Back</a> </div> <ul class="edgetoedge"> <?php $ltr = ''; while($row1 = mysql_fetch_array($towns)) { $letter1 = substr($row1['RSTOWN'],0,1); if ($letter1 != $ltr) { print'<li class="sep">'. $letter1 .'</li>'; } $ltr = $letter1; echo '<li class="forward"><a href="townpubs.php?RSTOWN='.$row1['RSTOWN'].'" rel="external">'.$row1['RSTOWN'].'<small class="listcounter">'.$row1['PubCount'].'</small></a></li>'; } ?> </ul> </div> <!-- COUNTIES --> <div id="counties"> <div class="toolbar"> <h1>View Counties</h1> <a class="back" href="#home">Back</a> </div> <ul class="edgetoedge"> <?php $ltr = ''; while($row1 = mysql_fetch_array($counties)) { $letter1 = substr($row1['RSCOUNTY'],0,1); if ($letter1 != $ltr) { print'<li class="sep">'. $letter1 .'</li>'; } $ltr = $letter1; echo '<li class="forward"><a href="countypubs.php?RSCOUNTY='.$row1['RSCOUNTY'].'" rel="external">'.$row1['RSCOUNTY'].'<small class="listcounter">'.$row1['PubCount1'].'</small></a></li>'; } ?> </ul> </div> <form id="login" action="dologin.php" method="POST" class="form"> <div class="toolbar"> <h1>Login</h1> <a class="back" href="#">Back</a> </div> <ul class="rounded"> <li><input type="text" name="rsUser" value="" placeholder="Username" /></li> <li><input type="Password" name="rsPass" value="" placeholder="Password" /></li> </ul> <a style="margin:0 10px;color:rgba(0,0,0,.9)" href="#" class="submit whiteButton">Submit</a> </form> <form id="signup" action="dosignup.php" method="POST" class="form"> <div class="toolbar"> <h1>Sign up</h1> <a class="back" href="#">Back</a> </div> <ul class="rounded"> <li><select name="RSTOWN" class="postcodedrop"> <option value="">Choose your Town...</option> <?PHP while($row = mysql_fetch_array($result)) { echo '<option value="'.$row['rsTown'].'">'; echo $row['rsTown']; echo '</option>'; }?> </select></li> <li><input name="RSUSER" type="text" class="textbox" id="RSUSER" value="" placeholder="Username" /></li> <li><input type="Password" name="RSPASS" value="" placeholder="Password" /></li> <li>Male <input name="RSGENDER" type="radio" value="Male" /> Female <input name="rsGender" type="radio" value="Female" /></li> <li><input name="RSEMAIL" type="text" class="textbox" id="rsEmail" placeholder="Email" /></li> <li><input name="RSMOBILE" type="text" class="textbox" id="rsMobile" placeholder="Mobile No." /></li> <li><input name="RSAGE" type="text" class="textbox" id="datepicker" placeholder="DOB: dd/mm/yyyy" /></li> </ul> <a style="margin:0 10px;color:rgba(0,0,0,.9)" href="#" class="submit whiteButton">Submit</a> </form> </body> </html> I need to set empty variables at the top and link page to itself?! My site seems to be going well, but on the back end, the users database is going crazy with duplicate entrys. but its not doing it from an INSERT. it seems to be doing it with this code: Code: [Select] $bitquery = $bitcoin->move("bittleship$username", "bittleships", $cost, $minconfirmations); if ($bitquery == true){ $query = mysql_query("INSERT INTO `transactions` ( `id` , `username` , `type` , `amount`, `address`) VALUES ('', '$username', 'buyclicks', '$cost', '')") or die(mysql_error()); $query = mysql_query("UPDATE users SET `clicks` = `clicks`+$quantity, `balance`=`balance`-$cost WHERE `username` = '$username' ") or die(mysql_error()); include('update.php'); Hi i followed a guid to create a login area to my site however i believe its a little outdated and therefore not working, i have done a little bit but being quite new i cannot find all the problems at the moment i have: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/a9855336/public_html/checklogin.php on line 12 here is my script line 12 is marked <?php $host="*************"; // Host name $username="a9855**6_root"; // Mysql username $password="************"; // Mysql password $db_name="****3***36_mail; // Database name // Connect to server and select databse. mysql_connect($host, $username, $password) mysql_select_db($db_name); // username and password sent from form $myusername=$_POST['myusername']; // line 12 $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); // encrypt password $encrypted_mypassword=md5($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$encrypted_mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> if you help please tell me the error so i can learn to debug scripts myself in the future thanks blink359 Hey guys, I'm having a strange problem with cURL that I'm drawing an absolute blank to. It works completely fine locally, but when I upload the files to my webhost and test it over there, it doesn't work at all - it loads for about 2 minutes, and then displays: Server error. The website encountered an error while retrieving http://www.craigwatcher.me/playground/units.php. It may be down for maintenance or configured incorrectly. I've checked the error logs but nothing new is being added into there. Basically I'm just iterating through a list of URLs and cURLing each of them. Let me show you the code that I'm working with: ini_set('max_execution_time',0); require_once('../system/utilities.php'); // This will give us our getLocations() function, which has been tested to work 100% both locally and online $categories = array('jjj', 'ggg', 'bbb', 'sss', 'hhh'); $locations = getLocations(); if (!$locations) exit; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($ch, CURLOPT_TIMEOUT, 10); foreach ($locations as $country => $cities) { $countryCode = getCountryCode($country); foreach ($cities as $city) { foreach ($categories as $category) { $url=$city.'.en.craigslist.'.$countryCode.'/'.$category.'/index.rss'; echo $url.'<br/>'; curl_setopt($ch, CURLOPT_URL, $url); $rss = curl_exec($ch); if (!$rss) echo ' FAILED to load: '.$url.'<br/>'; } } } curl_close($ch); I've already tested everything else (eg. the getLocations() and getCountryCode(), and they prove to work 100% fine both locally and online. What could it POSSIBLY be!? I'm pulling my hair out over here, my mind is boggling and I'm completely lost at what could possibly be going wrong. Hi there, I'm creating a shopping cart and to work out postage cost I need to add all the items weights together. The weight of each item is in the database. I currently have this code: Code: [Select] $basket = $_SESSION['basket']; if ($basket) { $items = explode(',',$basket); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } foreach ($contents as $id=>$qty) { $sql = "SELECT * FROM store WHERE id LIKE '$id' AND live LIKE '0'"; $result = mysql_query($sql); while ($rows = mysql_fetch_array($result)) { extract($row); so to work out each item's weight I can do $rows['weight'] * $qty. but how could i add all the item's weight together? i hope that makes some sense. thanks, jack We have a database that shows for example: 2500-5000 5000-10000 10000-15000 15000-20000 I need to show in a screen what people are have 3000 followers, and as such as grouped into that 2500-5000. The best way I can see how to do this, is to run through the database table for these values. Then for each value, put the first and second set of numbers into two respective variables, say $low, $high. Then find those people who are on a particular platform with followers between those two values. So how do I turn $row->followsrange (which might be for example: "2500-5000"), into:
$low = 2500 Many thanks. ps I have a feeling the hyphen might play a bit part, as it cannot be done by the amount of characters.......... Hi, in Mysql have a row with FLOAT 10,2 In form put the number 20.20 and after reload in form show: 20.200000762939 Hi there im not quite sure how to do something and was wondering if anyone can help me, I am going to create a large database with lots of fields and these are going to be displayed on a page i want to limit it to 20 per page and be able to sort them aswell by ID (default) and then a-z or z-a, i dont know how to do this and i also need to know how to create the next previous and last and first links im guessing theres a count++ involved ? im not quite sure but anyway if someone can help it will be great. Thanks, Blink359 Hi, I have this image gallery slideshow, below the image, it's the thumbnail pics. but the size of the thumbnail pics is random...I want to set the size to be the same for all thumbnail pics, since I'm not the one wrote the code so I'm just guessing that this is the php code for the gallery: Code: [Select] <?php for($i=1;$i<10;$i++) { if(!empty($foto[$i])) { if($i==1) { $foto_first=$foto[$i]; } echo "<img border=0 width=0px height=2px src='conf/i/".$foto[$i]."'>"; $dataku.="'".$foto[$i]."': { thumbnail: 'thumb/".$foto[$i]."'},"; } else { $i--; break; } } $dataku=substr($dataku,0,-1); ?> <link rel="stylesheet" href="css/slideshow.css"> <script src="js/mootools-1.3.1-core.js"></script> <script src="js/mootools-1.3.1.1-more.js"></script> <script src="js/slideshow.js"></script> <script src="js/slideshow.flash.js"></script> <script> window.addEvent('domready', function(){ var data = { <?php echo $dataku;?>}; new Slideshow.Flash('flash', data, { color: ['tomato'],duration: 1500, delay: 10000, height: 400, hu: 'conf/i/', width: 500}); }); </script> <div style="padding-bottom:350px;padding-right:100px"> <div id="flash" class="slideshow"> <img src="conf/i/<?php echo $foto_first; ?>" alt="1" height=100px><br> </div> </div> is this the part that I need to add "size" to it? $dataku.="'".$foto[$i]."': { thumbnail: 'thumb/".$foto[$i]."'},"; I'm totally newb at php, so I have no clue at all hi, I have problems when people upload pictures to my page, some images are only half, see example. http://photoagahi.com/advert/detail/------92733 this is how the code looks like: if ( ! function_exists('upload')) { function upload($post_field, $folder = DEFAULT_ADVERT_IMAGE_FOLDER) { $config['upload_path'] = $folder; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '5000'; $config['encrypt_name'] = true; $config['remove_spaces'] = true; $CI =& get_instance(); $CI->load->library('upload'); $CI->load->library('image_lib'); $CI->load->library('image_lib', null, 'secondary_image_lib'); $CI->upload->initialize($config); if(!$CI->upload->do_upload($post_field)) return $CI->upload->display_errors(); $data = $CI->upload->data(); $thumb['source_image'] = DEFAULT_ADVERT_IMAGE_FOLDER.$data['file_name']; $thumb['width'] = 80; $thumb['height'] = 60; $thumb['create_thumb'] = true; $thumb['maintain_ratio'] = true; $CI->image_lib->initialize($thumb); $thumb_result = true; if(!$CI->image_lib->resize()) $thumb_result = $CI->image_lib->display_errors(); $img_data = getimagesize(DEFAULT_ADVERT_IMAGE_FOLDER.$data['file_name']); if($img_data[0] > 620 || $img_data[1] > 480) { $orig['source_image'] = DEFAULT_ADVERT_IMAGE_FOLDER.$data['file_name']; $orig['maintain_ratio'] = true; $orig['width'] = 620; $orig['height'] = 480; $CI->secondary_image_lib->initialize($orig); $orig_result = true; if(!$CI->secondary_image_lib->resize()) $orig_result = $CI->secondary_image_lib->display_errors(); if($orig_result !== true) return $orig_result; $new_size = getimagesize(DEFAULT_ADVERT_IMAGE_FOLDER.$data['file_name']); if($new_size) { $data['image_width'] = $new_size[0]; $data['image_height'] = $new_size[1]; } } if($thumb_result === true) { $data['file_thumb_data'] = file_get_contents(DEFAULT_ADVERT_IMAGE_FOLDER.$data['raw_name'].'_thumb'.$data['file_ext']); $data['file_data'] = file_get_contents($data['full_path']); return $data; } else return $thumb_result; } } I recently updated wordpress to 5.8 and PHP to v8. Suddenly, when I want to add, change, or edit pictures in the Fusion theme builder, I get redirected to a 404 with this error:
Notice: Use of undefined constant php - assumed 'php' in /home/c0gf5875uk7l/public_html/wp-content/themes/Avada/404.php on line 23 Here is the PHP for the 404.php file this error is calling out:
<?php get_header(); ?>
<?php
Anyone have a clue as to why this is happening? Hi guys, I am currently working on one of my assignments that requires PHP and think of myself as a beginner programmer, only having knowledge of Python and JavaScript. So I have a page that allows me to upload files to the server(no problem here), then I created a drop down menu that shows list of these and depending on which is selected can be viewed after clicking on a submit button(again no problem here). The problem occurs that after clicking submit to save the changes, it refreshes variable containing which file is the target and doesn't save the changes. Tried using sessions, but with no success and I am going absolutely crazy with this. I have been trying to resolve the issue for 5 hours straight. Here is the code if anyone is keen to help me out: <html> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>P2</title> <style> .uploadbox { background-color: skyblue; border: 1px, solid black; margin: 10px; padding: 5px; width: 20%; height: 10%; line-height: 50px; } .selectbox { background-color: skyblue; border: 1px, solid black; margin: 10px; padding: 5px; width: 25%; max-height: 50%; } </style> </head> <body> <h1>File Upload</h1> <form class="uploadbox" action="upload.php" method="post" enctype="multipart/form-data"> Select to upload: <input type="file" name="fileUpload1" id="fileUpload1"> <input type="submit" value="Upload file" name="submit"> </form> <br> <?php session_start(); $dirpath="uploads/"; $filenames=""; if(is_dir($dirpath)) { $files=opendir($dirpath); if($files) { while(($filename=readdir($files))!=false) if($filename!="." && $filename!="..") { $filenames=$filenames."<option>$filename</option>"; } } } $url = 'index.php'; $_SESSION['Open'] = htmlEntities($_POST['Open']); $file="uploads/".$_SESSION['Open']; // check if form has been submitted if (isset($_POST['text'])) { // save the text contents $newcontent = $_POST['text']; file_put_contents($file, $newcontent); // redirect to form again //header(sprintf('Location: %s', $url)); //printf(htmlspecialchars($url)); // exit(); } // read the textfile $text = file_get_contents($file); echo($newcontent); echo($file); echo($_SESSION['Open']); ?> <div class="selectbox"> <form action="" method="post"> <select name="Open"><?php echo $filenames; ?></select> <input type="submit" value="Open"/> </form> <form action="" method="post"> <textarea style="width:90%; height:20%;" name="text"><?php echo htmlspecialchars($text) ?></textarea> <br> <input type="submit" value="Save"/> </form> </div> </body> </html>
Need another set of eyes... I am getting: Quote Warning: Invalid argument supplied for foreach() in ... on line 83 $dup = array(); // Create an array to store the duplicate entries. foreach($fileList as $filename) { if (($handle = fopen(UPLOAD_PATH.$filename, "r")) != FALSE) { // Create the input array while(($data = fgetcsv($handle, 0, ",")) != FALSE) { $sql = "SELECT id FROM leads.prospect WHERE (email='{$data[3]}' OR phone='" . $format->stripPhoneChars($data[2]) . "') LIMIT 1"; $result = $db->query($sql); if (mysql_num_rows($result) == 0) { $sql = "INSERT IGNORE INTO leads.prospect (email, phone, ip, firstName, lastName, resort) VALUES ('" . trim($data[3]) . "', '" . $format->mysqlSafe($data[2]) . "', '" . $format->mysqlSafe($data[5]) . "', '" . $format->mysqlSafe($data[0]) . "', '" . $format->mysqlSafe($data[1]) . "', '" . $format->mysqlSafe($data[4]) . "')"; $result = $db->query($sql); $added++; } else { $dup = array_push($dup, array($data[0], $data[1])); } } fclose($handle); // Close the file } else { echo "<p>Could not load file $filename</p>"; } } echo "$added records added."; // Show me the duplicate data! echo "<h2>This is the data that would be dumped into the duplicate CSV file:</h2> <h3>" . count($dup)." Duplicates:</h3><ol>"; print_r($dup); echo $dup; foreach($dup as $d) { // <-------------------------------------- LINE 83 echo "<li>$d[0] $d[1] $d[2] $d[3]</li>"; } echo "</ol>"; Okay, so I'm a relative newbie to PHP. I've been learning for a few months now, and while I get some bits and can fix most of my errors (with a little help from google occasionally), this one's something I can't explain. Basically, I've been building an admin panel so I can edit various content on a website, as you'd gather. It was all going pretty well, until something I did meant that my forms now do nothing. When I press update on the edit forms or add on the...well..add forms, they go back to the prefilled in content. Here is my add form: <?php include('/home/charioti/public_html/andalasia/admin/skin/header.php'); //form not yet submitted //display initial form if (!$_POST['submit']) { ?> <h1>Add Content</h1><div class="cont"> <table align="center"> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <tr> <td>Title:</td><td><input type="text" name="title" id="title"></td></tr> <tr><td>Content:</td><td><textarea name="content">text here</textarea></td></tr> <tr><td></td><td><input type="submit" name="submit" value="add"></td></tr></table></form> <?php } else { include('/home/charioti/public_html/andalasia/admin/conf.php'); //set up error list array $errorList = array(); $title = $_POST['title']; $content = $_POST['content']; //validation if(trim($_POST['title']) == '') { $errorList[] = 'Invalid entry: activity name'; } if(trim($_POST['content']) == '') { $errorList[] = 'Invalid entry: answer'; } //check for errors if(sizeof($errorList) == 0) { //db connect $connection = mysql_connect($host, $user, $pass) or die('Unable to connect!'); //db select mysql_select_db($db) or die('Unable to select database!'); //generate and execute query $query = "INSERT INTO info(title, content, date) VALUES('$title', '$content', NOW())"; $result = mysql_query($query) or die("Error in query: $query . " . mysql_error()); // print result echo 'content added! <a href=/admin/index1.php>home</a>'; //close database connection mysql_close($connection); } else { //errors found // print as list echo ' The following errors were encountered:'; echo '<br>'; echo '<ul>'; for($x=0; $x<sizeof($errorList); $x++) { echo "<li>$errorList[$x]"; } echo '</ul>'; } } include('/home/charioti/public_html/andalasia/admin/skin/footer.php'); ?> My header file, incase I've messed something the <? session_start(); if(!session_is_registered(username)){ header("location:/admin/index.php"); } ?> <HTML> <HEAD> <TITLE>Andalasia ~ admin: <?php echo basename($_SERVER["PHP_SELF"]); ?></TITLE> <LINK REL="STYLESHEET" HREF="/admin/skin/style.css" TYPE="TEXT/CSS"> </HEAD> <BODY> <TABLE CLASS="CON"> <TR> <TD> <IMG SRC="/admin/skin/adpo.png" style="border-top:0px solid #A10543"> </TD> </TR> <TR> <TD> <TABLE style="font:8pt arial"> <TR> <TD CLASS="nav" style="width:200px"> <DIV CLASS="navi"> <p class="header">navigation</p> <a href="" target="__blank">Guild HQ</a> <a href="/" target="__blank">Web HQ</a> <a href="/admin/index1.php">Admin HQ</a> <a href="/admin/logout.php">logout</a></DIV> <DIV CLASS="navi"> <p class="header">points</p> <?php include('/home/charioti/public_html/andalasia/admin/points.php')?> </DIV> <DIV CLASS="navi"> <P CLASS="header">update posts</p> <?php include('/home/charioti/public_html/andalasia/admin/news/list.php')?> <a href="/admin/news/add.php">Add a post</a> </DIV> <DIV CLASS="navi"> <P CLASS="header">information posts</p> <?php include('/home/charioti/public_html/andalasia/admin/info/list.php')?> <a href="/admin/info/add.php">Add a post</a> </DIV> <DIV CLASS="navi"> <P CLASS="header">activities</p> <a href="/admin/activities/onsite.php">Onsite activities</a> <a href="/admin/activities/offsite.php">Web-hosted activities</a> <a href="/admin/activities/creative.php">Creative web activities</a> </DIV> <DIV CLASS="navi"> <P CLASS="header">Graphics</p> <h2>Guild layouts</h2> <?php include('/home/charioti/public_html/andalasia/admin/layouts/layl.php')?> <a href="/admin/layouts/add.php">Add layout</a> <h2>Userlookups</h2> <?php include('/home/charioti/public_html/andalasia/admin/lookups/list.php')?> <a href="/admin/lookups/add.php">Add lookup</a> <h2>Banners</h2> <a href="/admin/banners/banners.php">Banners</a> <h2>Fonts</h2> <?php include('/home/charioti/public_html/andalasia/admin/fonts/list.php')?> <a href="/admin/fonts/add.php">Add font</a></DIV> <DIV CLASS="navi"> <P CLASS="header">Members</p> <?php include('/home/charioti/public_html/andalasia/admin/users/list.php')?> <a href="/admin/users/add.php">Add user</a> </DIV> <DIV CLASS="navi"> <!-- BEGIN CBOX - www.cbox.ws - v001 --> <div id="cboxdiv" style="text-align: center; line-height: 0"> <div><iframe frameborder="0" width="200" height="305" src="http://www2.cbox.ws/box/?boxid=2184566&boxtag=evz64m&sec=main" marginheight="2" marginwidth="2" scrolling="auto" allowtransparency="yes" name="cboxmain" style="border:#11011A 1px solid;" id="cboxmain"></iframe></div> <div><iframe frameborder="0" width="200" height="75" src="http://www2.cbox.ws/box/?boxid=2184566&boxtag=evz64m&sec=form" marginheight="2" marginwidth="2" scrolling="no" allowtransparency="yes" name="cboxform" style="border:#11011A 1px solid;border-top:0px" id="cboxform"></iframe></div> </div> <!-- END CBOX --> </DIV> </TD> <TD CLASS="c" VALIGN="TOP" style="width:600px"> And my edit file: <? // edit.php - edit a layout ?> <!-- page header - snip --> <? // includes include("/home/charioti/public_html/andalasia/admin/skin/header.php"); include("/home/charioti/public_html/andalasia/admin/conf.php"); // form not yet submitted // display initial form with values pre-filled if (!isset($_POST['submit'])) { // open database connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // generate and execute query $id = mysql_escape_string($_GET['id']); $query = "SELECT title, content, id FROM info WHERE id = '$id'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // if a result is returned if (mysql_num_rows($result) > 0) { // turn it into an object $row = mysql_fetch_object($result); // print form with values pre-filled ?> <h1>Update post - ID <? echo $id; ?></h1> <div class=cont> <table class=view align=center> <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="POST"> <input type="hidden" name="id" value="<? echo $id; ?>"> <tr> <td valign="top"><b>Title</b></td> <td><input size="50" maxlength="250" type="text" name="title" value="<? echo $row->title; ?>"></td> </tr> <tr> <td valign="top"><b>Content:</b></td> <td><textarea name=content><? echo $row->content; ?></textarea></td> </tr> <tr> <td colspan=2><input type="Submit" name="submit" value="Update"></td> </tr> </form> </table> </div> <? } // no result returned // print graceful error message else { echo "<h1>Error!</h1><div class=cont>That post could not be located in our database.</div>"; } } else { // form submitted // start processing it // set up error list array $errorList = array(); $count = 0; // validate text input fields $title = mysql_escape_string($_POST['title']); $content = mysql_escape_string($_POST['content']); $id = mysql_escape_string($_POST['id']); if (!$title) { $errorList[$count] = "Invalid entry: title"; $count++; } if (!$content) { $errorList[$count] = "Invalid entry: content"; $count++; } // check for errors // if none found... if (sizeof($errorList) == 0) { // open database connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // generate and execute query $query = "UPDATE info SET title = '$title', content = '$content' WHERE id = '$id'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // print result echo "<h1>Success!</h1><div class=cont>Update successful. <a href=/admin/index1.php>Go back to the main menu</a>.</font></div>"; // close database connection mysql_close($connection); } else { // errors occurred // print as list echo "<h1>Errors:</h1><div class=cont><font size=-1>The following errors were encountered: <br>"; echo "<ul>"; for ($x=0; $x<sizeof($errorList); $x++) { echo "<li>$errorList[$x]"; } echo "</ul></font></div>"; } } include('/home/charioti/public_html/andalasia/admin/skin/footer.php'); ?> I started off working with templates from my book and from various sources, so I've tried reseting my pages to those and reworking them, and I've deduced that it's probably something to do with my header file, I just can't work out what or whereabouts the problem is. Any help you can offer would be greatly appreciated. (: I'm trying to setup my database class so that by default it will create all of the tables and triggers required for my application to run. I've got everything working except for it adding the trigger. Here's the relevant code (slightly obfuscated for security reasons): private function check_consistency() { $database_query = <<<QUERY CREATE TABLE IF NOT EXISTS d2b_users ( id INT NOT NULL AUTO_INCREMENT, obfuscated INT NOT NULL, obfuscated VARCHAR(50) NOT NULL, obfuscated VARCHAR(32) NOT NULL, obfuscated VARCHAR(32) NOT NULL, obfuscated VARCHAR(32) NOT NULL, obfuscated BOOL NOT NULL DEFAULT '1', UNIQUE KEY(id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; CREATE TABLE IF NOT EXISTS d2b_statistics ( id INT NOT NULL, obfuscated BIGINT NOT NULL DEFAULT '0', UNIQUE KEY(id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; delimiter | CREATE TRIGGER d2b_auto_statistics AFTER INSERT ON d2b_users FOR EACH ROW BEGIN INSERT INTO d2b_statistics SET id = NEW.id; END; | delimiter ; QUERY; if(!$consistency = $this->link->multi_query($database_query)) { die("Failed to create/verify the default database tables."); } return true; } I've also tried removing the delimiter and the colon after the INSERT line in the trigger and I still can't get it to add properly. What's annoying is that I'm able to take the code for the trigger from above and go into phpmyadmin and paste it into the SQL and it will add and work correctly. However, I'm trying to get my class to do that automatically so the php application automatically installs itself on other servers. What am I doing wrong? |