PHP - Help Cleaning Up This Simple Script...
The attached script does everything I want it to do, but it's not very elegant. I could use some help cleaning it up. Any and all help is greatly appreciated.
Thanks!!! Similar TutorialsHello, im very green to php and I am having trouble creating a simple log in script. Not sure why this is not working, maybe a mysql_query mistake? I am not receiving any errors but nothing gets updated in the members table and my error message to the user displays. any help is appreciated! here is my php: <?php session_start(); $errorMsg = ''; $email = ''; $pass = ''; if (isset($_POST['email'])) { $email = ($_POST['email']); $pass = ($_POST['password']); $email = stripslashes($email); $pass = stripslashes($pass); $email = strip_tags($email); $pass = strip_tags($pass); if ((!$email) || (!$pass)) { $errorMsg = '<font color="#FF0000">Please fill in both fields</font>'; }else { include 'scripts/connect_db.php'; $email = mysql_real_escape_string ($email); $pass = md5($pass); $sql = mysql_query("SELECT * FROM members WHERE email='$email' AND password='$pass'"); $log_check = mysql_num_rows($sql); if ($log_check > 0) { while($row = mysql_fetch_array($sql)) { $id = $row["id"]; $_SESSION['id']; $email = $row["email"]; $_SESSION['email']; $username = $row["username"]; $_session['username']; mysql_query("UPDATE members SET last_logged=now() WHERE id='$id' LIMIT 1"); }//Close while loop echo "You are logged in"; exit(); } else { $errorMsg = '<font color="#FF0000">Incorrect login data, please try again</font>'; } } } ?> and the form: <?php echo $errorMsg; ?> <form action="log_in.php" method="post"> Email:<br /> <input name="email" type="text" /><br /><br /> Password:<br /> <input name="password" type="password" /><br /><br /> <input name="myBtn" type="submit" value="Log In" /> </form> Hi can someone pls help, im tryin a tutorial but keep getting errors, this is the first one i get after registering. You Are Registered And Can Now Login Warning: Cannot modify header information - headers already sent by (output started at /home/aretheyh/public_html/nealeweb.com/regcheck.php:43) in /home/aretheyh/public_html/nealeweb.com/regcheck.php on line 46 I'm trying to clean up my code as best I know how and get rid of code that isn't necessary. This is where I'm most confused: On every page, I start a session and if someone goes to a page other than the index/login page, they are redirected if there is no session, otherwise, they are allowed to continue to view the page content. Here is my code: Code: [Select] <?php session_start(); $email=$_SESSION['email']; // is this line necessary on every page... if ($_SESSION['logged'] != 1) { $_SESSION['email'] = $email; // as well as this line? header("Location: index.php"); exit(); } ?> Basically, I need to know if the SESSION['email'] has to be set on every page, or does it stay set as long is the session is logged? If it stays set for the entire session, I shouldn't need to include the "$email=$_SESSION['email'];" line on every page, right? Also, if my thinking is correct, I shouldn't need to include the "$_SESSION['email'] = $email;" line unless I need to use the $email variable for some other purpose. Am I correct on this? Thanks for any input. basically this is like 60% written by me with a few copy/paste. What I am looking to do, is clean up this code a little. Functionally it does what I want it to relatively well, but it does look very very messy and I would like it to be a little more tidy. Any suggestions on how to do this? I am no PHP expert as you can most likely tell by the code itself. <?php require("cfg.php"); //FOLDER PATH $dir_cat= $imgpath; $openDir_cat = opendir($dir_cat); while (false !== ($fileNames_cat = readdir($openDir_cat))) { $check_cat = $dir_cat. "/" . $fileNames_cat; $size_cat = @getimagesize($check_cat); // this check mime of file if($fileNames == "." || $fileNames_cat == ".." || strpos($size_cat[mime], "image") === FALSE) { continue; // exclude everything wha is not image } else { $imagesAll_cat[] = $fileNames_cat; // create an array of images } } $imgnr_cat=0; $imgct_cat=count(glob($dir_cat . "*")); //COUNT THE NUMBER OF FILES IN THE UPLOAD DIR. echo '<center><fieldset class=fieldset>'; echo '<legend> IMGS '; echo ' (' .$imgct_cat. ' IMAGES)</legend><div>'; //GET IMAGES AND DISPLAY THEM while ($imgnr_cat<$imgct_cat){ echo '<a href=' .$dir_cat.$imagesAll_cat[$imgnr_cat]. '>'; echo '<img width=140 height=100 src=' .$dir_cat.$imagesAll_cat[$imgnr_cat]. '>'; echo '</a>'; $imgnr_cat++; } echo '</div></fieldset></center>'; ?> I need to pull a list of mp3 file names to create a playlist. I have a column for "priority" which will handle the rotation of the mp3's...so that a priority of 4 will play more often than a priority of 3...and so on. I have this code (which works) to select a column from the db that matches the selected criteria...AND has a priority of "4". If there are no matches, select a row that has a priority of "3". How can I clean up this code...preferably to remove the need for adding 2's after each variable? Also, is there a better way of handling this, so that it's ONE select...and then puts the mp3's in the playlist the correct number of times? Code: [Select] <?php $sql = "SELECT * FROM audio WHERE `client_id` = '$client' AND (`start_date` <= '$nownohour' AND `end_date` >= '$nownohour') AND `$dow` = '1' AND `is_active` = '1' AND (`start_hour` <= '$hournozero' AND `end_hour` >= '$hournozero') AND `priority` = '4' LIMIT 1"; $rs = mysql_query($sql,$dbc); $matches = 0; while ($row = mysql_fetch_assoc($rs)) { $matches++; echo "$row[title].mp3<br />"; } if (!$matches) { $sql2 = "SELECT * FROM audio WHERE `client_id` = '$client' AND (`start_date` <= '$now' AND `end_date` >= '$now') AND `$dow` = '1' AND `is_active` = '1' AND (`start_hour` <= '$hournozero' AND `end_hour` >= '$hournozero') AND `priority` = '3' LIMIT 1"; $rs2 = mysql_query($sql2,$dbc); $matches2 = 0; while ($row2 = mysql_fetch_assoc($rs2)) { $matches2++; echo "$row2[title].mp3<br />"; } } echo "-------------<br />"; ?> Thanks! Ok, i have this code that i want to print out the total number of times the defined username appears in my database with the defined date. Right now all it prints out is the echo at the end but with no numbers in the result. I just need help with getting it to display the number. Code: [Select] <?php //select a database to work with $selected = mysql_select_db("nwacompu_totals",$dbhandle) or die("Could not select examples"); $username = "bayyari"; $date = "3-16-2011"; $query = "SELECT COUNT(*) FROM totals WHERE date = '$date' AND username = '$username'"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo "There are ". $row['COUNT(username)'] ." ". $row['date'] ." items."; echo "<br />"; echo $result; } ?> what is printed is this There are items. Resource id #2Resource id #3 which makes no sense to me. Any help is very much appreciated. Hi there I allow users to make new albums. For each album they give a full display name, eg "New Years Eve 2012 at Persons' place", and a shorter display eg "New Years Eve 2012". The first string should be stored in a db and should be shown exactly as it is, so for that string I have: Code: [Select] <?php //$fullname gets stored in the db $fullname = myql_real_escape_string(htmlentities($fullname)); //when pulled from the db, it is only echoed, nothing else: echo $fullname; ?> Now I presume it is safe so far. Now is the 'tricky' part. Currently this is what I do to the short name: Code: [Select] <?php //$shortname gets stored in the database $shortname = mysql_real_escape_string(urlncode(str_replace(' ','',strtolower($shortname)))); ?> Now from this shortname, before the mysql_real_escape_string(), it makes a directory with that name. Now what happens is, if there are special charcters like '@', the '@' changes into '%40'. So the directory would be eg 'fun%40myplace'. The directories get made without a problem, but for some reason my uploader won't upload to this directory. It isn't the uploaders fault because in folders without these special characters there is no problem with uploading. Any ideas on how to fix this, or what the best method is to clean a string for url/directory names? Hi, This isn't so much a problem as my code/page works however my host shut down scripting on the site as too many connections to the database were left open apparently with this page. Also ive been looking into a way of cleaning up the code and making it less bloated but the only thing I have found is mysqli for running multiple queries in one go but I am unsure if this would help. Code: [Select] <?php session_start(); include("./includes/db_con.inc.php"); $image = $_GET["id"]; $id = str_replace("-", "/", $_GET["id"]); $cat = $_GET["cat"]; $sub_cat = $_GET["sub"]; $page_title = $cat . " - " . $sub_cat . " - " . $id; $sql_meta = mysql_query("SELECT * FROM english WHERE PRODID='$id' AND display='1'"); $row_meta = mysql_fetch_assoc($sql_meta); $meta_desc = $row_meta['META_DESC']; $meta_key = $row_meta['META_KEY']; include("./includes/head.php"); include("./includes/header.php"); ?> <div id="main-page-header"> <?php $header = "img/product-pages/product-specific-headers/" . $image . ".jpg"; if (file_exists($header)) { ?> <img src="<?php echo $img_loc; ?>/product-pages/product-specific-headers/<?php echo $image; ?>.jpg" width="940" height="310" /> <?php } else { $desc_sql = mysql_query("SELECT * FROM sub_cat WHERE name='$sub_cat'"); $row_desc = mysql_fetch_assoc($desc_sql); $description = $row_desc['description']; echo "<img src='$img_loc/product-pages/sub-cat-head/".str_replace(" ", "-", $row_desc['name'])."-sub-cat-head.jpg' width='940' height='310' />"; } ?> </div> <div id="page-content"> <div id="main-page-text"> <h1><?php $result = mysql_query("SELECT * FROM $table WHERE PRODID='$id' AND display='1'"); while($row = mysql_fetch_array($result)) { $prod_title = $row['PROD_TITLE']; echo $prod_title; ?> </h1> <h2 class="crumbs"><a href="<?php echo "$url/Products/$lang/"; ?>">Products</a> > <a href="<?php echo "$url/Category/$lang/".urlencode($cat)."/"; ?>"><?php echo $cat; ?></a> > <a href="<?php echo "$url/Range/$lang/".urlencode($cat)."/".urlencode($sub_cat)."/"; ?>"><?php echo $sub_cat; ?></a> > <?php echo $prod_title; ?> </h2> <p><?php echo $row['DESCRIPTION']; } ?></p> <script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like layout="button_count" show_faces="false" width="170" font="verdana"></fb:like> <br /> <?php $i = 1; while ($i <= 8) { $filename = "img/product-pages/hovers-800px/" . $image . "-" . $i . ".jpg"; if (file_exists($filename)) { ?> <a class="fuglybox" rel="gxr" href="<?php echo "../../../../../" . $filename; ?>"> <img src="../../../../../img/product-pages/product-detail-90px/<?php echo $image . "-" . $i . ".jpg"; ?>" alt="" width="90" height="90" /></a> <?php } else { break; } $i++; } ?> <table> <th>Product Code</th> <th>Description</th> <?php $table_result = mysql_query("SELECT * FROM PRODID WHERE PRODID='$id'"); $table_entry = mysql_fetch_assoc($table_result); echo "<tr><td class='prod-id'>" . $table_entry['PROD_CODE'] . "</td>\n"; echo "<td class='prod-desc'>" . $table_entry['TA_DESC'] . "</td></tr>\n"; ?> </table> <div id="FAQ-wrap"><h2>Frequently Asked Questions</h2> <?php $QA_table = $lang . "_qanda"; if ($id=="") { $list_QA = mysql_query("SELECT * FROM $QA_table WHERE SUB_CATEGORY='$sub_cat' AND DISPLAY='1'"); } else { $list_QA = mysql_query("SELECT * FROM $QA_table WHERE PRODID='$id' AND DISPLAY='1'"); } while($row_QA = mysql_fetch_array($list_QA)) { echo "<div id='FAQ-QA'>"; echo "<h2 class='FAQ-question'>Q: ".$row_QA['QUESTION']."</h2>"; echo "<p class='FAQ-question'>A: ".$row_QA['ANSWER']."</p></div>"; } ?> <div id="FAQ-question"> <h2 class="white">Got a question about the <span class="got-question-product"><?php echo $sub_cat; ?></span> </h2> </div> </div> </div> <div id="totem-menu-container"><?php include("./includes/search.php") ?> <?php include("./includes/totem.php") ?> </div> </div> </div> <?php include("./footer.php") ?> Please note in the db_con.inc.php is the connection to the database stored in variable $con and included in the footer.php is mysql_close($con) which is also why I dont understand how connections are being left open, any help greatly appreciated. I am cleaning up my website (replace tables with divs and turning all design code in to CSS). I would like to know a couple things. First, I see that register_globals is deprecated, but I still see new blog posts and such saying to keep it. I want to know if I should remove it, how it works, and if I do remove it what should I replace it with. Also, I have code like: Code: [Select] '".$SETTINGS['siteurl']."uploaded/".$val["pict_url"]."' and I was wondering whether it can be replaced with Javascript. Please don't call me a noob or tell me to Google it because when it comes to me, Google, and PHP; I'm like a kid in a candy shop and all the candy is filled with dirt. I have been trying to hack two parts of code together... I had code writen that will grab the text from a website and completely clean it of all junk except for full words... then echo it. Now I am trying to use the same script to pull from a database instead of a URL but am lost... Here is my code... I would make another donation to the site if we can get this going... THANK YOU! Code: [Select] <?php $con = mysql_connect("localhost","USERNAME","PASSWORD!"); mysql_select_db("DATABASE",$con); $get = "SELECT * FROM information_description WHERE information_id=4"; $SQ_query = mysql_query($get) or die("Query failed: $get\n" . mysql_error()); $fetch = mysql_fetch_array($SQ_query); $raw = $fetch['description']; /* Set internal character encoding to UTF-8 */ mb_internal_encoding("UTF-8"); mb_http_output( "UTF-8" ); ob_start("mb_output_handler"); function clean($html) { ###Remove number in html################ //$html = preg_replace("/[0-9]/", " ", $html); $html = preg_replace("/<([a-z][a-z0-9]*)[^>]*?(\/?)>/i",'<$1$2>', $html); // $html = preg_replace('/(<[^>]+) style=".*?"/i', '$1', $html); echo $html; $html = str_replace(" ", " ", $html); $html = str_replace("&", " ", $html); $html = str_replace("-", " ", $html); ######remove space $html = preg_replace ('/<[^>]*>/', '', $html); $html = preg_replace('/\s\s+/', ', ', $html); $html = preg_replace('/[\s\W]+/',' ',$html); // Strip off spaces and non-alpha-numeric return $html; } #call function //$raw = StripHtmlTags($raw); $raw = clean($raw); echo $raw; ##echo clean($html); $url = (isset($_GET['url']) ?$_GET['url'] : 0); $str = file_get_contents($url); ####################################################################3 function get_url_contents($url){ $crl = curl_init(); $timeout = 5; curl_setopt ($crl, CURLOPT_URL,$url); curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); $ret = curl_exec($crl); curl_close($crl); return $ret; } #--------------------------------------Strip html tag---------------------------------------------------- function StripHtmlTags( $text ) { // PHP's strip_tags() function will remove tags, but it // doesn't remove scripts, styles, and other unwanted // invisible text between tags. Also, as a prelude to // tokenizing the text, we need to insure that when // block-level tags (such as <p> or <div>) are removed, // neighboring words aren't joined. $text = preg_replace( array( // Remove invisible content '@<head[^>]*?>.*?</head>@siu', '@<style[^>]*?>.*?</style>@siu', '@<script[^>]*?.*?</script>@siu', '@<object[^>]*?.*?</object>@siu', '@<embed[^>]*?.*?</embed>@siu', '@<applet[^>]*?.*?</applet>@siu', '@<noframes[^>]*?.*?</noframes>@siu', '@<noscript[^>]*?.*?</noscript>@siu', '@<noembed[^>]*?.*?</noembed>@siu', // Add line breaks before & after blocks '@<((br)|(hr))@iu', '@</?((address)|(blockquote)|(center)|(del))@iu', '@</?((div)|(h[1-9])|(ins)|(isindex)|(p)|(pre))@iu', '@</?((dir)|(dl)|(dt)|(dd)|(li)|(menu)|(ol)|(ul))@iu', '@</?((table)|(th)|(td)|(caption))@iu', '@</?((form)|(button)|(fieldset)|(legend)|(input))@iu', '@</?((label)|(select)|(optgroup)|(option)|(textarea))@iu', '@</?((frameset)|(frame)|(iframe))@iu', ), array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0",),$text ); // Remove all remaining tags and comments and return. return strtolower( $text ); } function RemoveComments( & $string ) { $string = preg_replace("%(#|;|(//)).*%","",$string); $string = preg_replace("%/\*(?:(?!\*/).)*\*/%s","",$string); // google for negative lookahead return $string; } $html = StripHtmlTags($str); ###Remove number in html################ $html = preg_replace("/[0-9]/", " ", $html); #replace by ' ' $html = str_replace(" ", " ", $html); ######remove any words################ $remove_word = file("swords.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); foreach($remove_word as $word) { $html = preg_replace("/\b". $word ."\b/", " ", $html); } ######remove space $html = preg_replace ('/<[^>]*>/', '', $html); $html = preg_replace('/\b\s+/', ', ', $html); $html = preg_replace('/[\b\W]+/',', ',$html); // Strip off spaces and non-alpha-numeric #remove white space, Keep : . ( ) : & //$html = preg_replace('/\s+/', ', ', $html); ###process######################################################################### $array_loop = explode(",", $html); $array_loop1 = $array_loop; $arr_tem = array(); foreach($array_loop as $key=>$val) { if(in_array($val, $array_loop1)) { if(!$arr_tem[$val]) $arr_tem[$val] = 0; $arr_tem[$val] += 1; if ( ($k = array_search($val, $array_loop1) ) !== false ) unset($array_loop1[$k]); } } arsort($arr_tem); ###echo top 20 words############################################################ echo "<h3>Top 20 words used most</h3>"; $i = 1; foreach($arr_tem as $key=>$val) { if($i<=20) { echo $i.": ".$key." (".$val." words)<br />"; $i++; }else break; } echo "<hr />"; ###print array##################################################################### echo (implode(", ", array_keys($arr_tem))); ?> Just want to finalize what the best options/functions are when cleaning user supplied input in the following 3 situations: 1. Inserting data into a database 2. Sending data to an email (and displaying it as HTML) 3. Displaying data back to screen Hi. I've been banging my head against the wall with this stupid problem and I just figured out the problem.
I scrape data from a website. I query my table to see if I already have everything in there. If no match is found, I insert it.
Today, I noticed even after inserting, my script kept telling me there's a new entry I need to insert, despite it actually being there when I physically check the table.
But when I echo the query out and run it in phpmyadmin, it finds the row. But not if I run the query directly in my script.
Turns out, there are several invisible characters in my string. When I do var_dump(), it says length is 25. When I copy and paste the string into notepad, then back into a fresh php script and wrap it in quotes and echo out a strlen(), I get 21. There are apparently 4 invisible characters that I can't see. I trim() everything, so that apparently didn't catch it.
So... is there a good way to "clean" my data before inserting or comparing it to avoid this in the future? This wasted a ton of time and I hope to find a way to clean this junk out of my data.
Thanks! It just seems like I run into this sort of thing often when it's data scraped from the web. (breaks my regex! grr!)
<html> <head></head> <body> My favourite bands a <ul> <?php // define arrays $morebands = array('Desturbed', 'Anthrax'); $artists = array('Metallica', 'Evanescence', 'Linkin Park', 'Guns n Roses', "$morebands"); // loop over it // print array elements foreach ($artists as $a) { if ($a != 'Array'){ echo '<li>'.$a; } Else { foreach ("${$a}" as $b){ echo '<li>'.$b; } } } ?> </ul> </body> </html> I can not figure out why this will not work:( I would like the foreach to run through the array as normal, but if it encounters a nested array, loop it as well. I know this likely is not the right, or best way to do this, but I am just learning PHP through a tutorial and I learn best by doing... So I take the lessons, make them more complicated, then figure out how to make it happen (like so). right now I am working on http://devzone.zend.com/node/view/id/635 anyhow thanks for any help! I was told that you guys could probably help me with this, so heres my situation. I use this program called Activeworlds, and me and my buddies are makeing a "tv show" if you will within the program. To do so, you take screenshots, save the screenshots, and add the image files into a directory on your domain. You need a .php script to present them as a slideshow. Now the problem is, ive searched for scripts already made from other sites, but the thing is, they are all fancy slideshow viewers, meaning they come with control buttons to cycle through the pictures and all kinds of other banners and flashy looking things. The only script im needing, is a simple script that will display and cycle through the raw images, and nothing else, within the web browser, in a slideshow format. Id also like to have a value I can edit that will change how fast the pictures cycle through, 15 seconds or so would be perfect however. If someone could refer me to this code or even make it for me, it would be soo appreciated. I know im probably asking for alot, but it would help me soo much. I wish I knew a little more about .php files to do it myself, or else I would. If you do link me to a script, please give me simple instructions on what to do with it lol because like I said, I dont know anything about the world of .php yet. Thank you all for your time. Hi all, Im coding a simple script for my website which just changes the users rank. Code: [Select] <?php session_start(); include "../includes/db_connect.php"; include "../includes/functions.php"; logincheck(); ini_set ('display_errors', 1); error_reporting (E_ALL); $username=$_SESSION['username']; $get = mysql_query ("SELECT * FROM users WHERE username = '$username'"); $fetch = mysql_fetch_object($get); if ($fetch->userlevel >= "2"){ $newrank = $_POST['newrank']; $user1 = $_POST['user']; if (strip_tags($_POST['update'])){ mysql_query("UPDATE users SET `rank` = '$newrank' WHERE username='$user1'") or die (mysql_error()); echo ("You have updated $user1's rank to $newrank !"); } } else{ echo ("Your userlevel isnt high enouth to be here!"); } ?> <html> <head> <title>Change Rank</title> <link rel="stylesheet" href="../includes/in.css" type="text/css"> <style type="text/css"> .infobg { font-family: Arial; font-weight:normal; font-size:12px; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; background: URL(textbg1.png); font-weight:300; } .button { font-size: 12px; background:url(button.png); vertical-align: middle; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; color: #FFFFCC; height:23px; font-weight:300; border-radius: 10px; padding-bottom:2px; } </style> </head> <body> <form action='' method='post' name='form1'> <table width='30%' cellpadding='0' align='center' cellspacing='0' border='1' bordercolor='#000000' bgcolor='#808080' style='border-collapse: collapse'> <tr> <td background='../header.jpg' colspan='2' align='center'>Change Rank</td> <tr> <td>Username:</td><td><input type='text' name='user'></td> </tr> <tr> <td>Rank:</td><td><input type='text' name='newrank'></td> </tr> <tr> <td> </td><td><input type="submit" name="update" value="Update Rank"></td> </tr> </form> </table> </body> </html> But there seems to be something wrong with that code, which I carnt see or work out. When I click Update submit button it does nothing, but can anyone see why it does nothing? Thanks. Good evening guys and gals, for some reason I cant get my head around something quite simple, basically I am trying to work out a way of simply recording referrals to my site when the potential user registers. This worded example is basically what I want: registered user a with a username of smithy invites his friend western to become a member of a site he has joined: I guess here I would basically use something like mysite.com?refid=smithy as the link he gives he's friend Now this is where my brain refuses to work, what if western decides to have a look around the site before he decides to register and clicks on a few internal pages? Obviously the referral id will no longer be in the address bar. So my 1st question is, how can I check to see if a referral is used when accessing the site? I could then store the username in a session or cookie. If I had something like this: <?php $refid = $_GET('refid') setcookie("user", $refid, time()+3600); ?> But how would I check that a refid exists in the url so it doesnt throw up a parse error? I have more questions but 1 thing at a time! Many Thanks There is a sql query happening if the item is not empty, what I NEED and can not seem to figure out is to re run the rand() function. The server is PHP 4 so it is not possible to use the goto statement... That would be to easy. So any help would be great... Here is the code... the script running after the script finds a empty sql row is ot included... it works... just this one part does not. Code: [Select] <?php $connection = mysql_connect(CREDENTIALS REMOVED) or die(mysql_error()); mysql_select_db("testingblock", $connection)or die(mysql_error()); $random_num = rand(1,10); if($random_num == 1){ $query = sprintf("SELECT email FROM access_codes WHERE id='1'", mysql_real_escape_string($email)); $result = mysql_query($query); $row = mysql_fetch_assoc($result); if(!empty($row['email'])){ header('Location: http://www.thestreetbeatint.com/Testing/blah.php'); } else { echo $recipient; } } else if ($random_num == 2){ $query = sprintf("SELECT email FROM access_codes WHERE id='2'", mysql_real_escape_string($email)); $result = mysql_query($query); $row = mysql_fetch_assoc($result); if(!empty($row['email'])){ header('Location: http://www.thestreetbeatint.com/Testing/blah.php'); } else { echo $recipient; } } else if ($random_num == 3){ $query = sprintf("SELECT email FROM access_codes WHERE id='3'", mysql_real_escape_string($email)); $result = mysql_query($query); $row = mysql_fetch_assoc($result); if(!empty($row['email'])){ header('Location: http://www.thestreetbeatint.com/Testing/blah.php'); } else { echo $recipient; } } else if ($random_num == 4){ $query = sprintf("SELECT email FROM access_codes WHERE id='4'", mysql_real_escape_string($email)); $result = mysql_query($query); $row = mysql_fetch_assoc($result); echo '<br />'; if(!empty($row['email'])){ header('Location: http://www.thestreetbeatint.com/Testing/blah.php'); } else { echo $recipient; } } else if ($random_num == 5){ $query = sprintf("SELECT email FROM access_codes WHERE id='5'", mysql_real_escape_string($email)); $result = mysql_query($query); $row = mysql_fetch_assoc($result); if(!empty($row['email'])){ header('Location: http://www.thestreetbeatint.com/Testing/blah.php'); } else { echo $recipient; } } else if ($random_num == 6){ $query = sprintf("SELECT email FROM access_codes WHERE id='6'", mysql_real_escape_string($email)); $result = mysql_query($query); $row = mysql_fetch_assoc($result); if(!empty($row['email'])){ header('Location: http://www.thestreetbeatint.com/Testing/blah.php'); } else { echo $recipient; } } else if($random_num == 7){ $query = sprintf("SELECT email FROM access_codes WHERE id='7'", mysql_real_escape_string($email)); $result = mysql_query($query); $row = mysql_fetch_assoc($result); if(!empty($row['email'])){ header('Location: http://www.thestreetbeatint.com/Testing/blah.php'); } else { echo $recipient; } } else if ($random_num == 8){ $query = sprintf("SELECT email FROM access_codes WHERE id='8'", mysql_real_escape_string($email)); $result = mysql_query($query); $row = mysql_fetch_assoc($result); if(!empty($row['email'])){ header('Location: http://www.thestreetbeatint.com/Testing/blah.php'); } else { echo $recipient; } } else if ($random_num == 9){ $query = sprintf("SELECT email FROM access_codes WHERE id='9'", mysql_real_escape_string($email)); $result = mysql_query($query); $row = mysql_fetch_assoc($result); echo '<br />'; if(!empty($row['email'])){ header('Location: http://www.thestreetbeatint.com/Testing/blah.php'); } else { echo $recipient; } } else if ($random_num == 10){ $query = sprintf("SELECT email FROM access_codes WHERE id='10'", mysql_real_escape_string($email)); $result = mysql_query($query); $row = mysql_fetch_assoc($result); if(!empty($row['email'])){ header('Location: http://www.thestreetbeatint.com/Testing/blah.php'); } else { echo $recipient; } } ?> [icode] Can someone show me a simple mail script that I can run in cli, I can enter a $to = email@email.com and then have it send to my email? just in cli.. Thanks I'm very new to PhP and one of my asignments in class is to create a simple login using php and mysql. I made a simple page using html, php, and mysql and i keep getting errors. Here is my code so far: This is my index.php page: <html> <form action = 'login.php' method='POST'> Username: <input type='text' name='username'><br> Password: <input type='password' name='password'><br> <input type='submit' value='Log in'> </form> </html> This is my login.php page: <?php $username = $_POST['username']; $password = $_POST['password']; if ($username&&$password) { &connect = mysql_connect("localhost", "root", " ") or die ("Couldnt connect"); mysql_selct_db("phplogin") or die("Couldn't find db"); } else die ("Please enter a username and password"); ?> mySql file is very basic: 3 columns, id, username, password I dont think my problem is with the mySQL page that was the easiest to make but everytime I hit login in the index.php, the entire script for login.php gets outputted on screen. I would appreciate all the help. |