PHP - Variables Within A Switch Statement
$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. 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. 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? 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 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"; } 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... I am new to PHP and am currently learning the ropes. I have writen some code to insert a line into a mySQL database. I have created 3 fields in the mySQL database and am passing values two them. I can use a declared variable to pass information to the filed ID (Index filed in mySQL) but if I use a variable to pass purely text values the database is not updated. mysql_query( "INSERT INTO $tbl_name (category_Name, ID, test) VALUES ($category, $internalId, $category2)" ); If I replace the variables with specific text, the rows are added successfully. mysql_query( "INSERT INTO $tbl_name (category_Name, ID, test) VALUES ('werwerwer', $internalId, 'werrr')" ); It must be something stupid, I am sure. Full code below ob_start(); $host="localhost:8888"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name="expenses"; // Database name $tbl_name="expense_category"; // Table name $category="test3"; $internalId="7"; $category2="test3"; // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); mysql_query( "INSERT INTO $tbl_name (category_Name, ID, test) VALUES ('werwerwer', $internalId, 'werrr')" ); echo "Done now 6!"; ?> 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... Hello,
I have problem durring binding update query. I can't find what is causing problem.
public function Update(Entry $e) { try { $query = "update entry set string = $e->string,delimiter=$e->delimiter where entryid= $e->id"; $stmt = $this->db->mysqli->prepare($query); $stmt->bind_param('ssi',$e->string,$e->delimiter,$e->id); $stmt->close(); } catch(Exception $ex) { print 'Error: ' .$ex->getMessage(); } }When I run function update I'm getting next error:Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement Can you help me to solve this problem ? Edited by danchi, 17 October 2014 - 10:25 AM. 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? 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. 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>'; Here is my dilemma. I'm trying to get the "class name" to return instead of the number that is associated with it. I wrote a switch so that each of the 16 cases would be associated with what the class name is. However, how do I make it output into my statement? Here is what I have so far: function getClassByNumber($x){ switch($x){ case 1: return "Alchemist"; case 2: return "Assassin"; case 3: return "Dark Arts"; case 4: return "Dark Paladin"; case 5: return "Entertainer"; case 6: return "Hunter"; case 7: return "Mage"; case 8: return "Monk"; case 9: return "Paladin"; case 10: return "Pirate"; case 11: return "Priest"; case 12: return "Psion"; case 13: return "Scholar"; case 14: return "Thief"; case 15: return "Warlock"; case 16: return "Warrior"; } } $class = getClassByNumber($username->class); echo You are now a $class. Username is defined as seeking the table I want. Class is the field where the number is stored. Thanks! 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'){ }elseif ($_GET['action']=='edit_ok'){ } switch($_GET['action']){ case 'write_ok'; $sql="INSERT INTO project_data (Date_Of_Birth, Gender, Title, First_Name, Last_Name, Address_Line_1, Address_Line_2, City, Postcode, Contact_No, Email, Additional_Comment) VALUES ('".$_POST[dateofbirth]."','".$_POST[gender]."','".$_POST[title]."','".$_POST[firstname]."','".$_POST[lastname]."','".$_POST[address1]."','".$_POST[address2]."','".$_POST[city]."','".$_POST[postcode]."','".$_POST[contactno]."','".$_POST[email]."','".$_POST[note]."')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }else{ echo '<script>alert("Data Has Been Successfully Updated");</script>'; echo '<meta http-equiv="Refresh" content="0;URL=switch.php">'; } break; case 'edit_ok'; if ((!isset($_GET['id']) || trim($_GET['id']) == '')) { die('Missing record ID!'); } $id= $_GET['id']; mysql_query("UPDATE project_data SET Date_Of_Birth='".$_POST[dateofbirth]."',Gender='".$_POST[gender]."',Title='".$_POST[title]."',First_Name='".$_POST[firstname]."',Last_Name='".$_POST[surname]."',Address_Line_1='".$_POST[address1]."',Address_Line_2='".$_POST[address2]."',City='".$_POST[city]."',Postcode='".$_POST[postcode]."',Contact_No='".$_POST[contactno]."',Email='".$_POST[email]."',Additional_Comment='".$_POST[note]."' WHERE ID='".$_GET['id']. "'") or die ("Error in query: $query. " . mysql_error()); echo '<script>alert("Data Has Been Successfully Updated");</script>'; echo '<meta http-equiv="Refresh" content="0;URL=switch.php">'; } break; case 'delete_ok': #########Delete OK Start################# $id= $_GET['id']; $result = mysql_query("DELETE FROM project_data WHERE ID = '$id'") or die ("Error in query: $query. " . mysql_error()); echo '<script>alert("Data Has Been Successfully Updated");</script>'; echo '<meta http-equiv="Refresh" content="0;URL=switch.php">'; } #########Delete OK End ################# break; } ?> <!--HTML--> <?php switch($_GET['action']){ case 'delete'; break; case 'edit'; echo 'Edit page'; ?> <?php $id=$_GET['id']; $result = mysql_query("SELECT * FROM project_data WHERE id='$id'"); $row = mysql_fetch_array($result); ?> <table border = "1"> <form action="switch.php?id=<?php echo $row['ID']?> action=edit_ok" method="post"> <tr> <td>Date Of Birth</td> <td><input type="text" name="dateofbirth" value="<?php echo $row['Date_Of_Birth']?>"/></td> </tr> <tr> <td>Gender</td> <td><input type="radio" name="gender" value="male" <?php if($row['Gender']=='male'){echo 'checked';}?>/> Male<input type="radio" name="gender" value="female" <?php if($row['Gender']=='female'){echo 'checked';}?>/> Female</td> </tr> <tr> <td>Title</td> <td><select name="title"> <option value="">Please Select</option> <option value="Mr" <?php if($row['Title']=='Mr'){echo 'selected';}?>>Mr</option> <option value="Ms" <?php if($row['Title']=='Ms'){echo 'selected';}?>>Ms</option> <option value="Mrs" <?php if($row['Title']=='Mrs'){echo 'selected';}?>>Mrs</option> <option value="Miss" <?php if($row['Title']=='Miss'){echo 'selected';}?>>Miss</option> <option value="Other" <?php if($row['Title']=='Other'){echo 'selected';}?>>Other</option> </select></td> </tr> <tr> <td>First Name</td> <td><input type="text" name="firstname" value="<?php echo $row['First_Name']?>"/></td> </tr> <tr> <td>Last Name</td> <td><input type="text" name="lastname" value="<?php echo $row['Last_Name']?>" /></td> </tr> <tr> <td>Address Line 1</td> <td><input type="text" name="address1" value="<?php echo $row['Address_Line_1']?>" /></td> </tr> <tr> <td>Address Line 2</td> <td><input type="text" name="address2" value="<?php echo $row['Address_Line_2']?>" /></td> </tr> <tr> <td>City</td> <td><input type="text" name="postcode" value="<?php echo $row['City']?>" /></td> </tr> <tr> <td>Postcode</td> <td><input type="text" name="postcode" value="<?php echo $row['Postcode']?>" /></td> </tr> <tr> <td>Contact No</td> <td><input type="text" name="contactno" value="<?php echo $row['Contact_No']?>" /></td> </tr> <tr> <td>Email</td> <td><input type="text" name="email" value="<?php echo $row['Email']?>"/></td> </tr> <tr> <td>Additional Info</td> <td><textarea rows="10" cols="30" name="note"><?php echo $row['Additional_Comment']?></textarea></td> </tr> <tr> <td><input type="submit" value="Edit" /></td> <td><a href='switch.php'>Back</a></td> </tr> </table> </form> <?php break; case 'write'; ?> <form action="switch.php?action=write_ok" method="post"> <table> <tr> <td>Date Of Birth</td> <td><input type="text" name="dateofbirth" /></td> </tr> <tr> <td>Gender</td> <td><input type="radio" name="gender" value="male" />Male<input type="radio" name="gender" value="female" /> Female</td> </tr> <tr> <td>Title</td> <td><select name="title"> <option value="" selected="selcted">Please Select</option> <option value="Mr">Mr</option> <option value="Mrs">Mrs</option> <option value="Miss">Miss</option> <option value="Ms">Ms</option> <option value="Other">Other</option> </select></td> </tr> <tr> <td>First Name</td> <td><input type="text" name="firstname" /></td> </tr> <tr> <td>Last Name</td> <td><input type="text" name="lastname" /></td> </tr> <tr> <td>Address Line 1</td> <td><input type="text" name="address1" /></td> </tr> <tr> <td>Address Line 2</td> <td><input type="text" name="address2" /></td> </tr> <tr> <td>City</td> <td><input type="text" name="city" /></td> </tr> <tr> <td>Postcode</td> <td><input type="text" name="postcode" /></td> </tr> <tr> <td>Contact No</td> <td><input type="text" name="contactno" /></td> </tr> <tr> <td>Email</td> <td><input type="text" name="email" /></td> </tr> <tr> <td>Additional Info</td> <td><textarea rows="15" cols="30" name="note">Please Enter Any Additional Information</textarea></td> </tr> <tr> <td><input type="submit" value="Submit"></td> <td><a href='switch.php'>Back</a></td> </tr> </table> </form> <?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='switch.php?action=delete&id=" . $row['ID']."'>Delete</a></td>"; echo "</tr>"; } echo "</table>"; echo "<a href='switch.php?action=write'>Insert</a>"; } mysql_close($con); ?> Here is the completed code, but I still have a problem the page is coming up with an error: ( ! ) Fatal error: Cannot break/continue 1 level in C:\wamp\www\p1\switch.php on line 63 Call Stack # Time Memory Function Location 1 0.0009 413960 {main}( ) ..\switch.php:0 I cannot seem to figure it out, Can anyone help? Thanks Code: [Select] <?php switch($_GET['action']){ case 'delete': break; case 'edit': case 'write': if($action=='edit'){ $form_action = 'edit_ok'; echo 'Edit Page'; }else{ $form_action = 'write_ok'; echo 'Write Page'; } ?> <?php $id=$_GET['id']; $result = mysql_query("SELECT * FROM project_data WHERE id='$id'"); $row = mysql_fetch_array($result); ?> <table border = "1"> <form action="switch.php?id=<?php echo $row['ID']?>&action=[color=purple][b]<?php echo $action ?>[/b][/color]" method="post"> <tr> <td>Date Of Birth</td> <td><input type="text" name="dateofbirth" value="<?php echo $row['Date_Of_Birth']?>"/></td> </tr> <tr> <td>Gender</td> <td><input type="radio" name="gender" value="male" <?php if($row['Gender']=='male'){echo 'checked';}?>/> Male<input type="radio" name="gender" value="female" <?php if($row['Gender']=='female'){echo 'checked';}?>/> Female</td> </tr> <tr> <td>Title</td> <td><select name="title"> <option value="">Please Select</option> <option value="Mr" <?php if($row['Title']=='Mr'){echo 'selected';}?>>Mr</option> <option value="Ms" <?php if($row['Title']=='Ms'){echo 'selected';}?>>Ms</option> <option value="Mrs" <?php if($row['Title']=='Mrs'){echo 'selected';}?>>Mrs</option> <option value="Miss" <?php if($row['Title']=='Miss'){echo 'selected';}?>>Miss</option> <option value="Other" <?php if($row['Title']=='Other'){echo 'selected';}?>>Other</option> </select></td> </tr> <tr> <td>First Name</td> <td><input type="text" name="firstname" value="<?php echo $row['First_Name']?>"/></td> </tr> <tr> <td>Last Name</td> <td><input type="text" name="lastname" value="<?php echo $row['Last_Name']?>" /></td> </tr> <tr> <td>Address Line 1</td> <td><input type="text" name="address1" value="<?php echo $row['Address_Line_1']?>" /></td> </tr> <tr> <td>Address Line 2</td> <td><input type="text" name="address2" value="<?php echo $row['Address_Line_2']?>" /></td> </tr> <tr> <td>City</td> <td><input type="text" name="postcode" value="<?php echo $row['City']?>" /></td> </tr> <tr> <td>Postcode</td> <td><input type="text" name="postcode" value="<?php echo $row['Postcode']?>" /></td> </tr> <tr> <td>Contact No</td> <td><input type="text" name="contactno" value="<?php echo $row['Contact_No']?>" /></td> </tr> <tr> <td>Email</td> <td><input type="text" name="email" value="<?php echo $row['Email']?>"/></td> </tr> <tr> <td>Additional Info</td> <td><textarea rows="10" cols="30" name="note"><?php echo $row['Additional_Comment']?></textarea></td> </tr> <tr> <td><input type="submit" value="Update" /></td> <td><a href='switch.php'>Main Page</a></td> </tr> </table> </form> <?php break; //case 'write'; ?> <!--<table border = "1"> <form action="switch.php?action=write_ok" method="post"> <table> <tr> <td>Date Of Birth</td> <td><input type="text" name="dateofbirth" /></td> </tr> <tr> <td>Gender</td> <td><input type="radio" name="gender" value="male" />Male<input type="radio" name="gender" value="female" /> Female</td> </tr> <tr> <td>Title</td> <td><select name="title"> <option value="" selected="selcted">Please Select</option> <option value="Mr">Mr</option> <option value="Mrs">Mrs</option> <option value="Miss">Miss</option> <option value="Ms">Ms</option> <option value="Other">Other</option> </select></td> </tr> <tr> <td>First Name</td> <td><input type="text" name="firstname" /></td> </tr> <tr> <td>Last Name</td> <td><input type="text" name="lastname" /></td> </tr> <tr> <td>Address Line 1</td> <td><input type="text" name="address1" /></td> </tr> <tr> <td>Address Line 2</td> <td><input type="text" name="address2" /></td> </tr> <tr> <td>City</td> <td><input type="text" name="city" /></td> </tr> <tr> <td>Postcode</td> <td><input type="text" name="postcode" /></td> </tr> <tr> <td>Contact No</td> <td><input type="text" name="contactno" /></td> </tr> <tr> <td>Email</td> <td><input type="text" name="email" /></td> </tr> <tr> <td>Additional Info</td> <td><textarea rows="15" cols="30" name="note">Please Enter Any Additional Information</textarea></td> </tr> <tr> <td><input type="submit" value="Submit"></td> <td><a href='switch.php'>Back</a></td> </tr> </table> </form>--> <?php //break; I have this code, which is basically a form for inputting and another for editing. As you can see I have made one part a comment as I want just the edit part to control the input and edit, which is shown at the very beginning with write case, and the seperate edit case, all I need to complete it is the part that I have highlighted in purple/bold. Does anybody have any help? |