PHP - Checking For Undefined Variables
Hi.
I'm still very new to this forum, so i may be asking this the wrong way. I'm working on a project, but i keep running into the same wall. Whenever i try to load a page with a variable i named on another page, i get an error telling me that it does not know that variable. But how do i make it check for the variable before using it? Example of my code (i only show the first part, as it is the only one relevant): Code: [Select] <html><body> <?php session_start(); if($_SESSION['username']); { $username = $_SESSION['username']; As you can see i have tried to deal with it using an if statement, but i still get the error. I bet there is a very simple way to do this, but i cant see it right now. Similar TutorialsHello All, Attached are 2 screenshots of the form and output for better reference. What I am trying to do is select all or some checkboxes and for those boxes that are checked, echo out their Payment Method. ---If a checkbox is checked but the Payment Method box == select, give an error. ---If checkbox is checked and Payment Method != select, echo out the ID and selection from the drop down box. Currently, I am echoing the correct ID(s) when certain boxes are checked, but I'm getting every drop down box selection when the corresponding box is not selected. Any help would be greatly appreciated. This is the HTML / PHP Form: $results .= '<table align="center" width="70%" border="0" bgcolor="'.$bg.'" cellpadding="2" cellspacing="0" class="resultsUnderline">'; $results .= '<tr>'; $results .= '<td width="30%" align="left">'.'<input type="checkbox" name="checkbox[]" value="'.$app_pmt_id.'" id="checkbox" />' .$full.'<FONT size="1" color="maroon"> ( '.$app_id.' )</FONT></td>'; $results .= '<td width="30%" align="center">'.$created.'</td>'; $results .= '<td width="20%" align="center"> <select name="pay_method[]" class="drop" id="pay_method"> <option value="select">-- Method --</option> <option value="check">Check</option> <option value="credit">Credit Card</option></td>'; $results .= '<td width="10%" align="center">'.$paid.'</td>'; $results .= '<td width="10%" align="right">'.$fee.'</td>'; $results .= '</tr>'; $results .= '</table>'; Here is the PHP getting the results: if(isset($_POST['action_box']) && $_POST['action_box'] == 'mark_paid') { $checked = array(); $checked2 = array(); if(!isset($_POST['checkbox'])) { $val_error[] = 'You have not selected any applications.'; } elseif($_POST['pay_method'] == 'select') { $val_error[] = 'Please select a Payment Method.'; } else { foreach($_POST['checkbox'] as $value) { $checked[] = $value; } foreach($_POST['pay_method'] as $value2) { $checked2[] = $value2; } echo implode(",", $checked); echo implode(",", $checked2); //$result = mysql_query("UPDATE app_pmt SET paid = '1' WHERE app_pmt_id IN(" . implode(",", $checked) . ")"); //header('Location: bal_due.php?id='.$_GET['id']); } } I am trying to allow users of a web page the ability to create custom Excel exports. I have some code that I use elsewhere that works to make Excel exports. When I moved the code over to my custom report page, the Excel chart contains an error saying that $csv_output is undefined and so is $data (both variables toward the end of the page). I tried declaring the variables ($csv_output = ''; and $data = '' above the Excel code, but that didn't work. Can anybody help me out? Code below... Code: [Select] <?php //////////////////// INITIATE SESSION //////////////////// if (!isset($_SESSION)) { session_start(); } //////////////////// ALLOW ACCESS ONLY TO ADMINISTRATORS //////////////////// if ($_SESSION['person_priveleges'] == 0) { header("location:index.php"); } //////////////////// CONNECT AND SELECT DATABASE //////////////////// require_once('connect.php'); mysql_select_db($database, $connect); //////////////////// APPLY VARIABLES //////////////////// $state_search = ""; $payment_status = ""; $method_search = ""; //////////////////// GET USER SEARCH RESULTS //////////////////// if (array_key_exists('search', $_GET)) { // FILTER USER INPUT // // HERE // /////////////////////// // INITIALIZE ERROR ARRAY // $error = array(); // IF ALL INPUT FIELDS ARE LEFT BLANK THROW AN ERROR // if ((empty($_GET['state_search'])) && (empty($_GET['payment_status'])) && (empty($_GET['payment_method']))) { $error['search'] = "Please enter at least one search parameter."; // IF NO ERRORS START THE QUERY // } else { $search = "SELECT * FROM person"; // SET WHERE PART OF QUERY TO FALS SINCE WE DO NOT HAVE ANY WHERE PARAMETERS // $where = false; // IF THE PERSON SELECTS A STATE ASSIGN TO A VARIABLE AND ADD TO QUERY // if (isset($_GET['state_search']) && !empty($_GET['state_search'])) { $state_search = $_GET['state_search']; // FOR EACH STATE THAT WAS SELECTED // foreach ($state_search as $state) { // IF THERE ALREADY IS A WHERE CLAUSE ADD THE FOLLOWING CODE TO THE QUERY // if ($where) { $search .= " AND person_state = '$state'"; // IF THERE IS NO WHERE CLAUSE ADD THE FOLLOWING CODE TO THE QUERY AND SET WHERE TO TRUE SO FUTURE ADDITIONS WILL BE CORRECT // } else { $search .= " WHERE person_state = '$state'"; $where = true; } } } // IF THE PERSON SELECTS A PAYMENT STATUS ASSIGN TO A VARIABLE AND ADD TO QUERY // if (isset($_GET['payment_status']) && !empty($_GET['payment_status'])) { $payment_status = $_GET['payment_status']; foreach ($payment_status as $status) { if ($where) { $search .= " AND person_paid = '$status' "; } else { $search .= " WHERE person_paid = '$status' "; $where = true; } } } // IF THE PERSON SELECTS A PAYMENT METHOD ASSIGN TO A VARIABLE AND ADD TO QUERY // if (isset($_GET['payment_method']) && !empty($_GET['payment_method'])) { $payment_method = $_GET['payment_method']; foreach ($payment_method as $method) { if ($where) { $search .= " AND person_payment_method = '$method' "; } else { $search .= " WHERE person_payment_method = '$method' "; $where = true; } } } $search .= " AND person_priveleges = 0 ORDER BY person_last_name"; } $query_search = mysql_query($search, $connect) or die(mysql_error()); // CODE TO GENERATE EXCEL OUTPUT // // GET THE NUMBER OF FIELDS // $fields = mysql_num_fields($query_search); // FOR EACH RECORD IN THE DATABASE PRODUCE SOME OUTPUT // for ($i = 0; $i < $fields; $i++) { $csv_output .= mysql_field_name($query_search, $i) . "\t"; } while($row = mysql_fetch_row($query_search)) { foreach($row as $value) { if ((!isset($value)) OR ($value == "")) { $value = "\t"; } else { $value = str_replace('"', '""', $value); $value = '"' . $value . '"' . "\t"; } $line .= $value; } $data .= trim($line)."\n"; } $data = str_replace("\r","",$data); header("Content-Type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=Registration Report for IDUES 2011 Project Directors Meeting.xls"); header("Pragma: no-cache"); header("Expires: 0"); print $csv_output."\n".$data; exit; } ?> This is what I'm getting... Notice: Undefined variable: sitetitle in /home/vehiclep/public_html/functions.php on line 121 Notice: Undefined variable: ADcode in /home/vehiclep/public_html/functions.php on line 121 Notice: Undefined variable: email in /home/vehiclep/public_html/functions.php on line 121 Notice: Undefined variable: url in /home/vehiclep/public_html/functions.php on line 121 Notice: Undefined variable: charge in /home/vehiclep/public_html/functions.php on line 121 Notice: Undefined variable: currency in /home/vehiclep/public_html/functions.php on line 121 Notice: Undefined variable: price in /home/vehiclep/public_html/functions.php on line 121 this is functions.php Code: [Select] function sitesets() { $sql = "select * from settings limit 1"; $rs = mysql_query($sql); $row = @mysql_fetch_array($rs); extract($row); $sitesets = array("title"=>$sitetitle, "ADcode"=>$ADcode, "email" => $email, "url" => $url, "charge" => $charge, "currency" => $currency, "price" => $price); return $sitesets; } Ive tried going into phpMyadmin and creating a row and entering the info manualy but it doesnt work. I don't know much about coding so this may be a dumb question but it has me stumped. I hope somebody can tell me what I'm missing here. My form Code: [Select] <form action="process.php" method="post"> <font face= "calibri" size= "4"> <table border= "1"> <tr style= "background: #cccccc"> <td><b>Item Description:</b></td> <td><input type= "text" name= "itemDescription" size= "30" value=""/></td> </tr> <tr style= "background: #99ff00"> <td><b>Item Price:</b></td> <td><input type= "text" name= "itemPrice" size= "5" value=""/></td> </tr> </tr style= "background: #A8E5FF"> <td><b>Winning Bidders:</b></td> <td><input type="text" name= "winningBidder" size= "5" /> </td> </tr> <tr> <td><b>How many deals?:</b></td> <td><input type="text" name= "itemQty" size= "3" value= "1" /></td> </tr> </table> <br/> <input type="reset" value="Reset Form"><input type="submit" name="submit" value= "Save & Cont." " /> </form></font> My process script: Code: [Select] <?php error_reporting(E_ALL); ini_set("display_errors", 1); $host= ""; $db_name= ""; $db_user= ""; $db_password= ""; $logUser= $_POST['logUser']; $deleteBidder = $_POST['deleteBidder']; $newBidder= $_POST['newBidder']; $itemDescription= $_POST['itemDescription']; $itemPrice= $_POST['itemPrice']; $winningBidder= $_POST['winningBidder']; $itemQty= $_POST['itemQty']; ob_start(); if ($_POST['newBidder']) { $bidderId= $newBidder; mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM bidders WHERE biddersId='$bidderId'"; $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==0){ // Add $biddersId and redirect to anypage mysql_Query("INSERT INTO bidders (biddersId) VALUES ('$bidderId')"); header("Location: index.php"); exit(); } } if ($_POST['deleteBidder']) { mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB"); mysql_query("DELETE FROM bidders WHERE biddersId='$deleteBidder'"); header("Location: index.php"); exit(); } if ($_POST['itemDescription'] AND $_POST['itemPrice'] AND $_POST['winningBidder'] AND $_POST['itemQty']) { mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM transactions WHERE biddersId='$winningBidder'"; $result=mysql_query($sql); $count=mysql_num_rows($result); // If result matched, table row must be 1 row if($count==0){ echo "That Bidder Number is NOT logged in, "; echo "would you like to set this bidder as active?"; echo " Enter 1 for NO or 2 for YES"; echo "<form action= \"process.php\" method= \"POST\">"; echo "<input type =\"text\" name= \"logUser\"/>"; echo "<input type= \"submit\" value = \"Submit\"/>"; $logUser= $_POST['logUser']; exit(); } if ($logUser= 1) { header("Location: inprogress.php"); exit(); } else if ($logUser= 2){ // Add $biddersId and redirect to anypage mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB"); mysql_Query("INSERT INTO bidders (biddersId) VALUES ('$winningBidder')"); mysql_query("INSERT INTO transactions (itemDescription, itemPrice, bidderId, itemQty , totalPrice) VALUES('$itemDescription', '$itemPrice','$winningBidder', '$itemQty', '$totalPrice')") or die(mysql_error()); $_SESSION['itemDescription']='$itemDescription'; header("Location: index.php"); exit(); } } echo "<font color= \"red\" face=\"calibri\" size=\"4\">That bidder is already logged, Please press your browsers back button and try again.</font>"; ob_end_flush(); ?> DeleteBidder and newBidder are the only variables working? Hi Guys, Real PHP newbie here, and slowly getting to grips with it (I did say slowly, right!). Basically, I've created this register page. It's supposed to ask the user for their username, password, password verificiation, email address and then finally to ask the user to select from a tick list of interests (populated via the DB). Here's my code: <? include('includes/config.php'); $is_error = 0; if ($_POST['task'] == 'singup_do') { $signup_username = $_POST['user_username']; $signup_password = $_POST['user_password']; $signup_pwd_again = $_POST['user_password_again']; $signup_email = $_POST['user_email_address']; $signup_interest = $_POST['signup_interest']; if ($signup_username == ''){ $is_error = 1; $signup_username_msg = 'The username cannot be left blank'; } if ($signup_password == ''){ $is_error = 1; $signup_password_msg = 'Password field cannot be left blank'; } if ($signup_pwd_again == ''){ $is_error = 1; $signup_pwd_again_msg = 'Password again field cannot be left blank'; } if ($signup_email == ''){ $is_error = 1; $signup_email_msg = 'Email cannot be left blank'; } if ($signup_email != '' && !validateEmailAddress($signup_email)) { $is_error = 1; $signup_email_msg = 'Incorrect E-mail address'; } if (!is_array($signup_interest) || count($signup_interest)==0){ $is_error = 1; $signup_interest_msg = 'Please select atleast one interest'; } //EMAIL ADDRESS VALIDATION if ($signup_password!='' && $signup_pwd_again!='' && $signup_password != $signup_pwd_again) { $is_error = 1; $error_msg = 'Passwords don\'t match'; } //USERNAME DUPLICATION VALIDATION if (!$is_error && $signup_username!='' && !checkUsername($signup_username)) { $is_error = 1; $signup_username_msg = 'Username already taken, please enter another'; } if (!$is_error) { $signup_interest_ids = ( is_array($signup_interest) ? implode(',', $signup_interest) : '' ); $users_insert = "INSERT INTO users SET user_id='', user_username = '{$signup_username}' , user_password='{$signup_password}', user_email_address = '{$signup_email}', users_interests='{$signup_interest_ids}', user_active='Y', user_date_added=NOW()"; mysql_query($users_insert); header('Location:login.php?signup=success'); } } ?> <html> <head> <title>Register</title> <link href="css/style.css" rel="stylesheet" type="text/css" /> </head> <body > <div align="center"><BR><BR><BR> <div style="width:50%; "> <form name="frmSignup" action="sign_up.php" method="post"> <input type="hidden" name="task" value="singup_do"> <table width="100%" border="0" cellspacing="4" cellpadding="4" align="center"> <? if ($error_msg!='') {?> <tr><td> </td><td class="tahoma10rednormal"><?=$error_msg?></td></tr> <? }?> <tr><td width="20%" valign="top">Username : </td><td><input name="user_username" type="text" class="textfield" size="35" value="<?=$signup_username?>"/><? if ($signup_username_msg!='') { echo '<BR><span class="tahoma10rednormal">' . $signup_username_msg. '</span>' ; } ?></td></tr> <tr><td valign="top">Password : </td><td><input name="user_password" type="password" class="textfield" size="35" value="<?=$signup_password?>"/><? if ($signup_password_msg!='') { echo '<BR><span class="tahoma10rednormal">' . $signup_password_msg. '</span>' ; } ?></td></tr> <tr><td valign="top">Password (again): </td><td><input name="user_password_again" type="password" class="textfield" size="35" value="<?=$signup_pwd_again?>"/><? if ($signup_pwd_again_msg!='') { echo '<BR><span class="tahoma10rednormal">' . $signup_pwd_again_msg. '</span>' ; } ?></td></tr> <tr><td valign="top">Email address: </td><td><input name="user_email_address" type="text" class="textfield" size="35" value="<?=$signup_email?>"/><? if ($signup_email_msg!='') { echo '<BR><span class="tahoma10rednormal">' . $signup_email_msg. '</span>' ; } ?></td></tr> <tr><td colspan="2" ><b>Interests:</b><? if ($signup_interest_msg!='') { echo ' <span class="tahoma10rednormal">' . $signup_interest_msg. '</span>' ; } ?></td></tr> <tr><td colspan="2"> <? $categories = getCategories(); $categories_count = count($categories); if (is_array($categories)) { $cat_counter=0; ?> <table width="80%" border="0" cellspacing="4" cellpadding="4"> <? foreach($categories as $cats) { if ($cat_counter==0 || ($cat_counter%4) == 0) echo '<tr>'; $chk_selected = ''; if (is_array($signup_interest) && in_array($cats['id'], $signup_interest)) $chk_selected = "CHECKED"; ?> <td><input type="checkbox" name="signup_interest[]" value="<?=$cats['id']?>" <?=$chk_selected?>><?=$cats['text']?></td> <? if ($cat_counter==$categories_count || ($cat_counter%4) == 3) echo '</tr>'; $cat_counter++; } ?> </table> <? } else { echo 'No interest added yet.'; } ?> </tr> <tr> <td> </td> <td><input type="submit" name="submit_btn" value="Sign Up"> <input type="button" name="cancel_btn" value="Cancel" onClick="window.location.href='index.php'"></td> </tr> </table> </div> </div> </body> </html> I'm getting undefined varible errors for: Notice: Undefined variable: error_msg Undefined variable: signup_username_msg Notice: Undefined variable: signup_password_msg Notice: Undefined variable: signup_pwd_again_msg Notice: Undefined variable: signup_email_msg Notice: Undefined variable: signup_interest_msg Notice: Undefined variable: signup_interest Notice: Undefined variable: signup_interest Which as the canny of you will have noticed, is all of them! Hurrah at least I'm consistent! If anyone could help out a n00b I'd be so so grateful. Thanks! Rob Hello, I have just upgraded my wampserver and with it MySQL, PHP and PhpMyAdmin versions. And my scripts, which ran normally before, not burst hundreds of undefined variable and undefined index notices. I realize it's "notices", not "errors" but this is quite irritating. I believe it might be due to some upgrade in PHP scripting rules or something but I don't know what. I hope you can help me. The first type of notice is "undefined variable". This function will return the notice if I remove the bold red line, where I define the variable as empty before I use it in the loop. I didn't need to do this before. function statistics($array) { [color=red][b]$list = '';[/b][/color] if(is_array($array)) { foreach($array as $name => $value) { // Rip out the name of the client. $list .= "<li>".$name." - "; // set an integer so we know how many tier2 values we have read. $x = 0; foreach($value as $difference => $sum_total) { // if this is the more than the first tier2 values, use a '+' between the units. $list .= (++$x > 1) ? " + ".$sum_total." ".$difference : $sum_total." ".$difference; } // close the line out. $list .= "</li>"; } } return $list; } To avoid the 10+ like notices on the page I declare them empty before the variable's first occurrence. But this sounds stupid to me. Wasn't this one of PHP's benefits, not to have to declare the variable before using it? I also get about 30+ undefined index notices, e.g. Quote Notice: Undefined index: COMPANY XXX in F:\wamp\www\Project Management\main.php on line 37 Notice: Undefined index: USD in F:\wamp\www\Project Management\main.php on line 37 Notice: Undefined index: USD in F:\wamp\www\Project Management\main.php on line 41 Here are those lines: $income_total = calculate("income"); foreach($income_total as $row) { $clientID = $row['clientID']; $clientname = $row['clientname']; //$client = "<a href=\"index.php?page=Client&do=view&clientID=$clientID\">".$clientname."</a>"; $client = "<a href=\"index.php?page=Project&do=view&sortby=$clientID\">".$clientname."</a>"; $currency = $row['currency']; $client_sum = $row['client_sum']; $year_sum = ''; $year_sum += $client_sum; $income = ''; $income[$client][$currency] += $client_sum; $income_list = statistics($income); $income_all = ''; $income_all[$currency] += $client_sum; } Line 37 is: Quote $income[$client][$currency] = It's the values assigned to $client and to $currency that seem to cause the notice. How do I deal with this? I don't just want to turn error/notice display off, I want to resolve this issue. I am pretty sure I defined these, by making it something like $blah="blah" and `blah` = ' {$blah}' So why am I getting these errors = Notice: Use of undefined constant petid - assumed 'petid' in /home/vhosts/foggyjungle.6te.net/viewpet_forum.php on line 38 Notice: Use of undefined constant adopter - assumed 'adopter' in /home/vhosts/foggyjungle.6te.net/viewpet_forum.php on line 41 Notice: Undefined variable: fulldate in /home/vhosts/foggyjungle.6te.net/viewpet_forum.php on line 44 Fatal error: Call to undefined function showpet_forum() in /home/vhosts/foggyjungle.6te.net/viewpet_forum.php on line 45 $time = mysql_query("SELECT * FROM `pets_adopted`"); $date = mysql_fetch_array($time); $fulldate = "$date[fulldate]"; $halfdate = "$date[halfdate]"; function check(){ $pid = mysql_real_escape_string($_GET['id']); $result = mysql_query("SELECT * FROM `pets_adopted` WHERE `id` = '{$pid}'"); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $results = mysql_query("SELECT * FROM `pets_list` WHERE `id` = '{$row[petid]}'"); $pet = mysql_fetch_array($results); $results2 = mysql_query("SELECT * FROM `users` WHERE `id` = '{$row[adopter]}'"); $usercc = mysql_fetch_array($results2); There's the snippet. Thank you for any help. I am just really lost. my current code: Code: [Select] $Townsearch = $_REQUEST['rsTown']; list($Town, $County) = split('[,]', $Townsearch); ltrim($County,1); I am getting undefined index and undefined offset, so I tried this: Code: [Select] if $_REQUEST['rsTown'] == ''{ $Townsearch = ''; } else { $Townsearch = $_REQUEST['rsTown']; } but this brought back: Parse error: syntax error, unexpected T_VARIABLE, expecting '(' in D:\retroandvintage.co.uk\wwwroot\main.php on line 6 Can someone please help? thanks please help! I am getting undefined index and offset when I duplicated my SEARCH page for when logged in here is my code Code: [Select] <?php include_once("config.php"); include_once("functions.php"); // Check user logged in already: checkLoggedIn("yes"); ?> <!doctype html> <html> <head> <title>Retro and Vintage</title> <meta name="description" content="xxx" /> <meta name="keywords" content="xxx" /> <meta name="Content-Language" content="en-gb" /> <meta name="robots" content="FOLLOW,INDEX" /> <meta name="revisit-after" content="2 days" /> <meta name="copyright" content="jbiddulph.com" /> <meta name="author" content="John Biddulph - Professional web site design and development in the south of england mainly worthing and brighton" /> <meta name="distribution" content="Global" /> <meta name="resource-type" content="document" /> <link rel="stylesheet" type="text/css" href="css/reset.css" /> <link rel="stylesheet" type="text/css" href="css/style.css" title="default" /> <link rel="alternate stylesheet" type="text/css" href="css/style1.css" title="1" /> <link rel="alternate stylesheet" type="text/css" href="css/style2.css" title="2" /> <script type="text/javascript" src="js/stylechanger.js"></script> <script type="text/javascript" src="js/jquery-1.2.1.pack.js"></script> <script type="text/javascript"> function lookup(inputString) { if(inputString.length == 0) { // Hide the suggestion box. $('#suggestions').hide(); } else { $.post("rpc.php", {queryString: ""+inputString+""}, function(data){ if(data.length >0) { $('#suggestions').show(); $('#autoSuggestionsList').html(data); } }); } } // lookup function fill(thisValue) { $('#inputString').val(thisValue); setTimeout("$('#suggestions').hide();", 200); } </script> </head> <body> <?php if($messages) { displayErrors($messages); }?> <header> <div id="title"> <h1>My Pub Space <a href="#" onClick="setActiveStyleSheet('default'); return false;"><img src="images/0.gif" width="15" height="15" border="0" alt="css style" /></a> <a href="#" onClick="setActiveStyleSheet('1'); return false;"><img src="images/1.gif" width="15" height="15" border="0" alt="css style" /></a> <a href="#" onClick="setActiveStyleSheet('2'); return false;"><img src="images/2.gif" width="15" height="15" border="0" alt="css style" /></a> <span> <form method="post" class="textbox" action="search1.php"> City/Town: <input type="text" size="26" class="searchbox" value="" id="inputString" onKeyUp="lookup(this.value);" onBlur="fill();" /> <div class="suggestionsBox" id="suggestions" style="display: none;"> <img src="images/upArrow.png" style="position: relative; top: -36px; left: 105px; z-index:1;" alt="upArrow" /> <div class="suggestionList" id="autoSuggestionsList"> </div> </div> <input type="image" src="images/go.png" height="30" with="30" value="GO" /> </form> </span> </h1> </div> </header> <nav> <ul> <li class="selected"><a href="#">Home</a></li> <li><a href="#">Pubs</a></li> <li><a href="#">Members</a></li> <li><a href="#">Events</a></li> <li><a href="#">Register</a></li> </ul> </nav> <section id="intro"> <header> <h2>Your social guide to going down the pub, online!</h2> </header> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.</p> <img src="images/pub.jpg" alt="pub" /> </section> <div id="content"> <div id="mainContent"> <section> <article class="blogPost"> <header> <h2>This is the title of a blog post</h2> <p>Posted on <time datetime="2009-06-29T23:31+01:00">June 29th 2009</time> by <a href="#">Mads Kjaer</a> - <a href="#comments">3 comments</a></p> </header> <?php // drop out of PHP mode to display the plain HTML: $Townsearch = $_GET['rsTown']; echo $Townsearch; // Delimiters may be slash, dot, or hyphen list($Town, $County) = split('[,]', $Townsearch); $tableName="pubs"; $targetpage = "search1.php"; $limit = 20; $query = "SELECT COUNT(*) as num FROM $tableName WHERE rsTown LIKE '$Town%'"; $total_pages = mysql_fetch_array(mysql_query($query)); $total_pages = $total_pages['num']; $stages = 3; $page = mysql_escape_string($_REQUEST['page']); if( isset($_REQUEST['page']) && ctype_digit($_REQUEST['page']) ) { $page = (int) $_GET['page']; $start = ($page - 1) * $limit; }else{ $start = 0; } // Get page data $query1 = "SELECT * FROM $tableName WHERE rsTown LIKE '$Town%' LIMIT $start, $limit"; $result = mysql_query($query1); // Initial page num setup if ($page == 0){$page = 1;} $prev = $page - 1; $next = $page + 1; $lastpage = ceil($total_pages/$limit); $LastPagem1 = $lastpage - 1; $paginate = ''; if($lastpage > 1) { $paginate .= "<div class='paginate'>"; // Previous if ($page > 1){ $paginate.= "<a href='$targetpage?page=$prev'>previous</a>"; }else{ $paginate.= "<span class='disabled'>previous</span>"; } // Pages if ($lastpage < 7 + ($stages * 2)) // Not enough pages to breaking it up { for ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == $page){ $paginate.= "<span class='current'>$counter</span>"; }else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} } } elseif($lastpage > 5 + ($stages * 2)) // Enough pages to hide a few? { // Beginning only hide later pages if($page < 1 + ($stages * 2)) { for ($counter = 1; $counter < 4 + ($stages * 2); $counter++) { if ($counter == $page){ $paginate.= "<span class='current'>$counter</span>"; }else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} } $paginate.= "..."; $paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>"; $paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>"; } // Middle hide some front and some back elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2)) { $paginate.= "<a href='$targetpage?page=1'>1</a>"; $paginate.= "<a href='$targetpage?page=2'>2</a>"; $paginate.= "..."; for ($counter = $page - $stages; $counter <= $page + $stages; $counter++) { if ($counter == $page){ $paginate.= "<span class='current'>$counter</span>"; }else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} } $paginate.= "..."; $paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>"; $paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>"; } // End only hide early pages else { $paginate.= "<a href='$targetpage?page=1'>1</a>"; $paginate.= "<a href='$targetpage?page=2'>2</a>"; $paginate.= "..."; for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++) { if ($counter == $page){ $paginate.= "<span class='current'>$counter</span>"; }else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";} } } } // Next if ($page < $counter - 1){ $paginate.= "<a href='$targetpage?page=$next'>next</a>"; }else{ $paginate.= "<span class='disabled'>next</span>"; } $paginate.= "</div>"; } echo $total_pages.' Results'; // pagination echo $paginate; ?> <ul> <?php while($row = mysql_fetch_array($result)) { echo '<li>'.$row['rsPubName'].', '.$row['rsTown'].', '.$row['rsCounty'].'</li>'; if ($_SESSION["rsUser"] == "admin") { echo "<a href=\"edit.php?PUBID=".$row['PubID']."\" class=\"small\">edit this pub</a>"; } } ?> </ul> </article> </section> <section id="comments"> <h3>Comments</h3> <article> <header> <a href="#">George Washington</a> on <time datetime="2009-06-29T23:35:20+01:00">June 29th 2009 at 23:35</time> </header> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.</p> </article> <article> <header> <a href="#">Benjamin Franklin</a> on <time datetime="2009-06-29T23:40:09+01:00">June 29th 2009 at 23:40</time> </header> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.</p> </article> <article> <header> <a href="#">Barack Obama</a> on <time datetime="2009-06-29T23:59:00+01:00">June 29th 2009 at 23:59</time> </header> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut.</p> </article> </section> <form action="#" method="POST" method="post"> <h3>Post a comment</h3> <p> <label for="name">Name</label> <input name="name" id="name" type="text" required /> </p> <p> <label for="email">E-mail</label> <input name="email" id="email" type="email" required /> </p> <p> <label for="website">Website</label> <input name="website" id="website" type="url" /> </p> <p> <label for="comment">Comment</label> <textarea name="comment" id="comment" required></textarea> </p> <p> <input type="submit" value="Post comment" /> </p> </form> </div> <aside> <section> <header> <h3>Members Login Area</h3> </header> <h4>Welcome <? print($_SESSION["rsUser"]); ?></h4> <a href="logout.php">Logout</a> </section> <section> <header> <h3>Archives</h3> </header> <ul> <li><a href="#">December 2008</a></li> <li><a href="#">January 2009</a></li> <li><a href="#">February 2009</a></li> <li><a href="#">March 2009</a></li> <li><a href="#">April 2009</a></li> <li><a href="#">May 2009</a></li> <li><a href="#">June 2009</a></li> </ul> </section> </aside> </div> <footer> <div> <section id="about"> <header> <h3>About</h3> </header> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco <a href="#">laboris nisi ut aliquip</a> ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> </section> <section id="blogroll"> <header> <h3>Blogroll</h3> </header> <ul> <li><a href="#">NETTUTS+</a></li> <li><a href="#">FreelanceSwitch</a></li> <li><a href="#">In The Woods</a></li> <li><a href="#">Netsetter</a></li> <li><a href="#">PSDTUTS+</a></li> </ul> </section> <section id="popular"> <header> <h3>Popular</h3> </header> <ul> <li><a href="#">This is the title of a blog post</a></li> <li><a href="#">Lorem ipsum dolor sit amet</a></li> <li><a href="#">Consectetur adipisicing elit, sed do eiusmod</a></li> <li><a href="#">Duis aute irure dolor</a></li> <li><a href="#">Excepteur sint occaecat cupidatat</a></li> <li><a href="#">Reprehenderit in voluptate velit</a></li> <li><a href="#">Officia deserunt mollit anim id est laborum</a></li> <li><a href="#">Lorem ipsum dolor sit amet</a></li> </ul> </section> </div> </footer> </body> </html> error lies on these lines Code: [Select] // drop out of PHP mode to display the plain HTML: $Townsearch = $_GET['rsTown']; echo $Townsearch; // Delimiters may be slash, dot, or hyphen list($Town, $County) = split('[,]', $Townsearch); hi, I need help really badly for my PHP-Postcard Script. Basically it sends the card out but the URL does not work, I get the following error message: The URL is not valid and cannot be loaded It also states that Notice: Undefined index: www.voluntary.awardspace.co.uk in /home/www/voluntary.awardspace.co.uk/Postcard.php on line 25 Notice: Undefined index: Postcard.php in /home/www/voluntary.awardspace.co.uk/Postcard.php on line 25 See Code below: <?php session_start(); //check error log ini_set('display_errors', 1); ini_set('log_errors', 1); ini_set('error_log', dirname(__FILE__) . '/error_log.txt'); error_reporting(E_ALL); // CHANGE PARAMETERS HERE BEGIN $senderName = " Holidays From Home "; // Eg.: John's Postcards $senderEmail = "chris01@voluntary.awardspace.co.uk"; // Eg.: john@postcard.com // Change only if you have problems with urls $postcardURL = "http://".$_SERVER["www.voluntary.awardspace.co.uk"].$_SERVER["Postcard.php"]; // CHANGE PARAMETERS HERE END $result = 0; $msg = ""; $msg1 = ""; $pic = ""; function displayPhotos() { global $pic; $columns = 5; $act = 0; $act1 = 0; // Open the actual directory if($handle = opendir("thumbs")) { // Read all file from the actual directory while($file = readdir($handle)) { if(!is_dir($file)) { if(isset($pic[1])) { if($pic[1] == $act1){$sel = "checked";} else{$sel = "unchecked";} } if($act == 0){echo "<tr>";} echo "<td align='center'><img src='thumbs/$file' alt='postcard'/><br/><input type='radio' name='selimg' value='$file,$act1' $sel/></td>"; $act++; $act1++; if($act == $columns){$act = 0;echo "</tr>";} } } echo "</tr>"; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html> <head> <title>Micro Postcard</title> <link href= "style/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="main"> <div class="style1" id="caption"> <div align="left" class="style1"></div> </div> <?php //makes sure form is correctly filled in if(!empty($_POST["submit"])) { if(empty($_POST["selimg"])){$msg = "Please select an image from above!";$result = 3;} else{$pic = explode(",",$_POST["selimg"]);} if(empty($_POST["email"]) && empty($result)){$msg1 = "You must enter an email address!";$result = 3;} $secCode = empty($_POST["secCode"]) ? "" : strtolower($_POST["secCode"]); if($secCode == $_SESSION["securityCode"] && $result != 3) { $filename = date("YmdGis"); $f = fopen("messages/".$filename.".txt","w+"); fwrite($f,$pic[0]."\n"); fwrite($f,$_POST['email']."\n"); fwrite($f,stripslashes($_POST["message"])."\n"); fclose($f); // Compose the mail $from = "From: $senderName <$senderEmail>\r\n"; $replay = "Reply-To: $senderEmail\r\n"; $params = "MIME-Version: 1.0\r\n"; $params .= "Content-type: text/plain; charset=iso-8859-1\r\n"; $mailtext = "You have just received a Virtual Postcard!\r\n\r\n You can pick up your postcard at the following web address:\r\n $postcardURL?show=$filename\r\n\r\n We hope you enjoy your postcard, and if you do, please take a moment to send a few yourself!\r\n\r\n Regards,\r\n Holidays From Home\r\n $postcardURL"; // Send email @mail($_POST["email"],"You've received a postcard",$mailtext,$from.$replay.$params); echo "<center> Your postcard was sent successfully!<br /><br /> <img src='images/$pic[0]' alt='postcard' /><br /><br /><br />".stripslashes($_POST["message"]). "</center>"; $result = 1; } else{if($result != 3){$result = 2;}} } if(!empty($_GET["show"])) { $file = $_GET["show"]; $content = file("messages/$file.txt"); $pic = $content[0]; unset($content[0]); unset($content[1]); foreach($content as $value){$main .= $value;} echo "<center> Your postcard!<br /><br /> <img src='images/$pic' alt='postcard' /><br /><br /><br />$main </center>"; } if((empty($result) || $result == 2 || $result == 3) && empty($_GET["show"])) { echo "<form action='#' method='post'> <table align='center'>"; displayPhotos(); echo "</table> <div style='color:#f00;font-size:16px;'>$msg</div> <h2>Fill in the Form and then click on Send Card!!</h2> <table width='100%'> <tr><td>Send to (email address):</td><td><div style='color:#f00;font-size:16px;'>$msg1</div><input type='text' name='email' size='30' value='".$_POST["email"]."' /></td></tr> <tr><td>Message:</td><td><textarea name='message' rows='10' cols='40'>".stripslashes($_POST["message"])."</textarea></td></tr> <tr><td colspan='2'>".($result == 2 ? "<p style='color:#f00;font-size:16px;'>Sorry the security code is invalid! Please try it again!</span></p>" : " ")."</tr> <tr> <td>Security code: <input class='text' name='secCode' type='text' size='10' /> </td><td><img src='securityCode.php' alt='security code' border='1' /></td> </tr> <tr><td colspan='2'> </tr> <tr><td colspan='2' align='left'><input type='submit' value='Send card!' name='submit'/></td></tr> </table> </form>"; } ?> Absolutely any help would be much appreciated. I want ot know is there a way round this problem? Here is the http://voluntary.awardspace.co.uk/Postcard.php I am absolutely desperate to solve this burning issue does anyone know how to decode this XML variable value into string values? I also need to know the oposite way: creating variable values into xml. I've tried several code examples but they did filter the requested data. Code: [Select] $xml='<?xml version="1.0" encoding="utf-8"?> <elements> <text identifier="ed9cdd4c-ae8b-4ecb-bca7-e12a5153bc02"> <value/> </text> <textarea identifier="a77f06fc-1561-453c-a429-8dd05cdc29f5"> <value><![CDATA[<p style="text-align: justify;">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>]]></value> </textarea> <textarea identifier="1a85a7a6-2aba-4480-925b-6b97d311ee6c"> <value><![CDATA[<p style="text-align: justify;">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>]]></value> </textarea> <image identifier="ffcc1c50-8dbd-4115-b463-b43bdcd44a57"> <file><![CDATA[images/stories/red/cars/autobedrijf.png]]></file> <title/> <link/> <target/> <rel/> <lightbox_image/> <width><![CDATA[250]]></width> <height><![CDATA[187]]></height> </image> <text identifier="4339a108-f907-4661-9aab-d6f3f00e736e"> <value><![CDATA[Kramer 5]]></value> </text> <text identifier="ea0666d7-51e3-4e52-8617-25e3ad61f8b8"> <value><![CDATA[6000 RS]]></value> </text> <text identifier="90a18889-884b-4d53-a302-4e6e4595efa0"> <value><![CDATA[Eindhoven]]></value> </text> <text identifier="410d72e0-29b3-4a92-b7d7-f01e828b1586"> <value><![CDATA[APK Pick up and return]]></value> </text> <text identifier="45b86f23-e656-4a81-bb8f-84e5ea76f71f"> <value><![CDATA[15% korting op grote beurt]]></value> </text> <text identifier="3dbbe1c6-15d6-4375-9f2f-f0e7287e29f3"> <value><![CDATA[Gratis opslag zomerbanden]]></value> </text> <text identifier="2e878db0-605d-4d58-9806-8e75bced67a4"> <value><![CDATA[Gratis abonnement of grote beurt]]></value> </text> <text identifier="94e3e08f-e008-487b-9cbd-25d108a9705e"> <value/> </text> <text identifier="73e74b73-f509-4de7-91cf-e919d14bdb0b"> <value/> </text> <text identifier="b870164b-fe78-45b0-b840-8ebceb9b9cb6"> <value><![CDATA[040 123 45 67]]></value> </text> <text identifier="8a91aab2-7862-4a04-bd28-07f1ff4acce5"> <value/> </text> <email identifier="3f15b5e4-0dea-4114-a870-1106b85248de"> <value/> <text/> <subject/> <body/> </email> <link identifier="0b3d983e-b2fa-4728-afa0-a0b640fa34dc"> <value/> <text/> <target/> <custom_title/> <rel/> </link> <relateditems identifier="7056f1d2-5253-40b6-8efd-d289b10a8c69"/> <rating identifier="cf6dd846-5774-47aa-8ca7-c1623c06e130"> <votes><![CDATA[1]]></votes> <value><![CDATA[1.0000]]></value> </rating> <googlemaps identifier="160bd40a-3e0e-48de-b6cd-56cdcc9db892"> <location><![CDATA[50.895711,5.955427]]></location> </googlemaps> </elements>'; I have written the code for email check, but how and where can I put the code to check if a username has been used twice? Thanks in advance. Code: [Select] <?php $servername = "localhost"; $username = ""; $password = ""; //validate fields if(!$_POST["username"] || !$_POST["email"] || !$_POST["password1"] || !$_POST["password2"]){ echo "<p> </p><p> </p><p> </p><br />Please fill the required fields, <p> </p><p> </p><a href='register.php'>Go to register page</a>"; //validate password }else if($_POST["password1"] != $_POST["password2"]){ echo "<p> </p><p> </p><p> </p><br />Please go back, PASSWORDS do not match! <p> </p><p> </p><a href='register.php'>Go to register page</a>"; //validate email }else if(!(eregi("^.+@.+\\..+$", $_POST['email']))){ echo "<p> </p><p> </p><p> </p><br />Please enter a valid EMAIL! <a href='register.php'><p> </p><p> </p>Go to register page</a>"; //validate captcha }else if(($_SESSION['security_code'] != $_POST['security_code']) || (empty($_SESSION['security_code'])) ){ echo "<p> </p><p> </p><p> </p><br />CAPTCHA CODE does not match! <p> </p><p> </p><a href='register.php'>Go to register page</a>"; }else{ $conn= mysql_connect($servername,$username,$password)or die(mysql_error()); mysql_select_db("genesis_members",$conn); // check if already registered $sql_check = "SELECT * FROM users WHERE email = '".$_POST[email]."'"; $result_check = mysql_query($sql_check,$conn) or die(mysql_error()); $row = mysql_fetch_assoc($result_check); if($row['id']){ echo "<p> </p><p> </p><p> </p><br />EMAIL already registered! <p> </p><p> </p><a href='register.php'>Go to register page</a>"; }else{ // insert in db $sql = "INSERT INTO users (username, email, password, company, phone, services) VALUES ('".$_POST[username]."', '".$_POST[email]."', '".$_POST[password1]."', '".$_POST[company]."', '".$_POST[phone]."', '".$_POST[services]."')"; $result = mysql_query($sql,$conn) or die(mysql_error()); echo "<p> </p><p> </p><p> </p><br /><h1>You Have Successfully Registered</h1>"; echo "<p> </p><p> </p><br /><a href='main_login.php'>go to login page</a>"; } } ?> I don't know precisely how to put it so i will give an example: suppose you have a search form with input fields for: -an age range, -a data range, -for the sex, -postal code as soon as the user would fill in one of these input fields, a query should be generated including a condition doing something with the inputted value. For example, the user fills in maxAge, the the query should say: SELECT * FROM table WHERE age >= maxAge; Filling more than one criterion then would do .= " AND criteria (condition) inputvalue " etc... My question comes to the part about: how to check if there is already a WHERE in the clause and how to put WHERE or AND for every criterion. Since doing like above, i won't be able to search for another criterion if i don't select maxAge first because then there would be no WHERE in the sql clause. Hopefully i've put it clear thanks in advance Hello! Does anyone know an effective way to track inactive idlers in daily basis? So that it will count the amount of days no data has been posted to the table. E.g. User posts latest data and inserts timestamp 1282228120 which reads Thursday, August 19th 2010, 14:28:40 (GMT) The days for inactivity should output as 8 days because no data has been posted from 20th August to today - 28th August. Anyway I can achieve this? Any information is appreciated, thanks. php5.2, mysql server5.02: if record exists,append random digit to end of information in rows column then add to database If user mike already exists and another mike is trying to create a user id I would like to keep the old mike record like it is, then add a new mike record, but add a unique digit to the end of the name mike before the record gets added to the database as a new row. Thank you kindly! I coded small funny script I tested it in three hosting ww.rufaa.net dallawat.com/new ibuj.org but I don't know why in the first link, my script seem slow not like the other second and third links So basically I have a site, and on that site, I have a page that submits a form and updates a database. I have it set up so that someone can enter in Multiple values into a textarea, one on each line, and it will submit each of those values as a new row in the database, but for the life of me, I cannot figure out how to check those values against the actual users. It is basically a point system, where the staff can award points users of the site. But at the moment, a Staff member could enter in Jibberish, and it would insert that into the database, but I want it to check my users table to make sure the user exists before it inserts it into the database. here is my code: <?php include 'global.php'; echo $headersidebar; if ($_COOKIE['access'] == $accessstaff) { if(count($_POST)) { $array = preg_split('/(\r?\n)+/', $_POST['studentname']); foreach($array as $students) { $statusmsg = '<center><span style="background: #A6FF9E;">You have successfully submitted points to the database.</span></center>'; mysql_query("INSERT INTO points (giver, receiver, points, category, reason, date, status) VALUES ('{$_COOKIE['username']}', '{$students}', '{$_POST['pointamt']}', '{$_POST['pointcat']}', '{$_POST['pointreason']}', '{$date}', 'Validating')"); } } $addpointspage = $statusmsg . ' <form action="submit_points.php" method="post"> <table class="table" > <tr> <td colspan="10"> <h1><strong><center>Submit Points</center></strong></h1> </td> </tr> <tr> <td colspan="10" rowspan="100"> <center>Please remember to follow the house point limits when submitting house points.</center> </td> </tr> </table> <table class="table"> <tr> <td style="width: 15%;" valign="top"> Student Name:<br> <span style="font-size: 60%;">(List as many as you want; One per Line)</span> </td> <td colspan="10"> <center><textarea name="studentname" cols="60" rows="10"></textarea></center> </td> </tr> <tr> <td style="width: 15%;" valign="top"> Amount of Points: </td> <td> <input style="position: relative; left: 16px;" type="text" size="15" name="pointamt" /> </td> <td> Do not put anything that is not a number into this box. </td> </tr> <tr> <td style="width: 15%;" valign="top"> Point Category: </td> <td colspan="10"> <select name="pointcat" style="position: relative; left: 16px;"> <option SELECTED value="">-------</option> <option>Class Work</option> <option>Class Exam</option> <option>Extra Work</option> <option>Contests</option> <option>Teacher\'s Assistant</option> <option>Negative Points</option> </select> </td> </tr> <tr> <td style="width: 15%;" valign="top"> Reason: </td> <td colspan="10"> <input style="position: relative; left: 16px;" name="pointreason" type="text" size="80" /> </td> </tr> <tr> <td> </td> <td colspan="10"> <input style="position: relative; left: 16px;" type="submit" value="Submit Points" /> </td> </tr> </table </form> '; } elseif (1==1) { $addpointspage = $accessdenied; } echo ' <!-- start content --> <div id="content"> <div class="post"> <div class="entry"> <p><strong>' . $addpointspage . '</p> <p class="links">' . $addpointslink . '</p> </div> </div> </div> <!-- end content --> <div style="clear: both;"> </div> </div> <!-- end page --> </div>'; echo $footer; ?> I am fairly new to PHP, so I would appreciate any help someone could give me; I am not too good with arrays and such, so this one has got me stumped. can somebody please tel me how to make sure a field is a number? I have some error checking like if(empty($postcode)) { $errors[] = "Please enter your postcode"; } if(strlen($tel)<11) { $errors[] = "Please enter a phone number that is the correct length"; } But I dont know and cant find how to check for a number only. I have two arrays of keywords that I'm pulling from the database. I'm wanting to compare those two arrays and see if ANY of the contents are the same, if they are push that result into another array for later use. while($row_rsCWGetupsell = $cartweaver->db->db_fetch_assoc($rsCWGetupsell)) { $b = array_unique(array_filter(explode(",", preg_replace( '/\s*/m', '', $row_rsCWGetupsell["product_keywords"])), "strlen")); $a = array_unique(array_filter(explode(",", preg_replace( '/\s*/m', '', $row_rsCWGetProduct["product_keywords"])), "strlen")); if($a IN $b) // <--- this is where the comparison should be! $list[] = $row_rsCWGetupsell; } Okay I need some help. I want to check a MySQL DB and then if it says 0 then don't do anything if it says anything else echo out what's there. I have tried for about a hour now. |