PHP - I Know This Is Another Stupid Question, But I'm Tired And Can't Find It
<?php
$result = mysql_query ("SELECT genre FROM genres ORDER BY genre"); while ($row = mysql_fetch_row($result)) { echo "<tr>"; for ($i =0; $i<5; i++) { foreach ($row as $genre) echo "<td><input type='submit' name='listMovies' value='" .$genre ."'></td>"; } echo "</tr>"; } ?> ok i'm getting a single line of submit buttons for this output. i want there to be 5 buttons in a row. it seems like i have done this before with the for loop i have, but something is not working right. i know it will have to be a for loop, i just can't figure out where to start it. i know there are 1000 different ways to get the buttons on the screen, but i want to do it with the submit buttons. the best i can get is 5 columns of the same thing i'm outputting now. thanks in advance, i know this is a no-brainer. i just don't have a brain atm Similar TutorialsCode: [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 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.. !!! 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? Hi guys, im needing to grab information out of a mysql database field called "clientname" thats inside a table called "clients" how do i retrieve the clients name in html and display it? heres what i have so far, am just needing the code to retrieve... $host = localhost; $dbuser = user; $dbpass = pass; $dbname = mydb; $connection = mysql_connect($host, $dbuser, $dbpass); $db = mysql_select_db($dbname, $connection); // code to retrieve a particular clients details Cheers, i am trying to make a page to upload music to my website and add the information of the songs into a database, but i cannot get php to let me upload a file bigger than 2mb even after i went into the php.ini and changed the max_upload_size and a few others to 99mb. So i was wondering if i could put my music in a folder on my website and pull the data from the items in the folder and make database entries(probably doubtful) or if i could get some help with getting php to upload bigger files? thanks, Adam My Code is suppose to parse a text file and return the value that is attached to the variable. However when I try calling two different variables, one after the next, it adds a space. Here is the code: <?php define("FILE", "config/review_setup.txt"); function fix($var){ $var = strtolower($var); return str_replace(" ", "_", $var); } function findValue($var, $file = FILE){ $var = fix($var); $val = NULL; $fh = fopen(FILE, "r"); while(!feof($fh)){ $string = fgetss($fh); $i = stripos($string, "="); $f_var = str_replace(" ", "", substr($string, 0, $i) ); if($f_var == $var){ $val = str_replace("\"", "", substr($string, $i+1, strlen($string)) ); $val = str_replace(" ", "", $val); break; } } if(is_null($val)) $val = "DNE"; fclose($fh); } echo findValue("host"); echo findValue("port"); ?> Output of above: Quote smtp1.servage.net 25 if I just do host, I get this: Quote smtp1.servage.net Any thoughts? Hey everyone this is really really simple. say my site is www.mywebsite.com in my index page I have this define('PHPSITE_DIR', 'mywebsite'); require_once(PHPSITE_DIR . '/test/hello.php'); I have a folder named test and inside the folder i have hello.php but when i go to www.mywebsite.com i get Code: [Select] Warning: require_once(mywebsite/test/hello.php) [function.require-once]: failed to open stream: No such file or directory in wtf? i'm using godaddy server if that matters So I wanted to create stickers on my forum where people type in say ":Blobby-Tired" and then instead of the comment showing ":Blobby-Tired" it shows an html image tag displaying a picture of Blobby in the comment box So I created the following page CommentUpload.php However my sql fails to insert it despite the fact when I "echo $new" it shows the image on the page correctly And it can't be my sql insert code as if I change $new variable for "$BodyText" int he SQL query it it inserts ":Blobby-Tired" OK?
<?php include 'dbconnect.php'; session_start(); if(isset($_POST["submit"]) && !empty($_POST["CommentText"])){ $id = intval($_SESSION['id']); echo $_SESSION['id'] . '<p> </p>' ; $BodyText = $conn -> real_escape_string($_POST['CommentText']) ; $User = $_SESSION['username']; //Replace flairs with <img> tags /*not working currently) */ $new = str_replace(":Blobby-Tired","<img src='flairs/Blobby-Tired.jpg'> </img>","'$BodyText'"); echo "$new"; /************************/ $sql = "INSERT INTO Posts (User, CommentText, IdOfThread) VALUES ('$User','$new','$id')"; if (mysqli_query($conn, $sql)) { echo "New record has been added successfully !"; } else { echo "Error: " . $sql . ":-" . mysqli_error($conn); } mysqli_close($conn); } ?> Edited April 28 by Fishcakes 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. 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()); } ?> 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); 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! 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 have a bunch of quasi-static values that must be available to the application. Most of them are set based on settings in a configuration file. Others are based on GET, COOKIE, or SESSION values, and utilize the database to get the actual values. The values will never be written to or modified by the application, only read.
It seems to me that I could create some sort of superclass which includes static methods and properties, and I could access any value by something like superclass::get('some.value'); I could design the class so that the values are queried from the DB or obtained from a parsed file only the first time they are requested, and for future requests, retrieved from a static property.
That being said, I have been told from more than one person that I am just doing it "wrong".
Please let me know what is wrong about it.
Thank you
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 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 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 So 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 |