Jump to content

giannis196

Members
  • Posts

    14
  • Joined

  • Last visited

Everything posted by giannis196

  1. how i can make a php page that adds values to the database, and if the value already exist to delete it instead of add it? I am trying to do it but i am making a mistake and it only "deletes values". ``` <?php require("database.php"); if(empty($username) || empty($password)){ echo "error"; }else{ $cdtitle=$_POST["cds"]; $cdartist=$_POST["kal"]; $query= 'SELECT FROM cds WHERE cdtitle=:cdtitle && cdartist=:cdartist'; $result = $sql->prepare($query); $result->execute([":cdtitle" => $cdtitle, ":cdartist" => $cdartist]); $a = $result->fetchAll(); if($a>0){ $cdtitle=$_POST["cds"]; $cdartist=$_POST["kal"]; $query= 'DELETE FROM cds WHERE cdtitle=:cdtitle && cdartist=:cdartist'; $result = $sql->prepare($query); $result->execute([":cdtitle" => $cdtitle, ":cdartist" => $cdartist]); $a = $result->fetchAll(); echo "Deleted!"; }else{ $add = "INSERT INTO cds(username, cdtitle, cdartist) VALUES (:username, :cdtitle, :cdartist)"; $result = $sql->prepare($add); $result->execute([":username" => $username ,":cdtitle" => $cdtitle, ":cdartist" => $cdartist]); $result->fetchAll(); echo "Added!"; } } ?> ``` ok where is my mistake? how i can make it this way that it will add the value to the database if it doesn't exists and it will delete the value from the database if it exist?
  2. Ok, i finally found it! here is the correct code: <?php require_once("database.php"); $select = $pdo->prepare("SELECT * FROM `carshopdatabase` "); $select->execute([]); $query = $select->fetchAll(); echo "<table id='previewCon'><thead><th>ID</th><th>car name</th><th>HP</th><th>CC</th><th>Drive Type</th><th>Required License</th><th>Cost</th><th>qty</th></thead><tbody>"; foreach($query as $k => $i){ $comment[$k]=$i["comment"]; echo "<tr data-id=".$i["id"]."><td id='id'>cr".$i["id"]."</td> <td>".$i["car_name"]."</td> <td>".$i["HP"]."</td> <td>".$i["CC"]."</td> <td>".$i["drive_type"]."</td> <td>".$i["required_license"]."</td> <td>".$i["cost"]."</td><td><input type='number' id='number".$i['id']."' min='1' step='1'></td><td data-id=".$i["id"]."><input data-id=".$i['id']." class='addtocart' type='button' value='Add to cart'/></td></tr>"; } echo "</tbody></table>"; echo "<script>$('#previewCon tbody tr').click(function(){ var id=$(this).attr('data-id'); $.ajax({ url: 'Postcomment.php', type: 'POST', data: {id:id}, success: function(response){ $('#carcomment').html(response); } }) }) $('#previewCon tbody tr .addtocart').click(function(){ var itemid=$(this).attr('data-id'); var itemqty=$('#number'+itemid).val(); console.log(itemqty); }) </script>" ?> by this way it searches for the id number and it puts the itemid at the end so i have ex: number3 as id to search, it searches for the number3 it and it takes its value these 4 lines of code took me the entire day but i found it! edit: i also edited the id of the input type from my table and now its id=number.$i['id'] so i have ex number3 for the machine to find with the adobe id which is also number3 so it finds it and it gets its value
  3. if you can tell me how i can select 1 level back then i think i have the solution. i will select (this) i will tell the machine to look 1 level back and then i will call find('#number'+itemid)
  4. yes, it's a button what do you mean with "directly target the element"? can you give me an example? edit: ok i understood what do you mean so i need to target the element in the same level (because what i am trying to select is in the same level with button) just like css's + but how i select an element in the same level in javascript? i edited the code and now it works only for the 1st item of the list, if i click to another item of the list it will not work, it will simply take the 1st input box here is the edited code: $('#previewCon tbody tr .addtocart').click(function(){ var itemid=$(this).attr('data-id'); var itemqty=$('#previewCon tbody tr #number').val(); console.log(itemqty); }) so, what to do to take the value from the same tr where i pressed the add to cart button?
  5. Ok so i am trying to make a shopping cart and now i must make jQuery to select the value of input number box so i made this script code: $('#previewCon tbody tr .addtocart').click(function(){ var itemid=$(this).attr('data-id'); var itemqty=$(this).find('#number').val(); alert(itemqty); }) The code suppose to select the pressed button and find the #number's number to add it to cart, unfortunately there is something wrong with the selector. can you help me out with that?
  6. so, i tried to built a webpage with html css jquery ajax javascript and php the entire page runs well and when i click to a vehicle to show the comment it shows well until i click to spare parts and then click again back to browse cars after that when i click to a car to show the comment the comment doesn't appear when i go to developer tools i notice that, for each car at the right it have got "event listener" and when i go to spare parts and back again to browse cars it haven't got event listener i think it's a problem with ajax and PHP... ...so, what's wrong with the code? the link to the webpage files carshop.rar
  7. Hi everyone, i made a test webpage and i noticed the page is different between chrome and firefox and so i am here to ask if there is any way to ensure compatibility (both cross browser and cross device) without using any framework. Is there any "trick" to do that? So, what do you do to ensure the compatibility to webpages? Thanks! (btw i don't think i can post the page here because i have very limited bandwidth since i have the "free account") I am attaching 2 images, the 1 is from chrome and the other is from firefox So, why do i have this micro-difference? Thanks! Chrome.bmp Firefox.bmp
  8. Ok, i found it! it couldn't found it because it was in the function that i wasn't run it yet!
  9. Hi everyone, so today i started writing a page in PHP until i got this error message: Notice: Undefined variable: query in C:\Users\Ioann\usbwebserver\root\carshop\index.php on line 19 The variable query is defined in functions.php and yet it still thinks it's undefined my functions.php <?php $host="localhost"; $username="root"; $password="usbw"; $dbname="test"; $pdo= new PDO("mysql:host=$host; dbname=$dbname", $username, $password, [PDO::MYSQL_ATTR_INIT_COMMAND =>"SET NAMES utf8"]); try{ } catch(PDOException $e){ echo "error please try again"; } function appearcars(){ $select = $pdo ->prepare("SELECT * FROM `carshopdatabase` "); $select ->execute(); $query = $select ->fetch(); } ?> and the index.php <?php require("functions.php"); ?> <html> <head><title>car shop - educational purposes please don't take anything seriously!!</title> <link rel="stylesheet" type="text/css" href="style.css"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta content="utf-8" http-equiv="encoding"> <meta content="text/html;charset=utf-8" http-equiv="Content-Type"> </head> <body> <div id="a">Our shop have the best cars around!!!</div> <div id="lmenu"><ul> <li class="top">Home</li> <li>Browse cars</li> <li>Spare parts</li> <li class="bottom">Contuct us</li> </ul></div> <div id="carlist"><?php echo $query[1]["cost"]; ?></div> <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script> <script src="scripts.js"></script> </body> </html> so, what's going wrong here?
  10. Ok guys i found it! i should put my query between `` SELECT * FROM `carshopdatabase ` is the correct query!
  11. Hi everyone, i am using mysql for database and when i am trying to run the query SELECT * FROM carshopdatabase i got the following error message: SELECT * FROM carshopdatabase LIMIT 0, 25 So, why is this happening and how do i fix it? Thanks!
  12. Hi everyone, i am trying to make a ajax page that’s fully crawl-able from search engine so search engines can find it but i need to know how i can insert the search bar’s value in to a variable so i can process it and make a script that will load with ajax the content: Here is the script that i make but i don’t know how i can fill the hpage (h for hash) with search bat value window.addEventListener("hashchange", function(){ var page=$(this).attr("data-id"); var hpage= $("#content").load("content/"+page); }) how i can insert the search bar’s value to the hpage? Can someone tell me how to do that? Thanks!! I also use jQuery too! Just to give some explanations… The script works, when i click somewhere it will load the content of the file to the #content div but the search engines can’t find the site. I need to make something like php’s $_GET but with javascript or jQuery so a user can even copy paste the link to other user. Right now when i try to copy paste the link it will take me to the index page (home page) but with different link. Search engines will be confused or ignore it because it’s the same page. Even if they don’t ignore it, when a user clicks the link ex: OurBrandCompany/#/content/ourhistory it will take him/her to home page instead of the page that shows “our history”) so…it will have ex: localhost/#/content/Ourhistory to the search bar but the user will be in the index page (home page) That’s the why i need to know how i can load the search bar’s value to a variable so i can process it and make it work.
  13. ok i figured out what's wrong with the dropdown i had add a css style to the entire navbar i still have 2 more problems that i can't figure out: 1) the dropdown menu (at "Contact") adding space to the left as a result it's moving when someone hover the mouse over it 2) the Smenu that's at the left stills moving down when the dropdown menu opens here is my html code: <html> <head> <title>Website</title> <link rel="stylesheet" type="text/css" href="Style.css"> <meta content="text/html;charset=utf-8" http-equiv="Content-Type"> <meta content="utf-8" http-equiv="encoding"> </head> <body> <div class="navmenubg">&nbsp;</div> <div> <ul class="navmenu"> <li><a href="#Home">Home</a></li> <li><a href="#News">News</a></li> <li id="rolldown"><a href="#Contact"><span id="sArrow">Contact&#9660;</span></a> <ul class="dropdown"> <li>telephones</li> <li>email</li> <li>mail</li> <li>fax</li> </ul> </li> </ul> <div> <div id="container"> This is our website, feel free to contact us if you don't find something that you need. </div> </div> <div id="Smenu"> <div> <ul> <a href="#history"><li class="top">Our history</li></a> <a href="#workers"><li>Our workers</li></a> <a href="#buildings"><li>Our buildings</li></a> <a href="#tools"><li>Our tools</li></a> <a href="#targets"><li>Our targets</li></a> <a href="#ourjob"><li>Our job so far</li></a> <a href="#havedone"><li class="bottom">What we've done</li></a> </ul> </div> </div> </div> </body> </html> and here is my css code: html, body { margin: 0; } html{ height: 100%; background-image: linear-gradient(rgb(189, 189, 189), rgb(88, 88, 88)) } /*-------------navmenu---------*/ .navmenubg{ background-color: rgba(255, 217, 0, 0.5); position: fixed; left: 0px; width: 100%; opacity: 10%; height: 43px; z-index: -60000; } .navmenu{ overflow: hidden; text-decoration: none; display: block; font-size: 20px; color: white; margin-top: 1%; } .navmenu a{ text-decoration: none; } .navmenu li{ float: left; color: darkslategray; list-style-type: none; padding-right: 50px; padding-left: 50px; padding-top: 10px; padding-bottom: 10px; font-size: 100%; } .navmenu li:hover{ background-color: lightgreen; } .navmenu li:active{ background-color: darkgreen; color: lightgray; } .dropdown{ display: none; } #rolldown:hover > .dropdown, .dropdown:hover{ display: block; background-color: lightgreen; } #rolldown:hover > .dropdown, .dropdown:active{ display: block; background-color: darkgreen; } .dropdown{ width: 200px; z-index: -2; } /*---------Smenu--------------*/ #Smenu .bottom{ border-radius: 0px 0px 10px 10px; } #Smenu .top{ border-radius: 10px 10px 0px 0px; } #Smenu ul{ text-align: center; } #Smenu ul li{ font-size: 150%; margin-left: -40px; list-style-type: none; padding-bottom: 5%; padding-top: 5%; } #Smenu{ transform: translateY(30%); left: 1%; width: 10%; position: relative; background-color: greenyellow; border-radius: 10px 10px 10px 10px; } #Smenu a:visited{ color: darkblue; } #Smenu a:link{ color: darkblue; text-decoration: none; } #Smenu li:hover{ background-color: green } #Smenu li:active{ background-color: darkgreen; color: blue; } /*------------container---------*/ @media all and (orientation: landscape){ #container{ position: absolute; left: 20%; top: 30%; min-height: 40%; min-width: 60%; background-color: rgba(100, 200, 255, 50%); z-index: -20; } } @media all and (orientation: portrait){ #container{ position: absolute; left: 20%; top: 30%; min-height: 60%; min-width: 30%; background-color: rgba(100, 200, 255, 50%); } } #container{ border: 5px solid black; border-radius: 0px 15px 0px 15px; } can someone figure out how to solve those 2 problems? Thanks!
  14. hi, yesterday i started to write code of a page for fun and i came across one problem. my dropdown menu takes the entire line + it push down the left menu (it's id is Smenu for "small menu") here is my html code: <html> <head> <title>Website</title> <link rel="stylesheet" type="text/css" href="Style.css"> <meta content="text/html;charset=utf-8" http-equiv="Content-Type"> <meta content="utf-8" http-equiv="encoding"> </head> <body> <div> <ul class="navmenu"> <li><a href="#Home">Home</a></li> <li><a href="#News">News</a></li> <li id="rolldown"><a href="#Contact"><span id="sArrow">Contact&#9660;</span></a> <ul class="dropdown"> <li>telephones</li> <li>email</li> <li>mail</li> <li>fax</li> </ul> </li> </ul> <div> <div id="container"> This is our website, feel free to contact us if you don't find something that you need. </div> </div> <div id="Smenu"> <div> <ul> <a href="#history"><li class="top">Our history</li></a> <a href="#workers"><li>Our workers</li></a> <a href="#buildings"><li>Our buildings</li></a> <a href="#tools"><li>Our tools</li></a> <a href="#targets"><li>Our targets</li></a> <a href="#ourjob"><li>Our job so far</li></a> <a href="#havedone"><li class="bottom">What we've done</li></a> </ul> </div> </div> </div> </body> </html> and here is my css code: html, body { margin: 0; } html{ height: 100%; background-image: linear-gradient(rgb(189, 189, 189), rgb(88, 88, 88)) } /*-------------navmenu---------*/ .navmenu{ overflow: hidden; background-color: gold; text-decoration: none; display: block; font-size: 20px; color: white; text-align: center; margin-top: 1%; } .navmenu a{ text-decoration: none; } .navmenu li{ float: left; color: darkslategray; list-style-type: none; padding-right: 50px; padding-left: 50px; padding-top: 10px; padding-bottom: 10px; font-size: 100%; } .navmenu li:hover{ background-color: lightgreen; } .navmenu li:active{ background-color: darkgreen; color: lightgray; } .dropdown{ display: none; } #rolldown:hover > .dropdown, .dropdown:hover{ display: block; background-color: lightgreen; } #rolldown:hover > .dropdown, .dropdown:active{ display: block; background-color: darkgreen; } .dropdown{ width: 200px; z-index: -2; } /*---------Smenu--------------*/ #Smenu .bottom{ border-radius: 0px 0px 10px 10px; } #Smenu .top{ border-radius: 10px 10px 0px 0px; } #Smenu ul{ text-align: center; } #Smenu ul li{ font-size: 150%; margin-left: -40px; list-style-type: none; padding-bottom: 5%; padding-top: 5%; } #Smenu{ transform: translateY(30%); left: 1%; width: 10%; position: relative; background-color: greenyellow; border-radius: 10px 10px 10px 10px; } #Smenu a:visited{ color: darkblue; } #Smenu a:link{ color: darkblue; text-decoration: none; } #Smenu li:hover{ background-color: green } #Smenu li:active{ background-color: darkgreen; color: blue; } /*------------container---------*/ @media all and (orientation: landscape){ #container{ position: absolute; left: 20%; top: 30%; min-height: 40%; min-width: 60%; background-color: rgba(100, 200, 255, 50%); z-index: -20; } } @media all and (orientation: portrait){ #container{ position: absolute; left: 20%; top: 30%; min-height: 60%; min-width: 30%; background-color: rgba(100, 200, 255, 50%); } } #container{ border: 5px solid black; border-radius: 0px 15px 0px 15px; } so, what's wrong with it? 1) why does it takes the entire line 2) why does it push down the "Smenu"? Thanks!
×
×
  • Create New...