PHP - Stupid Problem With Basic Editnews.php
Similar TutorialsSo like When somones enter my site it shows them as a guest, but then if they havn't clicked anywere for about 5minutes and then refresh or if somone else refresh it will delete from the active users list because it's been over 5 minutes, but then if that same person refreshes again my script wont catch them as a GUEST AGAIN!! It just shows no one online, none of my if's catch him and put him in the ibf_session table! Code: [Select] //check for cookies //If no username, Is a Guest, Has COOKIE_ID and cookie USER_NAME and COOKIe PASSWORD if(!isset($_SESSION['user_name']) && !isset($_SESSION['is_guest']) && isset($_COOKIE['user_id']) && isset($_COOKIE['user_name']) && isset($_COOKIE['password'])){ $user_cond = "user_name='{$_COOKIE['user_name']}'"; $sql = "SELECT `id`,`user_name`,`approved` FROM users WHERE $user_cond AND `pwd` = '{$_COOKIE['password']}' AND `banned` = '0' "; $result = mysql_query($sql) or die (mysql_error()); $num = mysql_num_rows($result); // Match row found with more than 1 results - the user is authenticated. if ( $num > 0 ) { list($id,$full_name,$approved) = mysql_fetch_row($result); if(!$approved) { echo "YOU FREAKING HACKER"; exit(); } $_SESSION['user_id']= $id; $_SESSION['user_name'] = $full_name; $lol = session_id(); //$minute5 = 30 ? (time() - 30) : (time() - 3600); // mysql_query("DELETE FROM ibf_sessions WHERE running_time < {$minute5}"); mysql_query("INSERT INTO ibf_sessions (id, member_name, member_id, ip_address, running_time, location, member_group) ". "VALUES ('".$lol."', '{$_SESSION['user_name']}', '{$_SESSION['user_id']}', '{$_SERVER['REMOTE_ADDR']}', '".time()."', ". "'Index', '1')") or die(mysql_error()); unset($_SESSION['is_guest']); } } $lol = session_id(); //Thanks if (!$id) { //Create Guest Session ~ if (!isset($_SESSION['user_id']) && @(!$_SESSION['is_guest']) && !isset($_COOKIE['password'])) { //$minute5 = 39 ? (time() - 30) : (time() - 3600); //echo $minute5; // mysql_query("DELETE FROM ibf_sessions WHERE running_time < {$minute5}"); mysql_query("INSERT INTO ibf_sessions (id, member_name, member_id, ip_address, running_time, location, member_group) ". "VALUES ('".$lol."', 'Guest', '0', '{$_SERVER['REMOTE_ADDR']}', '".time()."', ". "'Index', '0')") or die(mysql_error()); $_SESSION['is_guest'] = 'yes'; } } if (isset($_SESSION['user_id']) && !isset($_SESSION['is_guest'])) { mysql_query("UPDATE ibf_sessions SET member_name='{$_SESSION['user_name']}',member_id='{$_SESSION['user_id']}',member_group='1', running_time='".time()."', in_forum='".$f."', in_topic='".$topicid."', location='".$act."' WHERE id='".$lol."'") or die(mysql_error()); } else { mysql_query("UPDATE ibf_sessions SET member_name='Guest',member_id='0',member_group='0', running_time='".time()."', in_forum='".$f."', in_topic='".$topicid."', location='".$act."' WHERE id='".$lol."'") or die(mysql_error()); } Thanks, it might be confusing but re read Hi, I'm very new to PHP so I hope this is not frustrating. I'm having trouble understanding how "isset" works. I'm trying to get it so that when I click a button, it returns two variables(in an array). This works, but I tried to use "Isset" to detect if a array was created, then alter the variable. It's not working... I'm not too sure where I'm going wrong, could anyone give me some advice? Thanks
<?php if(isset($_POST['name'])) { $userAnswer = $_POST['name']; if(isset($_SESSION['test'])){ $_SESSION['test'][$userAnswer]['var1']++; $test = $_SESSION['test'][$userAnswer]; foreach ($test as $key){ echo json_encode($key); }; } else { $test = $_SESSION['test'][$userAnswer]=array("var1" => 1, "var2" => 2); foreach ($test as $key){ echo json_encode($key); }; } } ?> $(document).ready(function(){ $("button").click(function(){ var test = "here"; $.ajax({ url: 'info.php', type: "POST", dataType:'json', data: ({name: test}), success: function(data){ $("#click").fadeOut(function() { $(this).append(data); }).fadeIn(); } }); }); }); I have a table 'combo' with two fields, id and char.
I want to populate a table, with the following query which fails.
$sql = mysql_query("SELECT id,char FROM combo ORDER BY id DESC LIMIT 28");
I a bit rusty on sql but can't see what is wrong with this.
Can anyone help please.
http://i.imgur.com/6olCy.png The picture (in the imgur link) pretty much describes what I'm trying to do. As it stands, it would take too long to simply do everything manually with html and css (both of which I'm pretty good at I think), moving all img src and dates from one div tag to another whenever I wanna add something. So yeah, what's the most efficient way to simply submit a picture, and all my other pictures will move? I know some of you guys will say to just learn php, but quite frankly, I don't have the time... and all the php books are ~1000pgs long which seems really daunting. I know, my problem's pretty basic and it'll probably be covered in the first 100pages or so, but still, like I said I don't have that much time for the moment. When I do, however, can you guys recommend me the quickest guide/video series/book to learn practical php? Not the most comprehensive, as the stuff I'm going to be doing's not that complex. One last thing, I've been hearing about CakePHP; what is it? I read that it's an "open source web application framework", but I still have little clue. I'm currently using dreamweaver for all my web stuff (no I do not use the WYSIWYG feature, I just grown accustom to using it). Should I "learn cakephp"? Please answer any one of those questions (particularly the first one). Many thanks and I'll be sure to reply! Hello there. Well this problem maybe basic but is kind of annoying me. I havea solution to it which I wil lexplain. I have created a .php document which has html codes as well. It is a form that provides validation, for arguments sake lets say it is a form that validates if a user has entered their username and password, if not it will produce an error. The problem I am having is I have embedded the code inside the echo " code is here "; Now I have looked at escape characters and tried afew things, yet it still produces the same error on the same line. Example echo " !!!!!!!<form action='book.php' method='post' onsubmit="return checkForm('flogin');">!!!!!! The reset of the form is here ..... ""; echo The area highlighted in exclamation marks is where the area occurs, due to the quotes. Any suggestions. Thanks. Ok first of all I want to apologize for asking what I'm about to ask. I understand it should be some stupidly easy to find mistake but considering the fact I have to send the code tomorrow leaves me with little to no time to try and find the solution so I'll be asking here and hope that by the time I wake up tomorrow an answer will be here and I'll be able to resume scripting. So my problem is that I just can't find how to make php commands run at all. I tried just randomly inserting them into my html code then found out it needs a separate file. So I created the basic.php with this code: <html> <body> <?php echo "Hello World"; ?> <div>adgaeganerhaohn</div> </body> </html> tried opening it through a form in my html code but it wouldn't print the Hello world line, then I tried running it straight into firefox but I only got adgaeganerhaohn again (without that line I get a white page) So I need to know what am I doing wrong? I have php5.301 installed with default options (no server). thanks for your help beforehand, once I get a bit more into php I'll be coming back with serious questions but for now I really need someone to tell me how php is supposed to work and what I'm doing wrong Hi, I have just started using PHP again after a long break and am very rusty. I am having a few problems with some basic things: I have defined a function to connect to my MySQL database and it doesn't work. My $hostname, $username, $password variables are stored in a separate php file which I am including first and the standard mysql_connect function works ok, but I wanted to put it inside another user defined function called "condb" to make things quicker later. my function looks like this: function condb(){ mysql_connect($hostname, $username, $password) OR DIE ('Unable to connect to database! Please try again later.'); } and I am trying to run it like this: condb(); Unfortunately it is not working. Probably a basic error but any help appreciated. Thanks Okay so I've been going over the PHP manual doing test applications as I go along and I came across this issue that honestly totally threw me. I figured it out (after 20 minutes of thinking the world was about to end) so thought I'd post the code and although some experts will simply shake their head others will hopefully see the funny side. So I'm running a simple script iterating through two arrays and outputting some text. Code is below. Code: [Select] <?php for($i = 0;$i < 100;$i++){ for($k =0; $k < 100;$k++){ echo "$i and $k"; } } ?> I'd have expect to get something along the lines of 00 and 01 and 02 and 03 etc... but as you have probably guessed that's not what I was getting. Instead I was getting 0 and 00 and 10 and 20 and 30. Anyway figured it all out now and I'm hanging my head in shame. For some reason both admin and home return home's contents but everything else returns it's own contents... <?php if(!isset($_GET['p'])) { $result = mysql_query("SELECT * FROM body WHERE name='home'"); ?> <script type="text/javascript">alert("home");</script> <?php } else{ $result = mysql_query("SELECT * FROM body WHERE name='" . $_GET['p'] . "'"); ?> <script type="text/javascript">alert("SELECT * FROM body WHERE name='<?php echo $_GET['p']; ?>'");</script> <?php } $row = mysql_fetch_array($result); function changeStuff($str) { $str = str_replace("[link=","<a href='",$str); $str = str_replace("[/link]","</a>",$str); $str = str_replace("[img]http://","<img src='",$str); $str = str_replace("[/img]","' />",$str); $str = str_replace("[b]","<b>",$str); $str = str_replace("[/b]","</b>",$str); return $str; } ?> if(!isset($_GET['p'])) { include("home.php"); } else{ include($_GET['p'] . ".php"); } echo changeStuff($row['content']); ?> There are three rows in my body table. They are as follows 1) (name) = home (content) = this is home page 2) (name) = admin (content) = this is admin page 3) (name) = eq (content) = this is equipment page When $_GET['p'] = home It displays this is home page When $_GET['p'] = admin It displays this is home page When $_GET['p'] = eq It displays this is equipment page The javascript alerts are all displaying the correct information so i don't understand what is fudging it up... I'm sure this is just a stupid mistake, but can someone please help me figure it out? I have one page with a dropdown that is populated from our database, I have submit to pull through to the next page but nothing shows up on the next page (app/approval). I've tried adding some echo statments, but they all show up blank. Code: [Select] <? require ('includes/getconfig.inc'); require ('includes/auth.inc'); require ('includes/dbfunctions.inc'); include (dirname(__FILE__).'/../includes/menuhead.inc'); include ('apptable_functions.inc'); $sql="SELECT pol_id, pol_policy_number FROM policies"; $result=myload($sql); $items = count($result); $options=""; for($x=0; $x<=$items; $x++) { $id=$result[$x]['pol_id']; $thing=$result[$x]['pol_policy_number']; $options.="<OPTION VALUE=\"$id\">".$thing; } ?> Select a case number to see the payout approval. <br> <form action="app/approval.php" method='post'> <SELECT NAME=pol_policy_number> <?=$options?> </SELECT> <input name="Submit" type="submit" Value="Submit Policy Number"/> </form> <br> Code: [Select] <? require ('includes/getconfig.inc'); require ('includes/auth.inc'); require ('includes/dbfunctions.inc'); $pol_number = $_POST['pol_policy_number']; echo "$pol_number"; ?> I'm not sure what I'm doing wrong here. I'm trying to get this to show the schedule for each person in the database. It does show the schedule, but it only shows one day in each box, and it's the last day. So, if the last day is October 28th, it populates every box with the schedule for the 28th. Code: [Select] <?php $query = "SELECT * FROM employees WHERE day > '$current_date' AND day < '$get_date'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { $id = $row['id']; $position = $row['position']; $pay_rate = $row['pay_rate']; $total_hours = $row['total_hours']; $total_pay = $row['total_pay']; $start_time = date("g:i a", strtotime($row['start_time'])); $end_time = date("g:i a", strtotime($row['end_time'])); $work_day = date("l", strtotime($row['day'])); $day = date("F j", strtotime($row['day'])); if($end_time == "24:00:00"){ $end_time ="Close";}; $schedule = $start_time ."<br />". $end_time; $first = $row['first_n']; $last = $row['last_n']; if ($work_day == "Monday"){ $name[$last.", ".$first] = $schedule; } if ($work_day == "Tuesday"){ $name[$last.", ".$first] = $schedule; } if ($work_day == "Wednesday"){ $name[$last.", ".$first] = $schedule; } if ($work_day == "Thursday"){ $name[$last.", ".$first] = $schedule; } if ($work_day == "Friday"){ $name[$last.", ".$first] = $schedule; } if ($work_day == "Saturday"){ $name[$last.", ".$first] = $schedule; } if ($work_day == "Sunday"){ $name[$last.", ".$first] = $schedule; } } foreach ($name as $n => $s) { ?> <tr> <td align="left" valign="top"><?php echo $n; ?></td> <td align="left" valign="top"><?php echo $position; ?></td> <td align="center" valign="top"><?php echo $s; ?></td> <td align="center" valign="top"><?php echo $s; ?></td> <td align="center" valign="top"><?php echo $s; ?></td> <td align="center" valign="top"><?php echo $s; ?></td> <td align="center" valign="top"><?php echo $s; ?></td> <td align="center" valign="top"><?php echo $s; ?></td> <td align="center" valign="top"><?php echo $s; ?></td> <td align="right" valign="top"> </td> </tr> <? } ?> Can somebody see what I'm doing wrong? Thanks in advance Quote Notice: Use of undefined constant d - assumed 'd' in /home/rayth/public_html/forum/shout.php on line 11 Strict Standards: date() [function.date]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'UTC' for 'UTC/0.0/no DST' instead in /home/rayth/public_html/forum/shout.php on line 11 Notice: Use of undefined constant F - assumed 'F' in /home/rayth/public_html/forum/shout.php on line 11 Strict Standards: date() [function.date]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'UTC' for 'UTC/0.0/no DST' instead in /home/rayth/public_html/forum/shout.php on line 11 Notice: Use of undefined constant Y - assumed 'Y' in /home/rayth/public_html/forum/shout.php on line 11 Strict Standards: date() [function.date]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'UTC' for 'UTC/0.0/no DST' instead in /home/rayth/public_html/forum/shout.php on line 11 I keep getting this. Line 11: $Date = date(d)." ".date(F)." ".date(Y); Hi. I am making a login script for my website and i want it to also not just check for the username and password but to also check for the value 1 in the field beta. Heres what i got <?php ob_start(); Mysql info // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Define $myusername and $mypassword $myusername=$_POST['myusername']; $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); $sql="SELECT * FROM $tbl_name WHERE username=md5('$myusername') and password=md5('$mypassword')and beta= '1'"; $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 Or Not Beta Tester"; } ob_end_flush(); ?> The login fully works but the check for the 1 dont. How whould i do this? Stupid question probably pretty obvious. but.. I am trying to add a href to an image echo And I can't seem to code this right. Here is a text link echo call: Code: [Select] echo '<div id="nav_image_title" align="center" valign="middle" ><a href="'. $sess->url( URL .'index.php?page=shop.browse&category_id=' . $categories[$kp]['category_child_id']). '">'.$categories[$kp]['category_name'].'</a></div>'; And I want to add that "a href" to this image: Code: [Select] echo '<div>'. ps_product::image_tag( $categories[$kp]["category_thumb_image"], "alt=\"".$categories[$kp]["category_name"]."\"", 0, "category") . '</div>'; I not sure if it's just too many hours working today.. But how do I add that link to that image. Thanks for any help anyone can give.. !!! I beleive that my code is "ok" overall, but i am getting a syntax error on lines 6 & 26, pretty sure im making a stupid mistake here, Code is a plugin for a PHP IRC Bot, basically a toggle on/off command via "!radio" to send meta data from the audio stream every 5minutes. <?php require_once('shoutcast_class.php'); $radio = false; class plugRadio{ public static function onCommandRadio( if($radio == false) $radio = true; $dh->reply('3 Info Stream : ON', $event->getName(), $dh->getCommandTrailing()); while($radio == true){ event $event, datahelper $dh = null, $help = 'use !Radio to toggle stream info On/Off') { $display_array = array("Stream Title", "Stream Genre", "Stream URL", "Current Song", "Server Status", "Stream Status", "Listener Peak", "Average Listen Time", "Stream Title", "Content Type", "Stream Genre", "Stream URL", "Current Song"); $radio = new Radio("radio.anonops.ru:8000"); $data_array = $radio->getServerInfo($display_array); $dh->reply('15,1 #RadioPayback | 9,1On Air: '.$data_array[8].' 15,1| 9,1Now Playing: '.$data_array[12].' ', $event->getName(), $dh->getCommandTrailing()); $event->delete(); flush(); sleep(300); } } if($radio == true) $radio = false; $dh->reply('4 Info Stream : OFF', $event->getName(), $dh->getCommandTrailing()); } ?> Code: [Select] $code = array("03","09"); if (!in_array($_POST['CODE'], $code)); message("Sorry, not today"); my $_POST['CODE'] is <input type=hidden name=CODE value='03'> still not being validated.. hmm I am fairly new to php relating to databases so I'm a little uncertain with my current quandry! I am using a component for Joomla to display tables of motorsport results. The programme produces a table in a module position with a number of links, driver name, team name and a view table link. My problem is that my SEO plug-in does not have a compatablity add on for the component and it screws up. I dont need the links, so I am trying to remove them. My question is this: Code: [Select] class TracksHelperRoute { /** * return link to details view of specified event * @param int $id * @param int $xref * @return url */ function getRoundResultRoute($id = 0) { $parts = array( "option" => "com_tracks", "view" => "roundresult" ); if ($id) { $parts['pr'] = $id; } return self::buildUrl( $parts ); } If I remove this bit: Code: [Select] return self::[b]buildUrl[/b]( $parts ); Will that stop the links from being made?? I have removed the link into the application, but I don't want to break the whole component removing code! all i am doing is trying to left join my column row "to_id" and "from_id" i can successfully left join to_id but once i try to add "from_id" to the "ON" clause it makes all my data blank Code: [Select] SELECT gold_logs.*,name,star FROM gold_logs LEFT JOIN ibf_members ON to_id = ibf_members.id WHERE to_id = 1 That query works fine, but when i try to add my "from_id" column the query works with no error's but no results are shown Code: [Select] SELECT gold_logs.*,name,star FROM gold_logs LEFT JOIN ibf_members ON (to_id = ibf_members.id AND from_id = ibf_members.id) WHERE to_id = 1 Okay, So I have a dropdown box: Code: [Select] <select name="imgsize"> <option value="small">480 x 360</option> <option value="medium">720 x 540</option> <option value="big">1200 x 900</option> <option value="large">1440 x 1080</option> </select> and I have code that gets the size: Code: [Select] $resizeimg = $_REQUEST["imgsize"]; But I cannot get it to work with an if statement: Code: [Select] if ($resizeimg == "large") { } It just comes up with about 50 lines of gibberish. I have used error_reporting(-1); but that is not coming up with any errors. Could anyone help please. Its probably so simple, but my mind is drawing a blank Hi There I have a simple cms system that I have built but for some reason the login script wont let me login to the cms. Strange thing is the script seems to works on the original database but when I changed the details to a new db it doesnt work. I have made the necessary changes for the connecting to the db etc but it just wont let me login. Can anyone help The url is drmonlinemarketing.com/cms2/loginadmin.php try login with username demo password test thanks shalli |