PHP - Can Give Default: A Name?
In a Switch statement, can you give the Default: a specific name, maybe like this...
switch ($resultsCode){ // Missing Primary Key. case 'COMMENT_MISSING_KEYS_2050': echo '<h1>System Error</h1>'; echo '<p>A Fatal Error has occurred. Please contact the System Administrator. (2050)</p>'; break; default 'DEFAULT_CATCHALL_ERROR_CODE_9999': echo '<p>You have reached the catch-all error code... (9999)</p>'; break; Debbie Similar TutorialsHow to do #3 by a PHP page instead? mainly so that there wouldn't be a need to export the sql after doing #2 then import it into the online phpmyadmin(#3) #1. Convert database from foxpro to sql #2. Change some fields in the sql table #3. Upload to phpmyadmin Is it possible to create a code to export from the server and then import the sql online? like by making use of mysql_fetch_array() and insert into I am trying to learn PHP basics, and I just cant figure out a way to insert color when certain conditions are met. In my code below, I want to print out red color on lets say, odd numbers from 20-49. Appreciate your help big time! <?php for ($i=20; $i<=49; $i++){ echo "$i<br>"; } ?> I wanna give error messages if the user dont enter their name, email or comments. I trıed to do it but mine didnt work. Please help me do it. Index.php page Code: [Select] <html> <head> <title>Guestbook</title> </head> <body> <font color="#CC0000" size="+2">Please sign our guestbook</font> <br \> <br \> <?php echo "<form name=\"Guestbook\" action=\"confirm.php\" method=\"post\">\n"; echo "<table bgcolor=\"#DAE5CD\">\n"; echo " <tr>\n"; echo " <td valign=\"top\">Name: </td>\n"; echo " <td><input type=\"text\" name=\"name\" size=\"25\" value=\"Your Name\"></td>\n"; echo " </tr>\n"; echo " <tr>\n"; echo " <td valign=\"top\">E-mail:</td>\n"; echo " <td><input type=\"text\" name=\"email\" size=\"25\" value=\"example@mail.com\"></td>\n"; echo " </tr>\n"; echo " <tr>\n"; echo " <td valign=\"top\">Comments:</td>\n"; echo " <td><textarea rows=\"5\" cols=\"30\" name=\"comments\">Comments</textarea></td>\n"; echo " </tr>\n"; echo " <tr>\n"; echo " <td></td>\n"; echo " <td align=\"right\"><input type=\"submit\" name=\"submit\" value=\"Submit\"> <input type=\"reset\" value=\"Clear\"> </td>\n"; echo " </tr>\n"; echo "</table>\n"; echo "</form> "; ?> </body> </html> confirm.php page Code: [Select] <html> <head> <title> Submission receieved! </title> </head> <body> <font size="+2" color="#00B0EB">Your submission has been sent successfully!</font><br /> <br /> <?php //extract($_REQUEST); if (!isset($_POST["$submit"])) { if (empty($_POST["name"])) { echo "Please enter your name!"; } else if (empty($_POST["email"])) { echo "Please enter your E-mail"; } else if (empty($_POST["comments"])) { echo "Please enter some text"; } } ?> <table bgcolor="#DAE5CD" width="%50" cellpadding="5"> <tr> <td valign="top" width="75">Name : </td> <td> <?php echo $_POST["name"];?> </td> </tr> <tr> <td valign="top">E-Mail : </td> <td> <?php echo $_POST["email"]; ?> </td> </tr> <tr> <td valign="top">Comments :</td> <td> <?php echo $_POST["comments"]; ?> </td> </tr> </table> </body> </html> Hi, Hope this is the right place for this... I have php routines that print itineraries. For some reason the timestamp (1351378800) returns the same date Sunday 28th October (2012) as the time stamp (1351465200). $count = 0; while ($count <= ($nights+1)) { echo date ('l', $startdate1)." (".$startdate1.")"; echo "<br>"; echo date ('jS F', $startdate1); $startdate1 += 86400; // more code } Any ideas? Many thanks, Peter Hey, I would like to get some practice in the following areas: - arrays (including multidimensional and associative) - functions and their return values I would appreciate it if anyone could give me/point me to some exercises/challenges. Thanks! Hello, I have made a PHP script that will feed an existing XML file. The file stores song details like, title, name of singer etc ... Now the file structure is like this for the moment: Code: [Select] <?xml version="1.0" encoding="UTF-8"?> <music> <song> <title>Without me</title> <artist>Eminem</artist> <url>songs/coreIssues.mp3</url> <image>img/den.jpg</image> <discspeed>11</discspeed> </song></music> But I need it to be: Code: [Select] <?xml version="1.0" encoding="UTF-8"?> <music> <song mainTitle="Eminem - Without me"> <title>Without me</title> <artist>Eminem</artist> <url>songs/coreIssues.mp3</url> <image>img/den.jpg</image> <discspeed>11</discspeed> </song></music> I need it to be like that so if I want to delete a song from the list I just check for the element which will have a unique mainTitle and then delete that element with all it's details. Now, I've searched on Google for some solutions but didn't find any yet. Anyone here knows how to do this? Thanks! Alright, this is the code that i cant seem to get working. Its supposed to update the pin_lock field in my database. I have two databases that it needs to read from, the Account database to verify the login, then the Game database to modify the pin_lock field. It comes up that its sucessfully modified the entry but when i check it, its still the same as it was before. session_start(); if ($_POST["vercode"] != $_SESSION["vercode"] OR $_SESSION["vercode"]=='') { print("<center>Incorrect verification code!"); die(); } require_once('config.php'); mysql_select_db($accdb); $accountid=$_POST['accountid']; $pass=$_POST['pass']; $email=$_POST["email"]; $idnumber=$_POST["question"]; $phone=$_POST["answer"]; session_start(); if(!$_POST["accountid"]) { print("<center>Account ID Field Empty!"); die(); } if(!$_POST["email"]) { print("<center>E-mail Address Field Empty!"); die(); } if(!$_POST["question"]) { print("<center>Security Questions Field Empty!"); die(); } if(!$_POST["answer"]) { print("<center>Answer Field Empty!"); die(); } if(!ereg("^[0-9a-z]{4,12}$",$accountid)) { print("<center>Account ID Only letters from \"a\" to \"z\" and numbers, lenght of 4 to 12 characters"); die(); } if(!ereg("^[0-9a-z]{4,14}$",$pass)) { print("<center>Password Only letters from \"a\" to \"z\" and numbers, lenght of 4 to 14 characters"); die(); } if(!ereg("^[0-9a-zA-Z_]{4,128}$", (strtr($email, Array('@'=>'','.'=>''))))) { print("<center>E-mail Only letters a to z and special chars @ . are allowed!"); die(); } if($_POST["pass"]!=$_POST["pass2"]) { print("<center>Passwords do not match!"); die(); } $ac = mysql_fetch_array(mysql_query(sprintf("SELECT * FROM account WHERE name='$accountid'"))); if (!$ac) { print("<center>Account ID does not exist!"); die(); } $em = mysql_fetch_array(mysql_query(sprintf("SELECT * FROM account WHERE name='$accountid' AND email='$email'"))); if (!$em) { print("<center>E-mail is incorrect!"); die(); } $q = mysql_fetch_array(mysql_query(sprintf("SELECT * FROM account WHERE name='$accountid' AND idnumber='$idnumber'"))); if (!$q) { print("<center>Security Question is incorrect!"); die(); } $an = mysql_fetch_array(mysql_query(sprintf("SELECT * FROM account WHERE name='$accountid' AND phone='$phone'"))); if (!$an) { print("<center>Answer is incorrect!"); die(); } $ac = mysql_fetch_array(mysql_query(sprintf("SELECT * FROM account WHERE name='$accountid'"))); mysql_select_db($gamedb); $temp["query"] = sprintf("UPDATE cq_user SET lock_key='0' WHERE account_id='$selectedid'"); if (!mysql_query($temp["query"])) { die(mysql_error()); } else { print("<center>You bank pin has been removed!"); } Any ideas what is wrong with it? Hi everyone, first thanks for caring to read my post! I am very very new to php but have a really good idea for a site so thought this could be a good chance to finally learn. The site is basically going to be a simple yet very well structured and organised repository for articles with the ability for users to post comments at the bottom of each article (logged in users). The users can also post articles and select which sections they want to put them in. The admin could then review all submissions and accept and then put them in the order in which they best fit (since the articles will usually be relevant to different stages and should be placed in order of assumed knowledge, if that makes sense) Kind of like a tutorials site with content being submitted. I imagine a really uncluttered site that looks more old school than web 2.0. From the first page is just like a simple search engine and underneath a kind of sitemap with each topic showing how many articles are in each. Then as you click into the topic area you are shown another sitemap like display of the articles in this which are perhaps some sectioning to define the type of article it is. As I say, I am quite new so I wondered if you had some suggestions of the top 'aids' to achieving this, and how you would suggest I progress to get it all setup? Or indeed any frameworks already that fit my needs? I hope to be active here and look forward to being to give something back some day. Edit: after reading this through,, I realise I just described a kind of wiki, but thats not really what I had in mind- more just how the old school basic but very clean and functional sites were back in the day (meaning no disrespect to any of the newer ones!). Thank you for reading. Is it possible to feed the browser a default save as name for the image when outputting to the browser, instead of it defaulting to the .php file name? So, instead of myimage.php I could use imagename.jpg or whatever I want. Hi all, I need some help. My ob_get_contents() is empty and gives me a empty file everytime. I tried different cache script it is still the same. I have also tried fwrite($fp, 'hello') In this case, it successfully writes to the file. But when i use ob_start and ob_get_contents, it will be empty. can anyone please advice. My simplified script is here <?php // Settings $cachedir = 'cache/'; // Directory to cache files in (keep outside web root) $cachetime = 600; // Seconds to cache files for $cacheext = 'html'; // Extension to give cached files (usually cache, htm, txt) // Ignore List $ignore_list = array( '/rss.php', '/search/' ); // Script $page = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; // Requested page $cachefile = $cachedir . md5($page) . '.' . $cacheext; // Cache file to either load or create $ignore_page = false; for ($i = 0; $i < count($ignore_list); $i++) { $ignore_page = (strpos($page, $ignore_list[$i]) !== false) ? true : $ignore_page; } $cachefile_created = ((@file_exists($cachefile)) and ($ignore_page === false)) ? @filemtime($cachefile) : 0; @clearstatcache(); // Show file from cache if still valid if (time() - $cachetime < $cachefile_created) { //ob_start('ob_gzhandler'); @readfile($cachefile); //ob_end_flush(); exit(); } // If we're still here, we need to generate a cache file ob_start(); ?> All My HTML AND PHP CODES TO RUN THE SITE <?php // Now the script has run, generate a new cache file $fp = @fopen($cachefile, 'w'); // save the contents of output buffer to the file @fwrite($fp, ob_get_contents()); @fclose($fp); ob_end_flush(); ?> Awhile ago I wrote a simple form to except image specific uploads from users and chmoded the directory to 777... worked great... Till there was a hack and then I found that chmod 777 is bad So changed the folder to 775, but now the upload script won't work. Can somebody point me to a post or article on how to give a file ownership or group permissions so it can safely run its uploads to the folder? I have tried google but keep getting Linux and Window OS results.. its a tough question to google. Any help is very much appreciated. is this a good way of doing a simple admin different rights e.g if secret word then go to adminpage.php Code: [Select] session_start(); $captcha = $_POST["captcha"] ; $secretword = $_SESSION["secretword"] ; if (strcmp( $captcha, $secretword )) { // it's a bot } else { // matched -- it's a human } Please take a look at the following code (this would work if the statement was SELECT instead of UPDATE) But I need to grab the following: Code: [Select] $result = mysql_query("UPDATE `AUCTIONS_MAIN` SET Current_Price = Current_Price + '$increase_price', Last_Bidder_Time = '$last_bidder_time' WHERE PId = '$id'"); //grab the new updated current price to save on different bidding history DB while($row=mysql_fetch_array($result)) { $current_price = $row['Current_Price']; } As you can see, I need to give the new Current_Price value to the $current_price variable. Obviously the while function is incorrect, I would really appreciate any ideas and/or suggestions on how I can grab this value. PS: I can't make a new query call with a select statement in order to know the new Current_Price. I need the direct updated value coming from the Update Statement, is this possible? Thanks a lot in advance!! Hi, sorry for a noob question, but I'm having problem with this small code that doesn't work. I have secret image path written in php file which must be given to HTML parameter. After this I want to make PHP send file of mime type "audio/mpeg3". The thing is to hide actual file paths. Every code is as simple as it can get hopefully. I run these files locally with Firefox and they are located in the same folder: phptest.html, phptest.php, car.jpg. I have HTML file: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> </head> <body> <p>Image given by .php file:</p> <img src="phptest.php?id=1"> </body> </html> It's really simple, just look at body tag. The whole phptest.php file: <?php $path=''; if ($_GET["id"] === "1"){ //More "if" statements planned $path = 'car.jpg'; } header('Content-Type: image/jpeg'); //Don't need too much headers? readfile($path); exit(); ?> PHP is supposed to read file with "id" paramenter. But Somehow this doesn't work. i want the code for review approval platform (costumer reviews for a product )and in backend editing the code and updating it I'm using the following code. I have tried placing parenthesis around $date1 and $date2 to separate them. No matter where I place the parenthesis Dreamweaver keeps giving me a syntax error. If I remove the second operator $date2 with the && the error goes. checked all my books but I can't see what is probably a stupid error ! Code: [Select] if ($row_sales_shipping_tax['cdate'] >= $date1 && <=$date2 ) Thanks for the help ! Being fresh to PHP I installed PHPMailer (Not sure how to install classes so what I did is I dropped the PHPMailer files into my PEAR folder since that's where all my extensions are being sent to in XAMPP). Then I ran a basic script to send email via PHPMailer using the functions offered by PHPMailer instead of Mail() (of course) but when I do that and execute my code by going to localhost my Firefox will just display my PHP code right back at me. Hi friends i have latest rss news feed im my php site, i would like to share latest 5 rss feed so some of our partners can publish in thier site . How to do it ? I want to create an application for sending mails using PHPMailer by placing it on my website server (using SMTP), but I can not get object of class phpmailer to change its properties of: to_name to_email ContentType from default (i.e. null). Why are the properties keeping default values from the PHPMailer class, and not accepting my once, though I check values i get from DB and they are good. ContentType is set in a config file. Here is part of var_dump ($mailer); object of my extended class: object(MyMailer)#2 (56) { ["priority"]=> int(3) ["to_name"]=> NULL ["to_email"]=> NULL ... ["ContentType"]=> string(10) "text/plain"... also I get value of ["Port"]=> int(26) but ["SMTP_PORT"]=> int(25). I need to use smtp port 26. And here is the extended class of phpmailer require_once './PHPMailer/class.phpmailer.php'; require_once 'mailer-config.php'; class MyMailer extends PHPMailer { var $priority = 3; var $to_name = null; var $to_email = null; var $From = null; var $FromName = null; var $Sender = null; var $ContentType = null; function MyMailer() { global $eSlanje; // Comes from mailer-config.php $eSlanje array if($eSlanje['smtp_mode'] == 'enabled') { $this->Host = $eSlanje['smtp_host']; $this->Port = $eSlanje['smtp_port']; if($eSlanje['smtp_username'] != '') { $this->SMTPAuth = true; $this->Username = $eSlanje['smtp_username']; $this->Password = $eSlanje['smtp_password']; } $this->Mailer = "smtp"; } if(!$this->From) { $this->From = $eSlanje['from_email']; } if(!$this->FromName) { $this->FromName = $eSlanje['from_name']; } if(!$this->Sender) { $this->Sender = $eSlanje['from_email']; } $this->Priority = $this->priority; //echo "<br>eSlanje[content_type]"; //var_dump ($eSlanje['content_type']); $this->ContentType = $eSlanje['content_type']; } } and here is the cofig file: mailer-config.php <?php $eSlanje['from_email'] = "hi@mysite.com"; $eSlanje['from_name'] = "Joe Blog"; $eSlanje['title'] = "hi there"; $eSlanje['content_type'] ="text/html"; $eSlanje['smtp_username'] = null; $eSlanje['smtp_mode'] = "enabled"; $eSlanje['smtp_port'] = 26; $eSlanje['smtp_host'] = "mail.mysite.com"; Here is where I insert values of email and name into the object: <?php session_start(); include ("password.php"); require_once 'class_lib/MyMailer.php'; require "class_lib/MySQL_Database.php"; require "get_email_template.php"; $db = new MySQL_Database (); $id = isset($_GET['id']) ? $_GET['id'] : false; $sql = "select email,ime from ".TABLE." where id = $id"; $query = mysql_query ($sql); $toClient = mysql_fetch_array($query); $to = isset($toClient['email']) ? $toClient['email'] : false; var_dump($to); // here I get a valid email address $to_name = isset($toClient['ime']) ? $toClient['ime'] : false; //var_dump($to_name); // here I get a valid preson's name $mailer = new MyMailer(); $mailer->AddAddress($to, $to_name); $mailer->Body = get_htmlBody(); $mailer->AltBody = get_txtBody(); if(!$mailer->Send()) { echo "<br> Mailer Error: " . $mailer->ErrorInfo." "; } else { echo "<br>message not sent  "; } $mailer->ClearAddresses(); var_dump($mailer); // this is where the object trace comes from ?> |