PHP - Oop Problem (small)
the problem im getting is with this line in the bootstrap
Code: [Select] $this->view->head_title('test'); the view property is only initiated in the league_controller and $this->view doesnt exsist within the bootstap but i call the bootstrap header in the league controller and it wont let me execute the head title...if anyone can help me on why or how i can over come this please....thank you (code below) bootstrap Code: [Select] public static function header() { $this->view->head_title('test'); } leaugue_controller method Code: [Select] public function league($game_name, $league_name) { Bootstrap::header(); $rows = $this->leagues->fetch_league($game_name, $league_name); $this->view->head_title()->set_separator()->prepend('hello'); $this->view->rows = $rows; Bootstrap::footer(); } Similar TutorialsI have made a php cart : check it out on http://fhcs.be/cart-demo4/ My question is: when I order something by clicking on the "voeg toe" button, I'm redirected to the shopping cart. But I don't want to be redirected to the shopping cart, I want to stay on de menu list. What is an easy way to fix this? thanks people index.php Code: [Select] <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>PHP Shopping Cart Demo · Bookshop</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingcart"> <h1>Welkom, plaats uw order</h1> </div> <div id="booklist"> <h1>Warme dranken</h1> <?php $sql = 'SELECT * FROM products WHERE cat=2'; $result1 = $db->query($sql); $output1[] = '<ul>'; while ($row = $result1->fetch()) { $output1[] = '<li>'.$row['name'].': €'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Voeg Toe</a></li>'; } $output1[] = '</ul>'; echo join('',$output1); ?> <h1>Cocktails</h1> <?php $sql = 'SELECT * FROM products WHERE cat=3'; $result2 = $db->query($sql); $output2[] = '<ul>'; while ($row = $result2->fetch()) { $output2[] = '<li>'.$row['name'].': €'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Voeg Toe</a></li>'; } $output2[] = '</ul>'; echo join('',$output2); ?> </div> </body> cart.php Code: [Select] <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session session_start(); // Process actions $cart = $_SESSION['cart']; $action = $_GET['action']; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; case 'delete': if ($cart) { $items = explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($_GET['id'] != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } $cart = $newcart; } break; case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=>$value) { if (stristr($key,'qty')) { $id = str_replace('qty','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break; } $_SESSION['cart'] = $cart; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>PHP Shopping Cart Demo · Cart</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingcart"> <h1>Uw bestelling</h1> <?php echo writeShoppingCart(); ?> </div> <div id="contents"> <h2>Gelieve na te kijken voordat u bestelt</h2> <?php echo showCart(); ?> <p><a href="index.php">Terug naar lijst</a></p> <form action="mail.php" method="post"> <input type="submit" name="sendemail" value="Bestel" /> <input type="hidden" name="cart" value="<?= $cart; ?>" /> </form> </div> </body> </html> Okay, I am writing a new form validation script that also keeps the data so it can re-populate the fields the user already filled out if there is an error on the page so they do not have to fill it out again. Here is an example of the code I am using in the HTML part of the form input elements. <input name="name" type="text" id="name" value="<?php=$fields['name']?>"> Now, the problem I am getting is the <?php=$fields['name']?> code is being physically displayed within the form field at all times. How would I go about having it not display this line of code in the field? Thanks!! echo "<tr> <td class='trow2' align='center' valign='center' width='1'></td> <td class='trow2' valign='center'> <strong><a href='server.php?view=details&id=" . $list['id'] . "'>" . capitalizeFirstCharacter($list['servername']) . "</a></strong> <div class=\"stat2\"> <div class=\"stat\"> if(!$sock=@fsockopen($list_f['serverip'],$list_f['serverport'], $num, $error, 1)) { echo "<font color='red'><b>Offline</b></font>"; } else { echo "<font color='green'><b>Online</b></font>"; } </div> </div> <div class='smalltext'>" . $list['shortdescription'] . "</div> </td> <td class='trow1' valign='middle' align='left' style='white-space: nowrap'><span class='smalltext'>" . $list['revision'] . "</span></td> <td class='trow2' valign='middle' align='right' style='white-space: nowrap'><font size='4px'>" . $voteAmount . " Votes</font></td> </tr>"; How can I make this echo code work? <?php // SQL Connection $username="root"; $password=""; $database="mydb"; $connection = mysql_connect("localhost", $username, $password) or die("Connection Failure to Database"); // Select Database mysql_select_db($database, $connection) or die ($database . "No Database" . $username); $id = $_GET['id']; $MyQuery = "SELECT * FROM bookings WHERE id = '$id'"; $retrieve = mysql_query($MyQuery) or die(mysql_error()); if(mysql_num_rows($retrieve) != 0): $row = mysql_fetch_assoc($retrieve); endif; $idX = ($row['id']); echo $idX; if(mysql_num_rows($retrieve) == 0) { echo '<blink><font color="red"><strong>No Booking Found</strong></font></blink>'; } else { echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">'; echo '<table width="350">'; echo ' <tr>'; echo ' <td width="100">Full Name</td>'; echo ' <td width="100"><input style="width: 235px" value="' . ($row['fullname']) . '" type="text" name="fullname"></td>'; echo ' </tr>'; echo ' <tr>'; echo ' <td width="100">Address</td>'; echo ' <td width="100"><input style="width: 235px" value="' . ($row['address']) . '" type="text" name="address"></td>'; echo ' </tr>'; echo ' <tr>'; echo ' <td width="100">City</td>'; echo ' <td width="100"><input style="width: 235px" value="' . ($row['city']) . '" type="text" name="city"></td>'; echo ' <tr>'; echo ' <td width="100">Postcode</td>'; echo ' <td width="100"><input style="width: 235px" value="' . ($row['postcode']) . '" type="text" name="postcode"></td>'; echo ' </tr>'; echo ' <tr>'; echo ' <td width="100">Country</td>'; echo ' <td width="100"><select style="width: 235px" name="country">'; echo ' <option value="' . ($row['country']) . '">' . ($row['country']) . '</option>'; echo ' <option></option><option value="Abkhazia">Abkhazia</option><option value="Afghanistan">Afghanistan</option><option value="Aland">Aland</option><option value="Albania">Albania</option><option value="Algeria">Algeria</option><option value="American Samoa">American Samoa</option><option value="Andorra">Andorra</option><option value="Angola">Angola</option><option value="Anguilla">Anguilla</option><option value="Antarctica">Antarctica</option><option value="Antigua and Barbuda">Antigua and Barbuda</option><option value="Argentina">Argentina</option><option value="Armenia">Armenia</option><option value="Aruba">Aruba</option><option value="Ascension">Ascension</option><option value="Ashmore and Cartier Islands">Ashmore and Cartier Islands</option><option value="Australia">Australia</option><option value="Australian Antarctic Territory">Australian Antarctic Territory</option><option value="Austria">Austria</option><option value="Azerbaijan">Azerbaijan</option><option value="Bahamas, The">Bahamas, The</option><option value="Bahrain">Bahrain</option><option value="Baker Island">Baker Island</option><option value="Bangladesh">Bangladesh</option><option value="Barbados">Barbados</option><option value="Belarus">Belarus</option><option value="Belgium">Belgium</option><option value="Belize">Belize</option><option value="Benin">Benin</option><option value="Bermuda">Bermuda</option><option value="Bhutan">Bhutan</option><option value="Bolivia">Bolivia</option><option value="Bosnia and Herzegovina">Bosnia and Herzegovina</option><option value="Botswana">Botswana</option><option value="Bouvet Island">Bouvet Island</option><option value="Brazil">Brazil</option><option value="British Antarctic Territory">British Antarctic Territory</option><option value="British Indian Ocean Territory">British Indian Ocean Territory</option><option value="British Sovereign Base Areas">British Sovereign Base Areas</option><option value="British Virgin Islands">British Virgin Islands</option><option value="Brunei">Brunei</option><option value="Bulgaria">Bulgaria</option><option value="Burkina Faso">Burkina Faso</option><option value="Burundi">Burundi</option><option value="Cambodia">Cambodia</option><option value="Cameroon">Cameroon</option><option value="Canada">Canada</option><option value="Cape Verde">Cape Verde</option><option value="Cayman Islands">Cayman Islands</option><option value="Central African Republic">Central African Republic</option><option value="Chad">Chad</option><option value="Chile">Chile</option><option value="China, Peoples Republic of">China, Peoples Republic of</option><option value="China, Republic of (Taiwan)">China, Republic of (Taiwan)</option><option value="Christmas Island">Christmas Island</option><option value="Clipperton Island">Clipperton Island</option><option value="Cocos (Keeling) Islands">Cocos (Keeling) Islands</option><option value="Colombia">Colombia</option><option value="Comoros">Comoros</option><option value="Congo, Democratic Republic of the (Congo Kinshasa)">Congo, Democratic Republic of the (Congo Kinshasa)</option><option value="Congo, Republic of the (Congo Brazzaville)">Congo, Republic of the (Congo Brazzaville)</option><option value="Cook Islands">Cook Islands</option><option value="Coral Sea Islands">Coral Sea Islands</option><option value="Costa Rica">Costa Rica</option><option value="Cote dIvoire (Ivory Coast)">Cote dIvoire (Ivory Coast)</option><option value="Croatia">Croatia</option><option value="Cuba">Cuba</option><option value="Cyprus">Cyprus</option><option value="Czech Republic">Czech Republic</option><option value="Denmark">Denmark</option><option value="Djibouti">Djibouti</option><option value="Dominica">Dominica</option><option value="Dominican Republic">Dominican Republic</option><option value="Ecuador">Ecuador</option><option value="Egypt">Egypt</option><option value="El Salvador">El Salvador</option><option value="Equatorial Guinea">Equatorial Guinea</option><option value="Eritrea">Eritrea</option><option value="Estonia">Estonia</option><option value="Ethiopia">Ethiopia</option><option value="Falkland Islands (Islas Malvinas)">Falkland Islands (Islas Malvinas)</option><option value="Faroe Islands">Faroe Islands</option><option value="Fiji">Fiji</option><option value="Finland">Finland</option><option value="France">France</option><option value="French Guiana">French Guiana</option><option value="French Polynesia">French Polynesia</option><option value="French Scattered Islands in the Indian Ocean">French Scattered Islands in the Indian Ocean</option><option value="French Southern and Antarctic Lands">French Southern and Antarctic Lands</option><option value="Gabon">Gabon</option><option value="Gambia, The">Gambia, The</option><option value="Georgia">Georgia</option><option value="Germany">Germany</option><option value="Ghana">Ghana</option><option value="Gibraltar">Gibraltar</option><option value="Greece">Greece</option><option value="Greenland">Greenland</option><option value="Grenada">Grenada</option><option value="Guadeloupe">Guadeloupe</option><option value="Guam">Guam</option><option value="Guatemala">Guatemala</option><option value="Guernsey">Guernsey</option><option value="Guinea">Guinea</option><option value="Guinea-Bissau">Guinea-Bissau</option><option value="Guyana">Guyana</option><option value="Haiti">Haiti</option><option value="Heard Island and McDonald Islands">Heard Island and McDonald Islands</option><option value="Honduras">Honduras</option><option value="Hong Kong">Hong Kong</option><option value="Howland Island">Howland Island</option><option value="Hungary">Hungary</option><option value="Iceland">Iceland</option><option value="India">India</option><option value="Indonesia">Indonesia</option><option value="Iran">Iran</option><option value="Iraq">Iraq</option><option value="Ireland">Ireland</option><option value="Isle of Man">Isle of Man</option><option value="Israel">Israel</option><option value="Italy">Italy</option><option value="Jamaica">Jamaica</option><option value="Japan">Japan</option><option value="Jarvis Island">Jarvis Island</option><option value="Jersey">Jersey</option><option value="Johnston Atoll">Johnston Atoll</option><option value="Jordan">Jordan</option><option value="Kazakhstan">Kazakhstan</option><option value="Kenya">Kenya</option><option value="Kingman Reef">Kingman Reef</option><option value="Kiribati">Kiribati</option><option value="Korea, Democratic Peoples Republic of (North Korea)">Korea, Democratic Peoples Republic of (North Korea)</option><option value="Korea, Republic of (South Korea)">Korea, Republic of (South Korea)</option><option value="Kosovo">Kosovo</option><option value="Kuwait">Kuwait</option><option value="Kyrgyzstan">Kyrgyzstan</option><option value="Laos">Laos</option><option value="Latvia">Latvia</option><option value="Lebanon">Lebanon</option><option value="Lesotho">Lesotho</option><option value="Liberia">Liberia</option><option value="Libya">Libya</option><option value="Liechtenstein">Liechtenstein</option><option value="Lithuania">Lithuania</option><option value="Luxembourg">Luxembourg</option><option value="Macau">Macau</option><option value="Macedonia">Macedonia</option><option value="Madagascar">Madagascar</option><option value="Malawi">Malawi</option><option value="Malaysia">Malaysia</option><option value="Maldives">Maldives</option><option value="Mali">Mali</option><option value="Malta">Malta</option><option value="Marshall Islands">Marshall Islands</option><option value="Martinique">Martinique</option><option value="Mauritania">Mauritania</option><option value="Mauritius">Mauritius</option><option value="Mayotte">Mayotte</option><option value="Mexico">Mexico</option><option value="Micronesia">Micronesia</option><option value="Midway Islands">Midway Islands</option><option value="Moldova">Moldova</option><option value="Monaco">Monaco</option><option value="Mongolia">Mongolia</option><option value="Montenegro">Montenegro</option><option value="Montserrat">Montserrat</option><option value="Morocco">Morocco</option><option value="Mozambique">Mozambique</option><option value="Myanmar (Burma)">Myanmar (Burma)</option><option value="Nagorno-Karabakh">Nagorno-Karabakh</option><option value="Namibia">Namibia</option><option value="Nauru">Nauru</option><option value="Navassa Island">Navassa Island</option><option value="Nepal">Nepal</option><option value="Netherlands">Netherlands</option><option value="Netherlands Antilles">Netherlands Antilles</option><option value="New Caledonia">New Caledonia</option><option value="New Zealand">New Zealand</option><option value="Nicaragua">Nicaragua</option><option value="Niger">Niger</option><option value="Nigeria">Nigeria</option><option value="Niue">Niue</option><option value="Norfolk Island">Norfolk Island</option><option value="Northern Cyprus">Northern Cyprus</option><option value="Northern Mariana Islands">Northern Mariana Islands</option><option value="Norway">Norway</option><option value="Oman">Oman</option><option value="Pakistan">Pakistan</option><option value="Palau">Palau</option><option value="Palestine">Palestine</option><option value="Palmyra Atoll">Palmyra Atoll</option><option value="Panama">Panama</option><option value="Papua New Guinea">Papua New Guinea</option><option value="Paraguay">Paraguay</option><option value="Peru">Peru</option><option value="Peter I Island">Peter I Island</option><option value="Philippines">Philippines</option><option value="Pitcairn Islands">Pitcairn Islands</option><option value="Poland">Poland</option><option value="Portugal">Portugal</option><option value="Pridnestrovie (Transnistria)">Pridnestrovie (Transnistria)</option><option value="Puerto Rico">Puerto Rico</option><option value="Qatar">Qatar</option><option value="Queen Maud Land">Queen Maud Land</option><option value="Reunion">Reunion</option><option value="Romania">Romania</option><option value="Ross Dependency">Ross Dependency</option><option value="Russia">Russia</option><option value="Rwanda">Rwanda</option><option value="Saint Helena">Saint Helena</option><option value="Saint Kitts and Nevis">Saint Kitts and Nevis</option><option value="Saint Lucia">Saint Lucia</option><option value="Saint Pierre and Miquelon">Saint Pierre and Miquelon</option><option value="Saint Vincent and the Grenadines">Saint Vincent and the Grenadines</option><option value="Samoa">Samoa</option><option value="San Marino">San Marino</option><option value="Sao Tome and Principe">Sao Tome and Principe</option><option value="Saudi Arabia">Saudi Arabia</option><option value="Senegal">Senegal</option><option value="Serbia">Serbia</option><option value="Seychelles">Seychelles</option><option value="Sierra Leone">Sierra Leone</option><option value="Singapore">Singapore</option><option value="Slovakia">Slovakia</option><option value="Slovenia">Slovenia</option><option value="Solomon Islands">Solomon Islands</option><option value="Somalia">Somalia</option><option value="Somaliland">Somaliland</option><option value="South Africa">South Africa</option><option value="South Georgia and the South Sandwich Islands">South Georgia and the South Sandwich Islands</option><option value="South Ossetia">South Ossetia</option><option value="Spain">Spain</option><option value="Sri Lanka">Sri Lanka</option><option value="Sudan">Sudan</option><option value="Suriname">Suriname</option><option value="Svalbard">Svalbard</option><option value="Swaziland">Swaziland</option><option value="Sweden">Sweden</option><option value="Switzerland">Switzerland</option><option value="Syria">Syria</option><option value="Tajikistan">Tajikistan</option><option value="Tanzania">Tanzania</option><option value="Thailand">Thailand</option><option value="Timor-Leste (East Timor)">Timor-Leste (East Timor)</option><option value="Togo">Togo</option><option value="Tokelau">Tokelau</option><option value="Tonga">Tonga</option><option value="Trinidad and Tobago">Trinidad and Tobago</option><option value="Tristan da Cunha">Tristan da Cunha</option><option value="Tunisia">Tunisia</option><option value="Turkey">Turkey</option><option value="Turkmenistan">Turkmenistan</option><option value="Turks and Caicos Islands">Turks and Caicos Islands</option><option value="Tuvalu">Tuvalu</option><option value="U.S. Virgin Islands">U.S. Virgin Islands</option><option value="Uganda">Uganda</option><option value="Ukraine">Ukraine</option><option value="United Arab Emirates">United Arab Emirates</option><option value="United Kingdom">United Kingdom</option><option value="United States">United States</option><option value="Uruguay">Uruguay</option><option value="Uzbekistan">Uzbekistan</option><option value="Vanuatu">Vanuatu</option><option value="Vatican City">Vatican City</option><option value="Venezuela">Venezuela</option><option value="Viet Nam">Viet Nam</option><option value="Wake Island">Wake Island</option><option value="Wallis and Futuna">Wallis and Futuna</option><option value="Western Sahara">Western Sahara</option><option value="Yemen">Yemen</option><option value="Zambia">Zambia</option><option value="Zimbabwe">Zimbabwe</option></SELECT></td>'; echo ' </tr>'; echo ' <tr>'; echo ' <td width="100">Tel</td>'; echo ' <td width="100"><input style="width: 235px" value="' . ($row['tel']) . '" type="text" name="tel"></td>'; echo ' </tr>'; echo ' <tr>'; echo ' <td width="100">Email</td>'; echo ' <td width="100"><input style="width: 235px" value="' . ($row['email']) . '" type="text" name="email"></td>'; echo ' </tr>'; echo ' <tr>'; echo ' <td width="100">Info</td>'; echo ' <td width="100"><input style="width: 235px" value="' . ($row['info']) . '" type="text" name="info"></td>'; echo ' </tr>'; echo ' <tr>'; echo ' <td width="100">Checkin Date</td>'; echo ' <td width="100"><input style="width: 70px" value="' . ($row['checkin']) . '" type="text" name="checkin"></td>'; echo ' </tr>'; echo ' <tr>'; echo ' <td width="100">Checkout Date</td>'; echo ' <td width="100"><input style="width: 70px" value="' . ($row['checkout']) . '" type="text" name="checkout"></td>'; echo ' </tr>'; echo ' <tr>'; echo ' <td width="100"></td>'; echo ' <td width="100"><input type="submit" name="editbooking" value="Update Booking"></td>'; echo ' </tr>'; echo '</table>'; echo '<input type="hidden" name="source">'; echo '</form>'; } if (isset($_POST['editbooking'])) { $fullname = $_POST['fullname']; $address = $_POST['address']; $city = $_POST['city']; $postcode = $_POST['postcode']; $country = $_POST['country']; $tel = $_POST['tel']; $email = $_POST['email']; $info = $_POST['info']; $checkin = $_POST['checkin']; $checkout = $_POST['checkout']; $source = 'Manual Add'; $id_update = ($row['id']); $SQL = "UPDATE bookings SET fullname = '$fullname', address = '$address', city = '$city', postcode = '$postcode', country = '$country', tel = '$tel', email = '$email', info = '$info', checkin = '$checkin', checkout = '$checkout', source = '$source' WHERE id = '$id_update'"; error_reporting(0); $result = mysql_db_query($database,"$SQL"); header("location:index.php#bookings"); } ?> Where am I going wrong here? It simply won't update the query but if I change $id to 27 for example it will edit it?? I just want to compare this two functions <?php function myfunction($x) { if($_GET['x']==$x) { return "SELECTED"; } } echo "<option value='test'".myfunction('test').">TEST</option>"; ?> ======================================================= <?php function myfunction($x) { if($_GET['x']==$x) { echo "SELECTED"; } } ?> <option value="test" <?php myfunction("test");?>>TEST</option> * Assume that $_GET['x']=="test" My question: I try to use echo for the first case and option didnt SELECTED until i use return Same thing with the second one, where i have to use return instead of echo can anyone simply explain this thanks Hmm i can't figure this out... Below you see my code. I have 8 results from the query and i have the pegination set to max 2 values. It has 8 result so it devides them into 4 pages. But all the results are on the first page so the second third and fourth page are empty. Why is that? <?php if (isset($_POST['model_zoeken'])) { $con = mysql_connect("localhost","admin",""); if (!$con) { die('Could not connect: ' . mysql_error()); } if (!(isset($pagenum))) { $pagenum = 1; } mysql_select_db("produkten", $con); $data = mysql_query("SELECT * FROM eigenschappen") or die(mysql_error()); $rows = mysql_num_rows($qry); $page_rows = 2; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $data_p = mysql_query("SELECT * FROM eigenschappen $max") or die(mysql_error()); $qry = "SELECT * FROM eigenschappen WHERE 1=1"; if (isset($_POST['prod_name']) && trim($_POST['prod_name']) != "") { $qry .= " AND prod_name='" . mysql_real_escape_string($_POST['prod_name']). "'"; } "'"; } $result = mysql_query($qry) or die(mysql_error()); $teller = 0; $rijen = 0; echo '<table border="0"><tr>'; while($row = mysql_fetch_array($result)) { echo' <td width="160" align="center"> <a href="'.$row['website'].'"></a><img src="'.$row['prod_img'].'"> </td> <td width="165" valign="top"><br /><br />Name: '.$row['prod_name'].'<br/><br/>Website: <a href="'.$row['website'].'" target="_blank">'.$row['website_naam'].'</a> </td>' ; $teller = $teller + 1; $rijen = $rijen + 1; if ($teller == 3 || $rijen == 3){ echo "</tr><tr>"; $rijen = 0; $teller = 0; } } echo '</tr></table>'; echo '<br />'; echo " --Page $pagenum of $last-- <p>"; if ($pagenum == 1) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> "; } echo " ---- "; if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> "; } } ?> I have this $string=<span style=\"font-weight: bold;"> how can i replace the \" with " only i try this but didnt work str_replace("\\\"","\"",$string) I followed tutorial from youtube Code: [Select] http://www.youtube.com/watch?v=5b3TcoeY7Bsand made shopping cart. Everything is working fine, but there is one part I want to add. I want user to be able to set the quantity of products without going to the cart (user have to be able to enter quantity himself). At the moment I have no idea how to do this, i am still researching this topic, but wanted to try to ask for help from the pros . This is the complete code (a bit large): index.php: Code: [Select] <?php session_start(); require("includes/connection.php"); if(isset($_GET['page'])){ $pages=array("products", "cart"); if(in_array($_GET['page'], $pages)) { $_page=$_GET['page']; }else{ $_page="products"; } }else{ $_page="products"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="css/reset.css" /> <link rel="stylesheet" href="css/style.css" /> <title>Shopping Cart</title> </head> <body> <div id="container"> <div id="main"> <?php require($_page.".php"); ?> </div><!--end of main--> <div id="sidebar"> <h1>Cart</h1> <?php if(isset($_SESSION['cart'])){ $sql="SELECT * FROM products WHERE id_product IN ("; foreach($_SESSION['cart'] as $id => $value) { $sql.=$id.","; } $sql=substr($sql, 0, -1).") ORDER BY name ASC"; $query=mysql_query($sql); while($row=mysql_fetch_array($query)){ ?> <p><?php echo $row['name'] ?> x <?php echo $_SESSION['cart'][$row['id_product']]['quantity'] ?></p> <?php } ?> <hr /> <a href="index.php?page=cart">Go to cart</a> <?php }else{ echo "<p>Your Cart is empty. Please add some products.</p>"; } ?> </div><!--end of sidebar--> </div><!--end container--> </body> </html> cart.php: Code: [Select] <?php if(isset($_POST['submit'])){ foreach($_POST['quantity'] as $key => $val) { if($val==0) { unset($_SESSION['cart'][$key]); }else{ $_SESSION['cart'][$key]['quantity']=$val; } } } ?> <h1>View cart</h1> <a href="index.php?page=products">Go back to products page</a> <form method="post" action="index.php?page=cart"> <table> <tr> <th>Name</th> <th>Quantity</th> <th>Price</th> <th>Items Price</th> </tr> <?php $sql="SELECT * FROM products WHERE id_product IN ("; foreach($_SESSION['cart'] as $id => $value) { $sql.=$id.","; } $sql=substr($sql, 0, -1).") ORDER BY name ASC"; $query=mysql_query($sql); $totalprice=0; while($row=mysql_fetch_array($query)){ $subtotal=$_SESSION['cart'][$row['id_product']]['quantity']*$row['price']; $totalprice+=$subtotal; ?> <tr> <td><?php echo $row['name'] ?></td> <td><input type="text" name="quantity[<?php echo $row['id_product'] ?>]" size="5" value="<?php echo $_SESSION['cart'][$row['id_product']]['quantity'] ?>" /></td> <td><?php echo $row['price'] ?>$</td> <td><?php echo $_SESSION['cart'][$row['id_product']]['quantity']*$row['price'] ?>$</td> </tr> <?php } ?> <tr> <td>Total Price: <?php echo $totalprice ?></td> </tr> </table> <br /> <button type="submit" name="submit">Update Cart</button> </form> <br /> <p>To remove an item set it's quantity to 0. </p> products.php: Code: [Select] <?php if(isset($_GET['action']) && $_GET['action']=="add"){ $id=intval($_GET['id']); if(isset($_SESSION['cart'][$id])){ $_SESSION['cart'][$id]['quantity']++; }else{ $sql_s="SELECT * FROM products WHERE id_product={$id}"; $query_s=mysql_query($sql_s); if(mysql_num_rows($query_s)!=0){ $row_s=mysql_fetch_array($query_s); $_SESSION['cart'][$row_s['id_product']]=array( "quantity" => 1, "price" => $row_s['price'] ); }else{ $message="This product id it's invalid!"; } } } ?> <h1>Product List</h1> <?php if(isset($message)){ echo "<h2>$message</h2>"; } ?> <table> <tr> <th>Name</th> <th>Description</th> <th>Price</th> <th>Action</th> </tr> <?php $sql="SELECT * FROM products ORDER BY name ASC"; $query=mysql_query($sql); while ($row=mysql_fetch_array($query)) { ?> <tr> <td><?php echo $row['name'] ?></td> <td><?php echo $row['description'] ?></td> <td><?php echo $row['price'] ?>$</td> <td><a href="index.php?page=products&action=add&id=<?php echo $row['id_product'] ?>">Add to cart</a></td> </tr> <?php } ?> </table> So i have this page that pretty much displays all the members in the database, and its split into pages using a pagination php script. The problem is that i want the ID number displayed next to it, however the database record id jumps since some records have been deleted. So while there were a total of 1000 records 10 have been removed so instead of showing the accurate ID number of 995 on the last record it displays the number 1000 .... I've tried just assigning a number to each record using the following code... $get_members = "SELECT * FROM members ORDER BY ID ASC LIMIT $rowsperpage OFFSET $offset"; $run_mem_query = mysql_query($get_members) or die(mysql_error()); $club_id = 1; while($member = mysql_fetch_assoc($run_mem_query)){ ?> <li><strong><?php echo $club_id++ ;?>.</strong><?php echo $member['username'] ;?> - <span><?php echo $member['state'] ;?></span></li> <?php } The problem with that is that every time i click to go to the next page the number sequence refreshed back to 1 and starts over.... i've been trying to find a way around his, but can't....does anyone have any solutions to this??? Here's the script that controls the pagination <?php if ($totalpages > 1){ /*********** Start the pagination links ********/ echo "<p>"; // range of num links to show $range = 6; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'>First</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'>Previous</a> "; } // end if if($result > 0){ // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " <b>$x</b> "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for }else{ echo "<a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>1</a>"; } // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'> Next </a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'> Last </a> "; } // end if echo "</p>\n"; /****** end build pagination links ******/ } ?> Hi all, I have a simple script that does not work! I think it may be to do with $num = mysqli_num_rows($result) and $row = mysqli_assoc_result($result). I have tried echoing the value which works if I put it above the include("cxn.php");. The code is: <?php include("cxn.php"); $sql = "SELECT * FROM table WHERE email='$_POST[email]'"; $result = mysqli_query($cxn,$sql) or die("Cant execute query!"); $num = mysqli_num_rows($result); $row = mysqli_fetch_assoc($result); if ($num > 0) { $to = "$_POST[email]"; $subj = "from the website"; $mess = "Your value is".$row['value']; $mailsend = mail($to,$subj,$mess,$headers); echo "email sent to $_POST['email']"; } else { echo "email not found!";} ?> been trying to get a code up and working for a update database form, couldnt really get any working i found from google and then after a bit of help from here i got a crazy idea and stopped dead and my tracks and switched gears. so i thought, why not just use the form i used to insert my database and change it around a little. same concept, how should this not be possible ? for reference here are my tables and structure Movies ID(PK) Title Category(FK) URL 0 Name 1 http://www. Categories ID(PK) Category 1 Drama note: i know i should change Category from movies to CategoryID for less confusion. to make long story short when i tried i got errors, to much time to go back over everything so i will just stick with what i got for now. ok so my insert form inserts a movie title,category and url into my movies table. the dropdown for category is populated with a list of categories in my categories table, the way the code is writen it shows the actual category name instead of the id inside the dropdown. the form goes like: Title: textfield1 Category:dropdown URL:textfield2 so what i did was took the code from it, replaced title textfield1 with the same dropdown for category and just edited the select and echo to pull and show movie titles. i also added a WHERE to it so i can only select titles in a certian category. so it should look like, Title: dropdown Category:dropdown so here is the code below (ignore leftovers from URL or anything else i plan on taken them out pending the outcome) Code: [Select] <html> <form id="form1" name="Update" method="post" action="ad3.php"> <label> Title: <input type="text" name="Title" id="Title" /> </label> <br /> <select name='dropdownt' id='dropdownt'> <?php $con = mysql_connect("localhost", "root", ""); if (!$con) { die('Could not connect to DB: ' . mysql_error() ); } mysql_select_db ("5", $con); $query = "SELECT Title FROM movies WHERE Category='1'"; $result = mysql_query($query) OR DIE ("There was an error" .mysql_error()); while($row=mysql_fetch_array($result)) { echo " <option value=\"{$row['Title']}\">{$row['Title']}</option>"; } php?> </select> <select name='dropdown' id='dropdown'> <?php $con = mysql_connect("localhost", "root", ""); if (!$con) { die('Could not connect to DB: ' . mysql_error() ); } mysql_select_db ("5", $con); $query = "SELECT ID, Category from categories"; $result = mysql_query($query) OR DIE ("There was an error" .mysql_error()); while($row=mysql_fetch_array($result)) { echo " <option value=\"{$row['ID']}\">{$row['Category']}</option>"; } php?> </select> <input name="" type="submit" value="send" /> </form> </html> one thing that i could not figure out (due to my lack of php knownledge) is that after my SELECT i have the Code: [Select] echo " <option value=\"{$row['Title']}\">{$row['Title']}</option>"; before i had edited this code there was ID where the first 'Title' is. after trying to take one part of that out i got a error so i just left it. so what i thought i would do for the process page (ad3.php) i would just turn the INSERT into a UPDATE. Code: [Select] <?php $con = mysql_connect("localhost", "root", ""); if (!$con) { die('Could not connect to DB: ' . mysql_error() ); } mysql_select_db ("5", $con); $sql="UPDATE movies SET Category = '$_POST[dropdown]', Title = '$_POST[dropdownt]' LIMIT 1"; if (!mysql_query($sql,$con)) { die ('Error: ' . mysql_error()); } echo "<a href=\"form2.php\">Record added. Click here to make a new entry</a>"; the surprising thing (to me anyways) is that it actually worked! well.. ALMOST it should work by letting me select a certian title thats in a certian category and change its current category into a different one and then submit. after a few hours i finaly got it to do what i need BUT the problem i am having is that when looking into my phpmyadmin, it just changes the name and category to the first record in my movies table which is id "0". one of the too. i almost done it on my own.. almost... sorry for the extended post but i didnt want to leave anyone confused. so my question is, did i forget to add anything, take anything out, miss a change i needed to make ? maybe its the echos after my SELECT in my form > Hi guys, i'm trying to increment a variable / session value whenever 'submit' comes in the POST. I can't seem to get around the logic of this. Code looks like this: Code: [Select] $var = 0 if($_POST('submit'){ $_SESSION['var2'] = $var++; } What I want it to do is increment the value of the session index everytime a user clicks 'submit'. But because i've reset $var to 0 everytime, it's always just going to stay at 1. I just can't think of a way to achieve this, does anyone have any clue on how I can? hi phpfreaks Recently I tryed to create a login for my website and a logout using sessions. The problem I have is: Whenever I log in I will be going to the homepage of the website. My session will be set and everything works fine. Now when I log out my session will be unset and destroyed. The problem is, is that whenever I go back in history I can still see my homepage. When I refresh that page the browser asks the user to resend it's information (probably because it has to do with using post in my login template). b.t.w. is it a bad thing to use request and a .htaccess file for my login form? So whenever a user logs in -> logs out -> goes back in history -> refreshes -> resend information the user is not asked to answer any account and password information to get itself logged in again. This troubles me for quite a while now ! Here are the pages I use to login, logout and show the homepage: Login.php: Code: [Select] <?php class Handler_Login extends Action_Handler { function __construct($action_handle) { parent::construct($action_handle); $this->action = $action_handle; } function secured_handler() { if ($this->session->check_session() == false) { $password = $_POST['password']; $username = $_POST['username']; $login = $this->dbh->Login($username, $password); if ($login == true) { $this->session->set('username', $username); $this->view->displayHome(); $this->view->display(); } else { echo "you are not logged in"; } } else { $this->view->displayHome(); $this->view->display(); } } } ?> Logout.php: Code: [Select] <?php class Handler_Loguit extends Action_Handler { function __construct($action_handle) { parent::construct($action_handle); $this->action = $action_handle; } function secured_handler() { $this->session->stopSession(); $this->view->displayLogin(); $this->view->display(); } } ?> Home.php: Code: [Select] <?php class Handler_home extends Action_Handler { public function __construct($action_handle) { parent::construct($action_handle); $this->action = $action_handle; } function secured_handler() { if ($this->session->check_session() == false) { $this->view->displayLogin(); $this->view->display(); } else { $this->view->displayHome(); $this->view->display(); } } } ?> Session.php: Code: [Select] <?php class Session { function __construct() { if(!isset($_SESSION)) { session_start(); } } function set($name, $value) { $_SESSION[$name] = $value; } function get($name) { return $_SESSION[$name]; } function stopSession() { unset($_SESSION); session_destroy(); } function check_session() { if(isset($_SESSION['username']) && !empty($_SESSION['username'])) { return true; } else { return false; } } } ?> view.php: Code: [Select] <?php class view { private $tpl; function __construct() { } function displayStatus() { $status = file_get_contents("templates/status.tpl"); $this->tpl = str_replace("%content%", $status, $this->tpl); } function displayLogin() { $this->tpl = file_get_contents("templates/login.tpl"); } function displayHome() { $this->tpl = file_get_contents("templates/home.tpl"); } function display() { echo $this->tpl; } } ?> now what I'm trying to do is: whenever the user goes back in history after being logged out, the page should be redirected to the login page. I have no idea how I would accomplish this. I know it has got something to do with my login.php but I can't really make it redirect to itself since it will then most possibly start an endless loop of redirecting. I'm using templates to display my pages, if neccesary I will post them too, Thanks for your support and I hope this issue will get solved I have this code and its working awsomely fine if i provide a direct link of an uploaded image. Just and just only one problem i am not able to pass my uploaded image to facebook->api (whether its valid or not) and the following always echo echo 'Only jpg, png and gif image types are supported!'; i even remove the check on image type and try to get the image from $img = realpath($_FILES["pic"]["tmp_name"]); but $img gets nothing in it and uploads a by default empty image on facebook as my page Kindly check my following code and let me know what is wrong with my code and what should i do instead to upload images Online link of the following CODE: http://radiations3.com/facebook/1.php Code: [Select] <? require 'src/facebook.php'; $app_id = "364900470214655"; $app_secret = "xxxxxxxx"; $facebook = new Facebook(array( 'appId' => $app_id, 'secret' => $app_secret, 'cookie' => true, 'fileUpload' => true, )); $user = $facebook->getUser(); //echo $user; if(($facebook->getUser())==0) { header("Location:{$facebook->getLoginUrl(array('req_perms' => 'user_status,publish_stream,user_photos,offline_access,manage_pages'))}"); exit; } else { $accounts_list = $facebook->api('/me/accounts'); echo "i am connected"; } $valid_files = array('image/jpeg', 'image/png', 'image/gif'); //to get the page access token to post as a page foreach($accounts_list['data'] as $account){ if($account['id'] == 194458563914948){ // my page id =123456789 $access_token = $account['access_token']; echo "<p>Page Access Token: $access_token</p>"; } } //posting to the page wall if (isset($_FILES) && !empty($_FILES)) { if( !in_array($_FILES['pic']['type'], $valid_files ) ) { echo 'Only jpg, png and gif image types are supported!'; } else{ #Upload photo here $img = realpath($_FILES["pic"]["tmp_name"]); $attachment = array('message' => 'this is my message', 'access_token' => $access_token, 'name' => 'This is my demo Facebook application!', 'caption' => "Caption of the Post", 'link' => 'example.org', 'description' => 'this is a description', 'picture' => '@' . $img, 'actions' => array(array('name' => 'Get Search', 'link' => 'http://www.google.com')) ); $status = $facebook->api('/194458563914948/feed', 'POST', $attachment); // my page id =123456789 var_dump($status); } } ?> <body> <!-- Form for uploading the photo --> <div class="main"> <p>Select a photo to upload on Facebook Fan Page</p> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data"> <p>Select the image: <input type="file" name="pic" /></p> <p><input class="post_but" type="submit" value="Upload to my album" /></p> </form> </div> </body> I'm trying to find the write coding to pull the First and Second words from the 2nd line and the entire 3rd line from this file and have them as $subject1 and $subject2 And I have no php background. http://www.weatherserver.net/text/CWTO/WOCN11.txt so $subject1 = WOCN11 CWTO and $subject2 = SPECIAL WEATHER STATEMENT Hey guys i have a contact form for my site working fine but when i receive the emails i get some unwanted texts after the email section. here they r : name1: ryan number: 343244 message1: hey email: ss@yahoo.com clearField: [type Function] label1: NAME label2: E-MAIL label3: PHONE label5: MESSAGE countField: 5 arrayLabel: undefined,NAME,E-MAIL,PHONE,undefined,MESSAGE i: 6 txtField: _level0.topmenu.page.pages.contactform.txtField5 _request: contact/email.php the script Code: [Select] <?php /***************************************************\ * PHP 4.1.0+ version of email script. For more * information on the mail() function for PHP, see * http://www.php.net/manual/en/function.mail.php \***************************************************/ // First, set up some variables to serve you in // getting an email. This includes the email this is // sent to (yours) and what the subject of this email // should be. It's a good idea to choose your own // subject instead of allowing the user to. This will // help prevent spam filters from snatching this email // out from under your nose when something unusual is put. $sendTo = "hey@email.com"; $subject = "helloy"; // variables are sent to this PHP page through // the POST method. $_POST is a global associative array // of variables passed through this method. From that, we // can get the values sent to this page from Flash and // assign them to appropriate variables which can be used // in the PHP mail() function. // header information not including sendTo and Subject // these all go in one variable. First, include From: $headers = "From: " . $_POST["firstName"] ." ". $_POST["lastname"] . "<" . $_POST["email"] .">\r\n"; // next include a replyto $headers .= "Reply-To: " . $_POST["email"] . "\r\n"; // often email servers won't allow emails to be sent to // domains other than their own. The return path here will // often lift that restriction so, for instance, you could send // email to a hotmail account. (hosting provider settings may vary) // technically bounced email is supposed to go to the return-path email $headers .= "Return-path: " . $_POST["email"]; // now we can add the content of the message to a body variable $message = $_POST['message']; $message = ""; foreach($_POST as $key=>$value) { $message .= $key.": ".$value."\n\r"; } // once the variables have been defined, they can be included // in the mail function call which will send you an email mail($sendTo, $subject, $message, $headers); ?> can some1 suggest me something iam a complete noob ! it says i have an error in in line 23 which is i cant seem to find it Code: [Select] <?php if($_POST['loginbtn']){ require "scripts/connect.php"; $email = mysql_real_escape_string($_POST['email']); $password = mysql_real_escape_string($_POST['password']); if($email && $password){ $password = md5("$password"); $query = mysql_query("SELECT * FROM ezadmin WHERE email = '$email'"); $numrows = mysql_num_rows($query); if($numrows != 0){ $row = mysql_fetch_assoc($query); //line 23 $dbemail = $row ['email']; $dbpassword = $row ['password']; if($dbemail === $email && $dbpassword === $password){ $_SESSION['email'] = $dbemail; header("location: adminpanel"); exit(); }else $msg = "PLEASE CHECK YOU EMAIL OR PASSWORD!"; }else $msg = "PERSON DOES NO EXSIT!"; }else $msg = "YOU MUST FILL IN ALL FIELDS!"; mysql_close(); } ?> This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=348574.0 let say i have this <a href="myuploadfolder/picture1.jpg">Picture</a> and when user click on the link, they can see in which folder their picture were kept...is this dangerous?? if yes then how to hide it?? thanks in advance Hi, my name is Michael Vallier and I am the director of Killer Film Fest. This year I have incorporated some new features and need some php help. If you are able to help with either or both problems, please let me know. Thanks in advance. 1. I am using a forum and I need help customizing it. I have no idea what I am doing. I have changed a few things, but don't know enough to do what I want. I don't need anything crazy, just to fit the look of our website. The forum is not open yet but you can see it he http://www.killerfilmfest.com/forum/ 2. I found a add-on to my website which is a file manager. People can create an account and upload files to my FTP server. I want to use this for filmmakers to upload their films if they choose to do it this way. There is a 10mb limit and it is possible to make it unlimited. I contacted the creator of the application and he led me to a wiki page with the directions. It looked real simple and I tried to do this but without any luck. So if there is anyone out there who can help, that would be great. Thanks -Michael Vallier- |