Jump to content

lovephp

Members
  • Posts

    530
  • Joined

  • Last visited

Everything posted by lovephp

  1. your condition works like a charm bro. yes i messed it up a little with my if else conditions but got it sorted now thanks a ton.
  2. im trying to redirect user according to their role, when i try logging in as admin it redirects ok but below amdin roles i get a blank login.php page ? if($result) { if(mysql_num_rows($result) == 1) { //Login Successful session_regenerate_id(); $user = mysql_fetch_assoc($result); $_SESSION['HOTEL_USER_ID'] = $user['id']; $_SESSION['HOTEL_UNAME'] = $user['uname']; $_SESSION['HOTEL_UROLE'] = $user['urole']; $role = $_SESSION['HOTEL_UROLE']; session_write_close(); if($role == 'Admin') header("location: reservation.php"); exit(); }elseif($role == 'Manager'){ header("location: reservation.php"); exit(); }elseif($role == 'Front_Desk'){ header("location: reservation.php"); exit(); }elseif($role == 'Writer'){ header("location: articles.php"); exit(); }else {
  3. guess ill have to give a serious thought on ;earning PDO
  4. ok so i got this two tables CREATE TABLE IF NOT EXISTS `rooms` ( `room_id` int(11) NOT NULL AUTO_INCREMENT, `room_name` text, `room_number` int(11) NOT NULL, `room_capacity` int(11) DEFAULT NULL, `room_status` varchar(30) DEFAULT NULL, PRIMARY KEY (`room_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1; CREATE TABLE IF NOT EXISTS `reservations` ( `id` int(11) NOT NULL AUTO_INCREMENT, `start` datetime DEFAULT NULL, `end` datetime DEFAULT NULL, `room_id` int(11) DEFAULT NULL, `status` varchar(30) DEFAULT NULL, `ip` varchar(32) NOT NULL, `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1; now how do i do a search for available rooms for reservation user would select checkin date and checkout and room name like delux, standard or suite etc or all available rooms.rooms in html form like <form action="" method="post"> <h5>Checkin</h5> <div class="book_date"> <input class="date" id="from" name="form" type="text" value="" > </div> </li> <li class="span1_of_1 left"> <h5>Checkout</h5> <div class="book_date"> <input class="date" id="to" name="to" type="text" value="" > </div> <li class="span1_of_1"> <h5>Room</h5> <div class="rooms"> <select name="rooms"> <option value="" selected="selected" disabled="disabled">Select</option> <option value="All">All Rooms</option> <option value="Deluxe Room">Deluxe Rooms</option> <option value="Super Deluxe Room">Super Deluxe Rooms</option> <option value="Executive Room">Executive Rooms</option> <option value="Suite">Suites</option> </select> </div> </li> <li class="span1_of_3"> <div class="date_btn"> <input type="submit" name="submit" value="Check Availability"/> </div> </form> i need help to query out available room type which start and end date is not available in reservation table and give out result how many rooms available in rooms table. thanks appreciate your time and help
  5. but me do not like PDO i still use php, will this matter in near future? no still not familiar with PDO though i understand how its done still php is far better for me
  6. it just wont do a header redirect i dunno why
  7. nope $total_rows = mysql_num_rows($allRecords); //$base_url = 'https://localhost/pagi/'; //Provide location of you index file $per_page = 1; //number of results to shown per page $num_links = 4; // how many links you want to show $total_rows = $total_rows; if(empty($total_rows)){ header("Location:articles.php?page=1"); exit(); } $cur_page = 1; this did not work
  8. is this the right way? $allRecords = mysql_query('select * from article'); $total_rows = mysql_num_rows($allRecords); $base_url = 'https://localhost/pagi/'; $per_page = 1; $num_links = 4; $total_rows = $total_rows; if($total_rows<1){ header("Location:article.php?page=1"); } $cur_page = 1;
  9. friends if a page number does not exist how do i get the user back to page=1? here is my following code <table class="table" width="100%"> <tbody> <tr class="top nodrop nodrag"> <th class="checkbox" style="width: 12px;"></th> <th>Image/Video</th> <th>Title/Description</th> <th class="action">Action</th> </tr> <?php $allRecords = mysql_query('select * from article'); $total_rows = mysql_num_rows($allRecords); $base_url = 'https://localhost/pagi/'; $per_page = 1; $num_links = 4; $total_rows = $total_rows; $cur_page = 1; if(isset($_GET['page'])) { $cur_page = $_GET['page']; $cur_page = ($cur_page < 1)? 1 : $cur_page; } $offset = ($cur_page-1)*$per_page; $pages = ceil($total_rows/$per_page); $start = (($cur_page - $num_links) > 0) ? ($cur_page - ($num_links - 1)) : 1; $end = (($cur_page + $num_links) < $pages) ? ($cur_page + $num_links) : $pages; $res = mysql_query("SELECT * FROM article LIMIT ".$per_page." OFFSET ".$offset); if(is_resource($allRecords)) { while($row = mysql_fetch_assoc($res)) { $img = $row['image']; $yt = $row['youtube']; if(!empty($img)){ $img = '<img src="../uploads/images/'.$row['image'].'" height="120" width="120" />'; }elseif(!empty($yt)){ $img = ''; }else{ $img = '<img src="../uploads/images/noimg.png" height="120" width="120" />'; } if(!empty($yt)){ $yt = '<img src="../uploads/images/youtube.png" height="120" width="120" />'; }else{ $yt = ''; } ?> <tr> <td class="checkbox"><input type="checkbox" value="<?php echo $row['id'];?>" name="ids[]" class="case"></td> <td><?php echo $img.$yt; ?></td> <td><a href="<?php echo $site_path.$row['url']; ?>" target="_blank"><?php echo ucfirst($row['title']); ?></a><br/><?php echo shortenString($row['article']); ?></td> <td class="action"><a href="post-article.php?id=<?php echo $row['id']; ?>"><img src="media/layout/edit.png" alt="Edit" /></a><br/><a href="javascript:delete_id(<?php echo $row['id']; ?>)"><img src="media/layout/x.png" alt="Delete" /></a></td> </tr> <?php } } ?> <tr> <td> </td> <td class="checkbox" colspan="4"><br/><br/> <select name="action" class="select" style="width:143px;"> <option selected="selected" disabled="disabled">Choose an action</option> <option value="delete">Delete</option> </select> <input type="submit" name="Go" class="submit" value="Apply action"> </td> </tr> </tbody> </table> <div id="pagination"> <div id="pagiCount"> <?php if(isset($pages)) { if($pages > 1) { if($cur_page > $num_links) { $dir = "first"; echo '<span id="prev"> <a href="'.$_SERVER['PHP_SELF'].'?page='.(1).'">'.$dir.'</a> </span>'; } if($cur_page > 1) { $dir = "prev"; echo '<span id="prev"> <a href="'.$_SERVER['PHP_SELF'].'?page='.($cur_page-1).'">'.$dir.'</a> </span>'; } for($x=$start ; $x<=$end ;$x++) { echo ($x == $cur_page) ? '<strong>'.$x.'</strong> ':'<a href="'.$_SERVER['PHP_SELF'].'?page='.$x.'">'.$x.'</a> '; } if($cur_page < $pages ) { $dir = "next"; echo '<span id="next"> <a href="'.$_SERVER['PHP_SELF'].'?page='.($cur_page+1).'">'.$dir.'</a> </span>'; } if($cur_page < ($pages-$num_links) ) { $dir = "last"; echo '<a href="'.$_SERVER['PHP_SELF'].'?page='.$pages.'">'.$dir.'</a> '; } } } ?> thanks in advance appreciate your time
  10. This code did it mate thanks de.onEventDelete = function(args) { if (!confirm("Do you really want to Delete this record?")) { args.preventDefault(); } }; i put it above the previous code. thanks for your time
  11. could anyone figure out how to add a popup dialog box asking you really want to delete this before it deletes anything on the following code de.onEventDeleted = function(args) { $.post("backend_delete.php", { id: args.e.id() }, function() { de.message("Deleted."); }); }; appreciate your time and help
  12. im planning to accept payment through some gateway so i need help in deciding the table structure to keep track of order. would appreciate all your inputs as i have not done this before so please do not be harsh
  13. I need this in simple php without pdo etc but should be injection and xss free. Add category Add subcategories Add products related to category and subcategories Edit if needed and delete then accordingly every gets deleted to cat or subcat then products Display links like Site.com/fashion-and-lifestyle (but in real it should show fashion & lifestyle) Site.com/mobile Then sub categories Site.com/fashion/shoes Site.com/mibiles/android Accordingly the products display from products database table. In links can contain id also but should be friendly url. Its a small work so contact me if you can do.
  14. ok let me be more specific something like this url i am trying to acheive 1. category.php?name=shoes (this display all data from category shoes) category.php?name=watches (this display all data from category watechs) 2. category.php?name=shoes&area=casual (this display all data from casuals related to cat name shoes) category.php?name=shoes&area=watches (this display all data from casuals related to cat name watches) and lastly the product information display in some php file how do i plan this structure?
  15. Ianyone has some sample or could guide to a turorial on how to plan the tables structure and how to fetch the datas?
  16. well i got what i needed but got a little issue i want to add the results inside a input text field rather than <h3 id="result"></h3>? also display the results on keyup event while i input the number in other fields? something like <input type="text" name="totalamount" value="results" readonly/> here my code <form id="myForm"> <input id="actualprice" type="number" placeholder="Actual Price"> <input id="discount" type="number" placeholder="Discount"> <input id="shipping" type="number" placeholder="Shipping"> <input type="submit" value="Submit"> </form> <h3 id="result"></h3> <script> $('#myForm').submit(function (event) { event.preventDefault(); var actualprice = Number($("#actualprice").val().trim()); var discount = Number($("#discount").val().trim()); var shipping = Number($("#shipping").val().trim()); var discountRate = (100 - discount) / 100; var result = (actualprice * discountRate) + shipping; $("#result").html("Result :" + result.toFixed(2)); }); </script>
  17. anyone here good at js? im looking for a form with following fields which would auto calculate and display the total on fly. <input type="text" name="acutalprice" value="329">Actual Price: 329 <input type="text" name="discount" value="65">Discount: 65% <input type="text" name="shipping" value="50">Shipping: 50+ Total Amount: 165.15 on sumbit Regards
  18. mates all seems to be ok just that when i click add to cart nothing is getting added here products.php <?php include("includes/db.php"); include("includes/functions.php"); if($_REQUEST['command']=='add' && $_REQUEST['productid']>0){ $pid=$_REQUEST['productid']; addtocart($pid,1); header("location:shoppingcart.php"); exit(); } ?> <!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" /> <title>Products</title> <script language="javascript"> function addtocart(pid){ document.form1.productid.value=pid; document.form1.command.value='add'; document.form1.submit(); } </script> </head> <body> <form name="form1"> <input type="hidden" name="productid" /> <input type="hidden" name="command" /> </form> <div align="center"> <h1 align="center">Products</h1> <table border="0" cellpadding="2px" width="600px"> <?php $result=mysql_query("select * from products"); while($row=mysql_fetch_array($result)){ ?> <tr> <td><img src="<?php echo $row['picture']; ?>" /></td> <td> <b><?php echo $row['name']; ?></b><br /> <?php echo $row['description']; ?><br /> Price:<big style="color:green"> $<?php echo $row['price']; ?></big><br /><br /> <input type="button" value="Add to Cart" onclick="addtocart(<?php echo $row['serial']; ?>)" /> </td> </tr> <tr><td colspan="2"><hr size="1" /></td> <?php } ?> </table> </div> </body> </html> shoppingcart.php <?php include("includes/db.php"); include("includes/functions.php"); echo print_r($_SESSION); if($_REQUEST['command']=='delete' && $_REQUEST['pid']>0){ remove_product($_REQUEST['pid']); } else if($_REQUEST['command']=='clear'){ unset($_SESSION['cart']); } else if($_REQUEST['command']=='update'){ $max=count($_SESSION['cart']); for($i=0;$i<$max;$i++){ $pid=$_SESSION['cart'][$i]['productid']; $q=intval($_REQUEST['product'.$pid]); if($q>0 && $q<=999){ $_SESSION['cart'][$i]['qty']=$q; } else{ $msg='Some proudcts not updated!, quantity must be a number between 1 and 999'; } } } ?> <!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" /> <title>Shopping Cart</title> <script language="javascript"> function del(pid){ if(confirm('Do you really mean to delete this item')){ document.form1.pid.value=pid; document.form1.command.value='delete'; document.form1.submit(); } } function clear_cart(){ if(confirm('This will empty your shopping cart, continue?')){ document.form1.command.value='clear'; document.form1.submit(); } } function update_cart(){ document.form1.command.value='update'; document.form1.submit(); } </script> </head> <body> <form name="form1" method="post"> <input type="hidden" name="pid" /> <input type="hidden" name="command" /> <div style="margin:0px auto; width:600px;" > <div style="padding-bottom:10px"> <h1 align="center">Your Shopping Cart</h1> <input type="button" value="Continue Shopping" onclick="window.location='products.php'" /> </div> <div style="color:#F00"><?php echo $msg; ?></div> <table border="0" cellpadding="5px" cellspacing="1px" style="font-family:Verdana, Geneva, sans-serif; font-size:11px; background-color:#E1E1E1" width="100%"> <?php if(is_array($_SESSION['cart'])){ echo '<tr bgcolor="#FFFFFF" style="font-weight:bold"><td>Serial</td><td>Name</td><td>Price</td><td>Qty</td><td>Amount</td><td>Options</td></tr>'; $max=count($_SESSION['cart']); for($i=0;$i<$max;$i++){ $pid=$_SESSION['cart'][$i]['productid']; $q=$_SESSION['cart'][$i]['qty']; $pname=get_product_name($pid); if($q==0) continue; ?> <tr bgcolor="#FFFFFF"><td><?php echo $i+1; ?></td><td><?php echo $pname; ?></td> <td>$ <?php echo get_price($pid); ?></td> <td><input type="text" name="product<?php echo $pid; ?>" value="<?php echo $q; ?>" maxlength="3" size="2" /></td> <td>$ <?php echo get_price($pid)*$q; ?></td> <td><a href="javascript:del(<?php echo $pid; ?>)">Remove</a></td></tr> <?php } ?> <tr><td><b>Order Total: $<?php echo get_order_total(); ?></b></td><td colspan="5" align="right"><input type="button" value="Clear Cart" onclick="clear_cart()"><input type="button" value="Update Cart" onclick="update_cart()"><input type="button" value="Place Order" onclick="window.location='billing.php'"></td></tr> <?php } else{ echo "<tr bgColor='#FFFFFF'><td>There are no items in your shopping cart!</td>"; } ?> </table> </div> </form> </body> </html> includes/functions.php <?php function get_product_name($pid){ $result=mysql_query("select name from products where serial=$pid"); $row=mysql_fetch_array($result); return $row['name']; } function get_price($pid){ $result=mysql_query("select price from products where serial=$pid"); $row=mysql_fetch_array($result); return $row['price']; } function remove_product($pid){ $pid=intval($pid); $max=count($_SESSION['cart']); for($i=0;$i<$max;$i++){ if($pid==$_SESSION['cart'][$i]['productid']){ unset($_SESSION['cart'][$i]); break; } } $_SESSION['cart']=array_values($_SESSION['cart']); } function get_order_total(){ $max=count($_SESSION['cart']); $sum=0; for($i=0;$i<$max;$i++){ $pid=$_SESSION['cart'][$i]['productid']; $q=$_SESSION['cart'][$i]['qty']; $price=get_price($pid); $sum+=$price*$q; } return $sum; } function addtocart($pid,$q){ if($pid<1 or $q<1) return; if(is_array($_SESSION['cart'])){ if(product_exists($pid)) return; $max=count($_SESSION['cart']); $_SESSION['cart'][$max]['productid']=$pid; $_SESSION['cart'][$max]['qty']=$q; } else{ $_SESSION['cart']=array(); $_SESSION['cart'][0]['productid']=$pid; $_SESSION['cart'][0]['qty']=$q; } } function product_exists($pid){ $pid=intval($pid); $max=count($_SESSION['cart']); $flag=0; for($i=0;$i<$max;$i++){ if($pid==$_SESSION['cart'][$i]['productid']){ $flag=1; break; } } return $flag; } ?> anyone can figure out whats wrong?
  19. A little help please on adding cookies in secure way to my login code above.
  20. the above code fetches results with no issues, but now im trying to make a edit.php page where i wish to fetch users saved data and there are fields as State and Town so how could i use the above code to display saved values? as of now after selecting the State name then the Town name dynamically loads eg $sql = mysql_query("SELECT * FROM posts WHERE userID='1'"); $row = mysql_fetch_array($result); $state=$row['State'] ; $town=$row['Town'] ; the code above will have the saved value or the post right? so i want the results of my dropdown to also display the values of $state and $town.
  21. ok so this is how i generate state and towns name <script type="text/javascript"> $(document).ready(function() { $('#wait_1').hide(); $('#State').change(function(){ $('#wait_1').show(); $('#result_1').hide(); $.get("state_towns.php", { func: "State", drop_var: $('#State').val() }, function(response){ $('#result_1').fadeOut(); setTimeout("finishAjax_1('result_1', '"+escape(response)+"')", 400); }); return false; }); }); function finishAjax_1(id, response) { $('#wait_1').hide(); $('#'+id).html(unescape(response)); $('#'+id).fadeIn(); } </script> <select name="State" id="State"> <option value="" selected="selected" disabled="disabled">State</option> <?php getTowns(); ?> </select> <span id="wait_1" style="display: none;"> <small><b>Loading...</b></small> </span> <span id="result_1" style="display: none;"></span>, and here is the state_towns.php fike <?php function getTowns() { $result = mysql_query("SELECT DISTINCT State FROM state_town") or die(mysql_error()); while($tier = mysql_fetch_array( $result )) { echo '<option value="'.$tier['State'].'">'.$tier['State'].'</option>'; } } if($_GET['func'] == "State" && isset($_GET['func'])) { state_dropdown($_GET['drop_var']); } function state_dropdown($drop_var) { include("manage/connect.php"); $result = mysql_query("SELECT * FROM state_town WHERE State='$drop_var'") or die(mysql_error()); echo '<select name="Town" id="Town"> <option value="" disabled="disabled" selected="selected">Any Town</option>'; while($town_dropdown = mysql_fetch_array( $result )) { echo '<option value="'.$town_dropdown['Towns'].'">'.$town_dropdown['Towns'].'</option>'; } echo '</select> '; } ?> in my update data page how could i fetch the state and town names which was stored already? having a hard time figuring it out. appreciate your help and time. cheers
  22. ok got it working with the following code # SEO URL Settings RewriteEngine On RewriteBase /blog/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)\?*$ article.php?$1 [L,QSA] but is it ok?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.