PHP - Question About Switch Statement
when you build a switch, does it have to have a default case? If so, is there a way to get it to default to the first case instead of re posting the code in the default?
Similar TutorialsHello, Hi all, I am creating a switch page which will be acting as more of an index page for the different php files I have in my project. I have seven different pages and, I am a bit stuck as to what the order is and where the codes should go. I have got this far as is shown below: Code: [Select] <!--PHP Update--> <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("project1", $con); if ($_GET['action']=='delete_ok' and or){ }elseif ($_GET['action']=='edit_ok'){ } switch($_GET['action']){ case 'delete_ok': #########Delete OK Start################# //echo '<meta http-equiv="Refresh" content="0;URL=switch.php">'; #########Delete OK End ################# break; case 'edit_ok': break; } ?> <!--HTML--> <?php switch($_GET['action']){ case 'delete'; break; case 'edit'; echo 'Edit page'; ?> <form action="switch.php?action=edit_ok" method="post"> <?php break; default: echo "<table border='1'> <tr> <th>ID</th> <th>Date Of Birth</th> <th>Gender</th> <th>Title</th> <th>First Name</th> <th>Last Name</th> <th>Address Line 1</th> <th>Address Line 2</th> <th>City</th> <th>Postcode</th> <th>Contact No</th> <th>Email</th> <th>Additional Info</th> <th>Action</th> </tr>"; $result = mysql_query("SELECT * FROM project_data"); while($row = mysql_fetch_array($result)){ echo "<tr>"; echo "<td>" . $row['ID'] . "</td>"; echo "<td>" . $row['Date_Of_Birth'] . "</td>"; echo "<td>" . $row['Gender'] . "</td>"; echo "<td>" . $row['Title'] . "</td>"; echo "<td>" . $row['First_Name'] . "</td>"; echo "<td>" . $row['Last_Name'] . "</td>"; echo "<td>" . $row['Address_Line_1'] . "</td>"; echo "<td>" . $row['Address_Line_2'] . "</td>"; echo "<td>" . $row['City'] . "</td>"; echo "<td>" . $row['Postcode'] . "</td>"; echo "<td>" . $row['Contact_No'] . "</td>"; echo "<td>" . $row['Email'] . "</td>"; echo "<td>" . $row['Additional_Comment'] . "</td>"; echo "<td><a href='switch.php?action=edit&id=" . $row['ID']."'>Edit</a>  <a href='delete_write.php?id=" . $row['ID']."'>Delete</a></td>"; echo "</tr>"; } echo "</table>"; echo "<a href='write.php'>Insert</a>"; } mysql_close($con); ?> the file names a delete_write.php- deletes the data display.php- displays the data edit_write.php- editing the info edit_write_ok.php- edits on the database and shows on display.php write.php- this is the input page write_input.php- this inputs the data from write.php into the main database any help would be much appreciated. MOD EDIT: code tags added. $price = 0.00; switch($someValue) { case "One": $price = 1; break; case "Two": $total = $price + 2; echo $total break; } I'm having problem on this. Basically what i want is to use the value of $price in case "One" to case "Two". But it won't work. Any idea how to accomplish this? Thank you in advance. I couldn't understand switch statements in .net and I still don't get them with php. Can someone turn this into a switch statement, I just can't wrap my head around then. if (isset($_POST['news'])){ add($_POST['text']); header("location: admin.php"); } elseif (isset($_POST['rnews'])){ deletenews($_POST['number']); header("location: admin.php"); } elseif (isset($_POST['taddm'])){ taddmember($_POST['website'], $_POST['name']); header("location: admin.php"); } elseif (isset($_POST['tdelm'])){ tdeletemember($_POST['number']); header("location: admin.php"); } elseif (isset($_POST['addm'])){ addmember($_POST['website'], $_POST['name']); header("location: admin.php"); } elseif (isset($_POST['delm'])){ deletemember($_POST['number']); header("location: admin.php"); } elseif (isset($_POST['tnews'])){ tadd($_POST['text']); header("location: admin.php"); } elseif (isset($_POST['trnews'])){ tdelete($_POST['number']); header("location: admin.php"); } elseif (isset($_POST['video'])){ videoupdate($_POST['link']); header("location: admin.php"); } else { echo " Failed"; } Code: [Select] <?php echo '<form action="hwCase.php" method="post"> Enter number <input type="text" name="number"/><br /> </form>'; $input = $_POST['number']; // if a number is entered in the form, ie not null if (isset($input)) { switch ($input) { // if number entered is less than 0, ie negative number case ($input<0): echo "Enter a positive number."; break; // if number entered is greater than 1000 case ($input>1000): echo "Enter a number less than 1000."; break; // if number entered is not a number, ie a letter, a character case (!ctype_digit($input)): echo "<br><img src=\"squidward.jpg\"><br><br>Enter a valid number. "; break; // if valid number is entered, loop "hello world" that many times case (($input>0) && ($input<1000)): echo "hello world " . $input . "<br />"; break; // if anything else is entered default: echo "Enter a number."; break; } } // if no number is entered in the form, ie null else { echo "Please enter a number."; } ?> For some reason, my loop doesn't work. Please help me fix it! Thanks in advance! I need to loop this part: Code: [Select] case (($input>0) && ($input<1000)): echo "hello world " . $input . "<br />"; break; i am trying to get the allowed file types from the database into a switch statement but with no luck so far. They types are in the database like: jpg, png, gif. All seperated with a comma and all in one db column. I am then splitting them at the comma and inserting them into $file_list. In the switch statement i want it to be like: switch($ext) { case "jpg": case "png": case "gif": break; } how can i make this possible? here is my code so far: $ext = strtolower(pathinfo($_FILES['Filedata']['name'], PATHINFO_EXTENSION)); $f_types = $f_types_info['file_types']; $f_types = preg_split("|\,|", $f_types); $types = count($f_types); $file_list = ""; for($i=0; $i<$types; $i++) { $file_list .= $f_types[$i]; } switch ($ext) { case $file_list: break; default: $error = "File Type Not Allowed"; break; } I have database that is a list of categories that I would like to insert into a switch statement. This is the only way that I know how to do it right off hand and of course it doesn't work. I've looked on the internet and found examples but they are slightly over my head as ways to do it. Depending on $group which comes from the url a title an h1 would be assigned. Code: [Select] $q = "SELECT * FROM categories"; $r = @mysqli_query ($dbc, $q); switch ($group) { if ($r) { //If $r ran OK while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)){ case '$row['id_cat']': $h1 = '.$row['group']'; break; } } } Thanks S Hello Everyone, I have to change the if statements to a switch statement, in this game. Can anyone help? Thanks. var checkKeyPressed = function (e) { // Press key A or key D to make dog run to the left or right // The running speed is specified by the step variable, 10 by default. // If you replace 10 with a larger integer, the dog will run faster. //press A, dog runs left if (e.keyCode == "65") { if (prex[0] > 5) { prex[0] = prex[0] - step; } } //press D, dog runs right if (e.keyCode == "68") { if (prex[0] < right) { prex[0] = prex[0] + step; } } }; Hi there, I am working on a PHP web form. There is simple textbox where users can enter countries. If the user enters any of the European countries for example Spain, Germany or Italy then the web page must echo ' You entered a European country. The code I am using is: switch ($txtCountry) { case 'Germany' || 'Spain' || 'Belgium' || 'Cyprus' || 'Estonia': echo "You entered a European Country"; break; case 'Japan': echo "You entered a Far Eastern Country"; break; default: echo "Unknown Country"; break; } Now the problem is even if I enter a different country like Japan, it goes to the first Case: i.e. 'You entered a European Country' Whats the best way to use Switch case to check multiple values. Is my Syntax correct or do I need to use single quote of double quote here. Please reply. Thank you! Hey guys, I have a mysql switch statement that shows different things based on the row value. Here it is... <?php switch ($rows['icon']) { case 1: $picture = '<img src=\"img/apple.gif\" title=\"apple\" alt=\"apple\" />'; echo $picture; break; case 2: $picture = '<img src=\"img/banana.gif\" title=\"banana\" alt=\"banana\" />'; echo $picture; break; case 3: $picture = '<img src=\"img/orange.gif\" title=\"orange\" alt=\"orange\" />'; echo $picture; break; default: echo "$rows[icon] is something other than 1 2 or 3"; break; } ?> Here is how the other code looks like. <?php error_reporting(E_ALL); ini_set('display_errors', '1'); mysql_connect("localhost", "", "")or die("cannot connect"); mysql_select_db("test")or die("cannot select DB"); $tbl_name="test_mysql"; $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); $count=mysql_num_rows($result); if (isset($_POST['Submit'])) { for($i=0;$i<$count;$i++){ $month = $_POST['month']; $date = $_POST['date']; $message = $_POST['message']; $title = $_POST['title']; $id = $_POST['id']; $icon = $_POST['icon']; // ILYA $monthday= $month[$i]."<br>".$date[$i]; $sql1="UPDATE $tbl_name SET monthday='$monthday', month='$month[$i]', date='$date[$i]', message='" . mysql_real_escape_string($message[$i]) . "', title='" . mysql_real_escape_string($title[$i]) . "', icon='$icon[$i]' WHERE id=".$id[$i]; // ILYA if(!($result1 = mysql_query($sql1))){ "<BR>Error UPDATING $tbl_name "; exit(); } } } $result=mysql_query($sql); $count=mysql_num_rows($result); ?> Dont mind the other UPDATE code its part of something else. Anyways, why is the case automaticaly going to the last one... with the words: is something other than 1 2 or 3 Also, this is with multiple rows at once so I think that that may the problem... As the title says, I'm looking for a better way to create a switch statement on an "edit" form. Since there are 3 of the same types of <selects>, all using the values of US states. Billing state, shipping state, drivers license state. Currently I am using this: switch($row['pri_add4']){ case 'AK': $pri_add4 = '<option value="AK" selected="selected">AK</option><option value="AL">AL</option><option value="AR">AR</option><option value="AZ">AZ</option><option value="CA">CA</option><option value="CO">CO</option><option value="CT">CT</option><option value="DC">DC</option><option value="DE">DE</option><option value="FL">FL</option><option value="GA">GA</option><option value="HI">HI</option><option value="IA">IA</option><option value="ID">ID</option><option value="IL">IL</option><option value="IN">IN</option><option value="KS">KS</option><option value="KY">KY</option><option value="LA">LA</option><option value="MA">MA</option><option value="MD">MD</option><option value="ME">ME</option><option value="MI">MI</option><option value="MN">MN</option><option value="MO">MO</option><option value="MS">MS</option><option value="MT">MT</option><option value="NC">NC</option><option value="ND">ND</option><option value="NE">NE</option><option value="NH">NH</option><option value="NJ">NJ</option><option value="NM">NM</option><option value="NV">NV</option><option value="NY">NY</option><option value="OH">OH</option><option value="OK">OK</option><option value="OR">OR</option><option value="PA">PA</option><option value="RI">RI</option><option value="SC">SC</option><option value="SD">SD</option><option value="TN">TN</option><option value="TX">TX</option><option value="UT">UT</option><option value="VA">VA</option><option value="VT">VT</option><option value="WA">WA</option><option value="WI">WI</option><option value="WV">WV</option><option value="WY">WY</option>'; break; case 'AL': $pri_add4 = '<option value="AK">AK</option><option value="AL" selected="selected">AL</option><option value="AR">AR</option><option value="AZ">AZ</option><option value="CA">CA</option><option value="CO">CO</option><option value="CT">CT</option><option value="DC">DC</option><option value="DE">DE</option><option value="FL">FL</option><option value="GA">GA</option><option value="HI">HI</option><option value="IA">IA</option><option value="ID">ID</option><option value="IL">IL</option><option value="IN">IN</option><option value="KS">KS</option><option value="KY">KY</option><option value="LA">LA</option><option value="MA">MA</option><option value="MD">MD</option><option value="ME">ME</option><option value="MI">MI</option><option value="MN">MN</option><option value="MO">MO</option><option value="MS">MS</option><option value="MT">MT</option><option value="NC">NC</option><option value="ND">ND</option><option value="NE">NE</option><option value="NH">NH</option><option value="NJ">NJ</option><option value="NM">NM</option><option value="NV">NV</option><option value="NY">NY</option><option value="OH">OH</option><option value="OK">OK</option><option value="OR">OR</option><option value="PA">PA</option><option value="RI">RI</option><option value="SC">SC</option><option value="SD">SD</option><option value="TN">TN</option><option value="TX">TX</option><option value="UT">UT</option><option value="VA">VA</option><option value="VT">VT</option><option value="WA">WA</option><option value="WI">WI</option><option value="WV">WV</option><option value="WY">WY</option>'; break; case 'AR': $pri_add4 = '<option value="AK">AK</option><option value="AL">AL</option><option value="AR" selected="selected">AR</option><option value="AZ">AZ</option><option value="CA">CA</option><option value="CO">CO</option><option value="CT">CT</option><option value="DC">DC</option><option value="DE">DE</option><option value="FL">FL</option><option value="GA">GA</option><option value="HI">HI</option><option value="IA">IA</option><option value="ID">ID</option><option value="IL">IL</option><option value="IN">IN</option><option value="KS">KS</option><option value="KY">KY</option><option value="LA">LA</option><option value="MA">MA</option><option value="MD">MD</option><option value="ME">ME</option><option value="MI">MI</option><option value="MN">MN</option><option value="MO">MO</option><option value="MS">MS</option><option value="MT">MT</option><option value="NC">NC</option><option value="ND">ND</option><option value="NE">NE</option><option value="NH">NH</option><option value="NJ">NJ</option><option value="NM">NM</option><option value="NV">NV</option><option value="NY">NY</option><option value="OH">OH</option><option value="OK">OK</option><option value="OR">OR</option><option value="PA">PA</option><option value="RI">RI</option><option value="SC">SC</option><option value="SD">SD</option><option value="TN">TN</option><option value="TX">TX</option><option value="UT">UT</option><option value="VA">VA</option><option value="VT">VT</option><option value="WA">WA</option><option value="WI">WI</option><option value="WV">WV</option><option value="WY">WY</option>'; break; case 'AZ': $pri_add4 = '<option value="AK">AK</option><option value="AL">AL</option><option value="AR">AR</option><option value="AZ" selected="selected">AZ</option><option value="CA">CA</option><option value="CO">CO</option><option value="CT">CT</option><option value="DC">DC</option><option value="DE">DE</option><option value="FL">FL</option><option value="GA">GA</option><option value="HI">HI</option><option value="IA">IA</option><option value="ID">ID</option><option value="IL">IL</option><option value="IN">IN</option><option value="KS">KS</option><option value="KY">KY</option><option value="LA">LA</option><option value="MA">MA</option><option value="MD">MD</option><option value="ME">ME</option><option value="MI">MI</option><option value="MN">MN</option><option value="MO">MO</option><option value="MS">MS</option><option value="MT">MT</option><option value="NC">NC</option><option value="ND">ND</option><option value="NE">NE</option><option value="NH">NH</option><option value="NJ">NJ</option><option value="NM">NM</option><option value="NV">NV</option><option value="NY">NY</option><option value="OH">OH</option><option value="OK">OK</option><option value="OR">OR</option><option value="PA">PA</option><option value="RI">RI</option><option value="SC">SC</option><option value="SD">SD</option><option value="TN">TN</option><option value="TX">TX</option><option value="UT">UT</option><option value="VA">VA</option><option value="VT">VT</option><option value="WA">WA</option><option value="WI">WI</option><option value="WV">WV</option><option value="WY">WY</option>'; break; case 'CA': $pri_add4 = '<option value="AK">AK</option><option value="AL">AL</option><option value="AR">AR</option><option value="AZ">AZ</option><option value="CA" selected="selected">CA</option><option value="CO">CO</option><option value="CT">CT</option><option value="DC">DC</option><option value="DE">DE</option><option value="FL">FL</option><option value="GA">GA</option><option value="HI">HI</option><option value="IA">IA</option><option value="ID">ID</option><option value="IL">IL</option><option value="IN">IN</option><option value="KS">KS</option><option value="KY">KY</option><option value="LA">LA</option><option value="MA">MA</option><option value="MD">MD</option><option value="ME">ME</option><option value="MI">MI</option><option value="MN">MN</option><option value="MO">MO</option><option value="MS">MS</option><option value="MT">MT</option><option value="NC">NC</option><option value="ND">ND</option><option value="NE">NE</option><option value="NH">NH</option><option value="NJ">NJ</option><option value="NM">NM</option><option value="NV">NV</option><option value="NY">NY</option><option value="OH">OH</option><option value="OK">OK</option><option value="OR">OR</option><option value="PA">PA</option><option value="RI">RI</option><option value="SC">SC</option><option value="SD">SD</option><option value="TN">TN</option><option value="TX">TX</option><option value="UT">UT</option><option value="VA">VA</option><option value="VT">VT</option><option value="WA">WA</option><option value="WI">WI</option><option value="WV">WV</option><option value="WY">WY</option>'; break; case 'CO': $pri_add4 = '<option value="AK">AK</option><option value="AL">AL</option><option value="AR">AR</option><option value="AZ">AZ</option><option value="CA">CA</option><option value="CO" selected="selected">CO</option><option value="CT">CT</option><option value="DC">DC</option><option value="DE">DE</option><option value="FL">FL</option><option value="GA">GA</option><option value="HI">HI</option><option value="IA">IA</option><option value="ID">ID</option><option value="IL">IL</option><option value="IN">IN</option><option value="KS">KS</option><option value="KY">KY</option><option value="LA">LA</option><option value="MA">MA</option><option value="MD">MD</option><option value="ME">ME</option><option value="MI">MI</option><option value="MN">MN</option><option value="MO">MO</option><option value="MS">MS</option><option value="MT">MT</option><option value="NC">NC</option><option value="ND">ND</option><option value="NE">NE</option><option value="NH">NH</option><option value="NJ">NJ</option><option value="NM">NM</option><option value="NV">NV</option><option value="NY">NY</option><option value="OH">OH</option><option value="OK">OK</option><option value="OR">OR</option><option value="PA">PA</option><option value="RI">RI</option><option value="SC">SC</option><option value="SD">SD</option><option value="TN">TN</option><option value="TX">TX</option><option value="UT">UT</option><option value="VA">VA</option><option value="VT">VT</option><option value="WA">WA</option><option value="WI">WI</option><option value="WV">WV</option><option value="WY">WY</option>'; break; case 'CT': $pri_add4 = '<option value="AK">AK</option><option value="AL">AL</option><option value="AR">AR</option><option value="AZ">AZ</option><option value="CA">CA</option><option value="CO">CO</option><option value="CT" selected="selected">CT</option><option value="DC">DC</option><option value="DE">DE</option><option value="FL">FL</option><option value="GA">GA</option><option value="HI">HI</option><option value="IA">IA</option><option value="ID">ID</option><option value="IL">IL</option><option value="IN">IN</option><option value="KS">KS</option><option value="KY">KY</option><option value="LA">LA</option><option value="MA">MA</option><option value="MD">MD</option><option value="ME">ME</option><option value="MI">MI</option><option value="MN">MN</option><option value="MO">MO</option><option value="MS">MS</option><option value="MT">MT</option><option value="NC">NC</option><option value="ND">ND</option><option value="NE">NE</option><option value="NH">NH</option><option value="NJ">NJ</option><option value="NM">NM</option><option value="NV">NV</option><option value="NY">NY</option><option value="OH">OH</option><option value="OK">OK</option><option value="OR">OR</option><option value="PA">PA</option><option value="RI">RI</option><option value="SC">SC</option><option value="SD">SD</option><option value="TN">TN</option><option value="TX">TX</option><option value="UT">UT</option><option value="VA">VA</option><option value="VT">VT</option><option value="WA">WA</option><option value="WI">WI</option><option value="WV">WV</option><option value="WY">WY</option>'; break; case 'DC': $pri_add4 = '<option value="AK">AK</option><option value="AL">AL</option><option value="AR">AR</option><option value="AZ">AZ</option><option value="CA">CA</option><option value="CO">CO</option><option value="CT">CT</option><option value="DC" selected="selected">DC</option><option value="DE">DE</option><option value="FL">FL</option><option value="GA">GA</option><option value="HI">HI</option><option value="IA">IA</option><option value="ID">ID</option><option value="IL">IL</option><option value="IN">IN</option><option value="KS">KS</option><option value="KY">KY</option><option value="LA">LA</option><option value="MA">MA</option><option value="MD">MD</option><option value="ME">ME</option><option value="MI">MI</option><option value="MN">MN</option><option value="MO">MO</option><option value="MS">MS</option><option value="MT">MT</option><option value="NC">NC</option><option value="ND">ND</option><option value="NE">NE</option><option value="NH">NH</option><option value="NJ">NJ</option><option value="NM">NM</option><option value="NV">NV</option><option value="NY">NY</option><option value="OH">OH</option><option value="OK">OK</option><option value="OR">OR</option><option value="PA">PA</option><option value="RI">RI</option><option value="SC">SC</option><option value="SD">SD</option><option value="TN">TN</option><option value="TX">TX</option><option value="UT">UT</option><option value="VA">VA</option><option value="VT">VT</option><option value="WA">WA</option><option value="WI">WI</option><option value="WV">WV</option><option value="WY">WY</option>'; break; } NOTE: I had to remove a lot of the state options so the post wouldn't exceed the 40000 characters limit. I have a "switch statement" that is a bit ridiculous switch($row['warr_Ext_Term']) { case '24 month / 24,000 miles': $month24 = date('Y-m-d',strtotime($date_sold . '+730 days')); $warr_Ext_Exp_Date = substr($month24, 5, 2).'-'.substr($month24, 8, 2).'-'.substr($month24, 2, 2); $warr_Ext_Exp_Miles = number_format($row['mileage'] + 24000).' miles'; $today = date('Y-m-d'); if ($month24 > $today) { $warr_Ext_Exp_Text = 'Expires'; } else { $class = 'red'; $warr_Ext_Exp_Text = '<span class="'.$class.'">Expired</span>'; } break; } $warr_Ext_Cmpy = ' <li><label>Extended</label>'.$row['warr_Ext_Cmpy'].'</li> <li><label>Term</label>'.$row['warr_Ext_Term'].'</li> <li><label>Contract #</label>'.$row['warr_Ext_Num'].'</li> <li><label>'.$warr_Ext_Exp_Text.'</label><span class="'.$class.'">'.$warr_Ext_Exp_Date.'</span><br><label> </label><span class="'.$class.'">'.$warr_Ext_Exp_Miles.'</span></li>' ; What it does is determines when a customers warranty expires, or when it did expire based on the miles that they bought the vehicle at, and based on today's date. The problem is that I sell numerous warranties from 9 days, 4,500 miles up to 120 months, 100,000 miles. Is there a better way to write this, based on the info pulled from the "$row['warr_Ext_Term']" row? Any help would be greatly appreciated... Hi all Can I add another question statement into this? So if the string $keywords is 'Keywords' or if it's empty have an empty SQL statement? Otherwise "AND ..." Code: [Select] $keyword_search = $keywords === 'Keywords' ? '' : "AND job_title LIKE '%$keywords%' OR job_short_desc LIKE '%$keywords%' OR job_long_desc LIKE '%$keywords%'" Many thanks Pete Hey guys.. I've been making a contact form and doing the error checking. Usually this is not a problem in any other language besides php. However, it is mandatory that I use php for this. I am very good at .NET and such, but have not used much php. I am using post method and trying to do error checking for null fields. I used java and got it all to work but am having trouble putting it into php. My variables are as follows: //Define Variables $FirstName = $_POST['FirstNameTextBox']; $LastName = $_POST['LastNameTextBox']; $PhoneNumber = $_POST['PhoneNumberTextBox']; $EmailAddress = $_POST['EmailAddressTextBox']; $Address = $_POST['AddressTextBox']; $City = $_POST['CityTextBox']; $State = $_POST['StateDropDownBox']; $Zip = $_POST['ZipTextBox']; I was planning on using if else statements. For example: if(isempty($_POST['FirstNameTextBox'])) { // error } elseif($_POST['LastNameTextBox'])) //error } elseif($_POST['PhoneNumberTextBox'])) //error and so on.. I am also unsure of the actual code for the error message.. Am I correct in using this approach?? As you can see all my code is pretty much vb language. I've been researching this for a while and can not figure out the most simple way to do this using these statements. Any help you professionals can lend to a beginner is appreciated greatly! Hello Guys, I have a question about doing an IF statement in a function. Here is my code Code: [Select] function checkEmail($email){ return preg_match('/^\S+@[\w\d.-]{2,}\.[\w]{2,6}$/iU', $email) ? TRUE : FALSE; } How would I do the IF statement to test if the email is True or False? Is it like this? Code: [Select] function checkEmail($email){ return preg_match('/^\S+@[\w\d.-]{2,}\.[\w]{2,6}$/iU', $email) ? TRUE : FALSE; if ($email == "False") { Do something here } } Thanks for you help! probably a very stupid question, but i pose it because it's counterintuitive for me to write it: i find in alot of wordpress code if statements like: if ( false === $var) i suppose it's the same as if ( $var === false) ? why would one right it in the first way? Hi I need to send out +- 10 000 statements to our customers. How do I prevent from being marked as a spammer? I think the daily limit is 500. Should I use a public smtp? Thanks Jay Morning, I'm working on a web site using a switch to separate different calls from a MySQL database. My style looks like this: <?php switch ($_GET['page']) { case 'news': echo ("NEWS HERE"); } break; case 'schedule'; echo ("SCHEDULE HERE"); } break; default: echo ("MAIN PAGE HERE"); break; } What I am trying to do, is specify that if the page is news, there can be an additional variable for id. I attempted before and after the break; for the news case, to make a new switch, but it isn't taking. I've looked around online, but can't find any information about this. Can anyone offer a hand? Hi and thanks for taking the time to read through this first and foremost. I have a bit of code that I have managed to piece together with help from other sites and what it does is connect to our local ms sql server and retrieve a few tables from our database. The info is relating to property management and it basically displays the unit address, current date and its rental status. (Occupied or Vacant) This makes it easy for us to at a glance check the status of our rentals instead of having to log into our software and navigate through all that.. anyways, I have two issues I need help with. First problem, in my code, is it possible to write a conditional statement that would check for a certain status in a view and then if it is there, print a simple yes or no in a table with that appropriate property. For example, we have property 1000 name street and it is currently vacant, however the viewPendingLease shows us information regarding future bookings. I would like to be able to look through that view with the code, check property 1000 name street for any future pending leases, and if there is one, print out a "Yes" in a Future Booked column that I would create. If any of that makes sense, I can post the print out of the tables of the viewPendingLease if it makes it easier for anyone to see the data output to understand what I am meaning. The second issue, is it possible to change the color of the text according to a variable, say a word in a generated table with html or css? I would like to color the words vacant or occupied green and red respectively just to make it much easier to zero in on the vacant properties. Or even maybe just color every other row a background color just to help distinguish between the different properties. Here is my code that pulls up my current tables to show Property, Street and current rented status. Code: [Select] <?php //connect to a DSN "*******" $conn = odbc_connect('*******','*****','************'); if ($conn) { //the SQL statement that will query the database $query = "Select unit.PropertyUnitID, unit.Street, unit.Status, from unit"; //perform the query $result=odbc_exec($conn, $query); echo "<table border=\"1\"><tr>"; //print field name $colName = odbc_num_fields($result); for ($j=1; $j<= $colName; $j++) { echo "<th>"; echo odbc_field_name ($result, $j ); echo "</th>"; } //fetch tha data from the database while(odbc_fetch_row($result)) { echo "<tr>"; for($i=1;$i<=odbc_num_fields($result);$i++) { echo "<td>"; echo odbc_result($result,$i); echo "</td>"; } echo "</tr>"; } echo "</td> </tr>"; echo "</table >"; //close the connection odbc_close ($conn); } else echo "odbc not connected"; ?> I currently have the viewPendingLease.Active (which shows if there is a future pending lease) taken out due to a repeating data issue I am also trying to figure out... I'm having issues with the following: Code: [Select] <?php session_start(); $_SESSION['username']=$_POST['username']; $_SESSION['password']=$_POST['password']; if($_SESSION['username']=="username" && $_SESSION['password']=="password"){ if($_GET['product']=="add"){ $content.=' <p><label>Product Name:</label> <input type="text" name="product_name" size="30" /> <label>Product Price:</label> <input type="text" name="product_price" size="5" /> </p> <p><label>Product Category:</label> <input type="text" name="product_category" size="30" /></p> <p><label>Product Link:</label> <input type="text" name="product_link" size="30" /></p> <p><label>Product Image:</label> <input type="text" name="product_image" size="30" /></p> <p><label>Product Tag:</label> <input type="text" name="product_tag" size="30" /></p> <p><label>Product Keywords:</label> <input type="text" name="keyword" size="30" /></p> <p><label>Product Features:</label><br /> <textarea name="product_features" rows="10" cols="60"></textarea> </p> <p><label>Product Pros:</label><br /> <textarea name="product_pros" rows="5" cols="30"></textarea> </p> <p><label>Product Cons:</label><br /> <textarea name="product_cons" rows="5" cols="30"></textarea> </p> <p><label>Product Description:</label><br /> <textarea name="product_description" rows="10" cols="60"></textarea> </p> <p><label>Product Notes:</label><br /> <textarea name="product_notes" rows="5" cols="30"></textarea> </p> '; $logout='<div><a href="./acp_admincp.php?log-out">Log-Out</a></div>'; } elseif($_GET['product']=="view"){ } else{ $content.=' <a href="./admincp.php?product=add">Add New Product</a> <br /> <a href="./admincp.php?product=view">View Products</a> '; } } elseif(isset($_GET['log-out'])){ session_start(); session_unset(); session_destroy(); header("Location: ./admincp.php"); } else{ $content=' <form action="./admincp.php" method="post"> <p><label>Username:</label> <input type="text" name="username" size="30" />'; $content.='</p> <p><label>Password:</label> <input type="password" name="password" /></p>'; $content.='<p><input type="submit" value="Submit" name="Submit" /></p> </form>'; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <base href="http://ghosthuntersportal.com/" /> <title>Ghost Hunter's Portal - Admin Control Panel</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="verify-v1" content="" /> <meta name="keywords" content="ghost, hunters, hunter, ghosts, spirit, spirits, paranormal, investigation, investigator, investigators, k2, emf, meter, kii" /> <meta name="description" content="Ghost Hunters Potal. Parnormal research equipment store." /> <meta name="author" content="Andrew McCarrick" /> <meta name="robots" content="index, follow" <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <img src="./logo.png" alt="Ghost Hunter's Portal Admin Control Panel" /> <br /> <div style="color: #AA44AA; font-size: 26px; margin-top: -30px; margin-left: 125px;">Admin Control Panel</div> <?php echo $logout; echo $content; ?> </body> </html> I can log-in, and get to the page with the two links on it. However, once I click one of the links it falls back to the log-in page, and it ends up being a never ending loop. It's doing this: Log-In --> Page with links ---> Log-In page again Should be doing this: Log-In --> Page with links --> Add Product page or View Products page I can never get into the the actual sub page. Just to be clear, the address bar actually shows product=add or product=view, but it still shows the log-in page. |