Jump to content

rec0il

Members
  • Posts

    19
  • Joined

  • Last visited

Posts posted by rec0il

  1. Hello,
    I'm trying to create a code that can help me and my friend keep track on how much weight we have used in past workouts and update it regularly while at the gym.
    To visualise what I'm trying to create, here is a link to the design. Click me
     
    I'm not very good at php coder nor SQL, so it's pretty difficult for me, but I've tried to create the code for the whole design but I'm stuck and can't figure out how to create the rest, I was hoping someone could help me.
     

    What I'm trying to achieve;

    To have the name of whoever using it at the top.

    To have the dropdown menu automaticly generated from my database

    To have it show the current weight on the selected exercise

    Be able to update the weight fast and easy

     
    What I have so far is
    <?php
    include ("connect.php");
    
    $sql = "SELECT * FROM `workout` WHERE exercise='dumbell bench press'";
    $result = $conn->query($sql);
    
    if ($result->num_rows > 0) {
         // output data of each row
         while($row = $result->fetch_assoc()) {
             echo "<br> Ali: ". $row["Ali"] . "<br> Emil: ". $row["Emil"] . "<br><br>" ;
         }
    } else {
         echo "0 results";
    }
    
    function updater($value,$id){
    include ("connect.php");
    
           $value=mysqli_real_escape_string($conn,$value);
           $id=mysqli_real_escape_string($conn,$id);
    
           $sql = "UPDATE `workout` SET Ali='{$value}' WHERE exercise='{$id}'";
           if ($conn->query($sql) === TRUE) {
               header("Refresh:0");
           } else {
               echo "Error updating record: " . $conn->error;
           }
           $conn->close();
       }   
       
       if (isset($_POST['Ali'])) updater($_POST['Ali'],$_POST['id']) 
    ?>  
    
    
    <html>
    <body>
    
    
    <?php
    include ("connect.php");
    
    $sql = "SELECT exercise FROM `workout`";
    $result = $conn->query($sql);
    
    if ($result->num_rows > 0) {
    	$select= '<select name="select">';
         // output data of each row
         while($row = $result->fetch_assoc()) {
    $select.='<option value="'.$row['exercise'].'">'.$row['exercise'].'</option>';
         }
    } else {
         echo "rest in peace";
    }
    
    $select.='</select>';
    echo $select;
    
    
    ?>  
    
    <br><br>
    
    
    <form action="" method="post" style="height:50px;width:50px;">
        <input type="hidden" name="id" value="dumbell bench press" />           
        <input type="text" name="Ali" /><br><br>
        <input type="submit" /><br/>
    </form>
    
    </body>
    </html>
    

    Where I've created my database like so:

    http://i1227.photobucket.com/albums/ee433/rec0ill/12312321_zpsbkamhfry.png

     

     

    post-164572-0-09866100-1486778092_thumb.png

    post-164572-0-92599500-1486778095_thumb.png

  2. Hi again PHP Freaks.

    So I would like to code something similar to the buy menu of Counter-strike: Global offensive in-game module, just in a browser and for a project of mine. I've made the design in photoshop to illustrate better.

    I just don't know what I should look into to make this kind of menu, I would love if someone could explain me what languages that this would require. (I'm guessing HTML, CSS and jQuery but I am not sure) more specific help like which particular codes would be much appreciated.

     

    Here is a picture of what I would like to create. (Also attached)

    http://i1227.photobucket.com/albums/ee433/rec0ill/CSGOKeyz_zps4195288a.png

     

    post-164572-0-91390300-1415170867_thumb.png

  3. No, you cannot overlap or nest FORMs in HTML. If you need the quantity in both forms, and it needs to be the same value, you will need to use JavaScript.

     

    Put a hidden input field in the second form to hold the quantity. Then either (1) add an event (JS) to the other form's quantity field so when it changes, the hidden field is updated with the new value; or (2) and an onSubmit event to the paypal form to retrieve the current value from the other quantity field and put it in the hidden field (before sending).

    Yeah I see.. Hoped not to get JS involved as I'm not very familiar with it. Is there by any chance you may direct me to a website in which I can read more about the code I would need to know in order to make one of these work?

     

    Or perhaps if you could explain it somehow I would be very grateful.

     

    Thx in advance

    - rec0il

  4. The <FORM> tags do not have any affect on the layout of the page. It is really just a container for form fields. You just need to move the opening tag above your first form field.

     

    Be aware, if there are other form fields on the page (not shown in the code you posted), they will become part of the form and will be sent when the form is submitted.

    Oh didn't know that, but unfortunately my quantity box is inside another form tag haha, so that probably won't work..

    Any other tips? Also would it be more helpful if i were to post my code?

  5. Either modify your HTML so the paypal form tags span your other divs (easiest solution)

     

    Or use JavaScript to grab the values of the external inputs fields and dynamically inject their values into your main paypal form (adds unneeded complexity).

    Regarding the easiest solution: That's unfortunately not what I want. I want my paypal button on the bottom of my page and the quantity box at almost the top of the page. So that would screw it up, if i had to make everything between them inside the form tag as well hehe - or am i wrong?

     

    I haven't really been able to find something on google, can you maybe point me in the right direction regarding the coding for the more complexity solution?

  6. Hello Codingforums, yet again I desire some help to my coding, this time regarding a paypal button.

     

    I'm working on a local project of mine in which I wish to let my costumers type the amount of quantities for a product they wish into a text box and then want it to automatically edit the amount of quantities on the paypal page. This works when I have the input inside the form, but due to my template I wish to have my quantity text box outside the "form" code of the paypal button but still want it to connect so that it changes. Let me explain with some code

     

    This is the working code for which i can enter the amount of quantities into a text box and it will automatically change it on the paypal page as well.

    <div id="payment" style="margin-top:10px;">
    <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
    <input type="hidden" name="cmd" value="_s-xclick">
     
    <input type="TEXT" name="quantity" value="1">
     
    <input type="hidden" name="hosted_button_id" value="C5P9LBML2FSC6">
    <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynow_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
    <img alt="" border="0" src="https://www.paypalobjects.com/da_DK/i/scr/pixel.gif" width="1" height="1">
    </form>
    </div>

     

    This is what I want it to do, I want to be able to put the input of the quantities text box onto another div and still be able to change the amount of quantities on paypal. (Doesn't change the amount of quantities when clicked on button)

    <div id="anotherdiv">
    <input type="TEXT" name="quantity" value="1">
    </div>
     
    <div id="payment" style="margin-top:10px;">
    <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
    <input type="hidden" name="cmd" value="_s-xclick">
    <input type="hidden" name="hosted_button_id" value="C5P9LBML2FSC6">
    <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynow_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
    <img alt="" border="0" src="https://www.paypalobjects.com/da_DK/i/scr/pixel.gif" width="1" height="1">
    </form>
    </div>

     

    Thx in advance

    - rec0il

  7.  

    use jquery to change the display

    I'm not very familiar with jQuery, could you direct me in the right direction maybe? Thank you

     

    I'm doing more "assuming" cause you still haven't provided any clue as to what your code looks like.  But it kind of looks like you're wanting to change the value of $quantity based on a input field being posted. 

    $quantity = (int)$_POST['quantity']; // (int) is used for security to type cast the value to an integer.
    

    Could also be $_GET['quantity'] but more likely $_POST.  But that also assumes that your inputs name is quantity.

    I'm not sure what part of the code you would need, but heres the full of the part I'm working on.

    <div class="part2">
    	<img src="images/part2.png"><br>
    	<input type="number" style="text-align:center;width:100px;background-color:transparent;color:#fff;border:0px;" name="quantity" value="1"><br>
    	<table style="width:300px;margin-left: auto;margin-right:auto;margin-top:10px;">
    	<tr>
    		<td>
    			Total price:
    		</td>
    		<td>
    			1.2€
    		</td>
    		<td style="font-size:12px;color:#e07b14">
    			1.2€ Each
    		</td>
    	</tr>
    	</table>
    	<table style="width:380px;margin-left: auto;margin-right:auto;margin-top:10px;">
    	<tr>
    		<td style="width:52%;">
    			Redeeem discount code:
    		</td>
    		<td style="">
    			<input style="text-align:center;" type="text">
    		</td>
    	</tr>
    	</table>
    </div>
    

    I've tried adding $quantity = (int)$_POST['quantity']; instead the previous code "$quantity = 10;" but it didn't seem to be working and my input name is set to quantity. I must have misunderstood something

  8. Can't give you a exact code since you didn't provide us with any of your code to compare with, but here is a basic idea.  PHP is very good at math, so just use normal mathematic operators and maybe a function depending how you want the output to look.

    $price_per_item = 1.2;
    $quantity = 10;
    
    $total = $price_per_item * $quantity;
    echo $total;
    
    $formatted_total = number_format($total, 2); // formats the number to have 2 decimal places.
    echo  $formatted_total;
    

    Beyond that you'll have to show us your code that deals with those specific areas.

    Thanks for the great and fast answer fastsol, really appreciated.

    Though I'm not sure if I can use this to function as I want it to.

     

    I would like it to automatically change the total price every time the quantity value is changed in the input, so that it doesnt have to depend on a given value.

    Heres the HTML code of my input.

    <input type="number" name="quantity" value="1">

    So I would like the php code to take the value from the input and put it in where it says X

    $quantity = X;
    

    How would this be possible?

  9. Hi again PHPFreaks

    I'm building on my new local project in which I wish to create a working function for a future e-commerce. But I ran into a problem.

    Please open following picture in order for me to illustrate my problem. http://i1227.photobucket.com/albums/ee433/rec0ill/example_zpsacd52b0c.jpg

     

    The picture represents what I want. My only problem is that I have no idea how to make the "Total price:" value (which is 1.2€ on the picture) to match the quantities above.

     

    Lets say a costumer chose 10 quantities - in that case i would like it to automaticly change the total price value to 12€ instead, so that it matches the amount of quantities chosen.

     

    How would i be able to do this? 

     

    Thx in advance

    - r e c 0 i l

  10. If you want to run your query and show the results on the same page that your input came from you should look into using an ajax process to trigger a php script and then capture the results and use js to place them on your page with the complete refresh. Sorry - don't have an example to show you here.

    I'm not very familiar with jQuery, is it really necessary to use it? Can't it be done in php/html only? :(

    and Is there anything specific you could recommend to look into, other than Ajax?

  11. Hi again PhpFreaks, yet again I got a problem regarding coding.

    I want to build somewhat a score board, which shows the latest results of matches. I've build it so that it shows all the matches on my MySQL.



    $query = $pdo->prepare("SELECT * FROM results ORDER BY id DESC");


     

    But i would like an option for my readers to choose a specific team, so that only matches of this specific team is shown.

    How would i be able to implement this feature without having to create a new page and stay on the same?

     

    Code of HTML



    <div class="results">
    <table style="width:800px">
    <?php foreach ($results as $result) { ?>
    <tr>
    <td style="background-color:grey;"><?php echo $result['date'] ?></td>
    <td ><?php echo $result['team1'] ?></td>
    <td style="background-color:green;"><?php echo $result['result1'] ?></td>
    <td><?php echo $result['team2'] ?></td>
    <td style="background-color:red;"><?php echo $result['result2'] ?></td>
    <td style="opacity: 0.5;"><?php echo $result['league'] ?></td>
    </tr>
    <?php } ?>
    </table>
    </div>


     

    Examples is more appreciated that explanations, I'm not that familiar with the english terms so makes it alittle harder for me to understand. Thanks alot in advance

  12.  

    Well you need to alter the example queries I provided so the table/column names match the ones you're using in your actual database!

     

    Also why are you using globals in a class? If your class requires the $pdo object you should pass it to the Article object on initiation and define it as a class property, this is refereed to as Dependency Injection, Example

    class Article
    
        private $db;
    
        public function __construct(PDO $db)
        {
            $this->db = $db;
        }
    
        public function fetch_all()
        {
            $this->db->prepare(... );
    
            // ...etc
        }
    }
    
    $pdo = new PDO(... );
    
    $article = new Article($pdo); // pass the pdo instance on object initialisation
    $articles = $article->fetc_all();
    

    Yeah not sure why I didn't do that. I've updated it and everything works great now. Still got issues with the 3rd one though. Hope to see someone smart who can help me out.

  13.  

    Apply a LIMIT to your SQL query, eg

    SELECT * FROM articles LIMIT 4
    

    Again modify you SQL query which orders the results by the article id or publishing date in descending order, example

    SELECT * FROM articles ORDER BY article_id LIMIT 4

    Wow, thanks for the quick answer Ch0cu3r. Both issues are now fixed and will be uploaded on the online website soon. Thanks alot

  14. Hi again PhpFreakz, yet again I have some issues with my PHP part of my website.
     
    A brief summary, I've created an simple CMS for my website so that I am able to add news and results faster and easier.
    The CMS works great I just have some issues with the finalizing part, so that it also works and looks good with my website.
     
    I have in total 3 issues, I will be stating the easiest first and follow up to the hardest. As I'm sure that many people can help me with some of them and might not be able to solve the difficult ones.
     
    If you head to this page, you can see my articles I've added to my website. I have an issue with the maximum allowed articles on this page. If I were to add several more articles it would just ignore my design and keep on going. I would like to set a maximum of 4 shown articles, how can i do that?
     
    Next up is another fairly easy one. I have - on same page as previous issue - an issue with the articles position. Currently the newest article created is on the bottom, I would like to diverse that so that the top has the newest news and it then goes down to the oldest.
     
    My third issue is a fairly complex one (At least for me) and is also an issue on several other pages. If you notice when you click on one of the news in the article page you get redirected to a new page where you can read the full article, problem is that I would like this "new page" to be opened in the same page as where the articles are. For example if you were to change on the navigation, then you get redirected on the same page but only on the "box" that appears. I would like the same effect from when my readers click on one of my articles, they just get a box with the full article and a "go back button". How could i possibly do this?
     
    Here are the codes I think are necessary to fix my issues. Let me know if you need anything else and I'll gladly add those.
     
    For 1st and 2nd issue:
    HTML + Some PHP part of index.php
    <?php foreach ($articles as $article) { ?>
    <h1 class="newsh1"><a href="article.php?id=<?php echo $article['Id'] ?>"><?php echo $article['title'] ?></a></h1>
    <p class="newstext">
        <?php echo $article[ 'short'] ?>
    </p>
    <p class="newsby">Artikel skrevet af
        <a class="newsauthor" href="#!/page_More">
            <?php echo $article[ 'author'] ?>
        </a>| <span class="newsdate"><?php echo date('j. F o', $article['date']); ?></span>
    </p>
    <div class="table"></div>
    <?php } ?>
    

    For 3rd issue:

    Full code of article.php

    <?php include_once( 'includes/connection.php'); include_once( 'includes/articles.php'); $article=new Article; if (isset($_GET['id'])) { $id = $_GET['id']; $data = $article->fetch_data($id); ?>
    <html>
    
    <head>
        <title>CMS System</title>
        <link rel="stylesheet" href="css/cms.css" />
    </head>
    
    <body>
        <div class="container">
            <h3><?php echo $data['title'] ?></h3>
            <small class="margin-left:20px;">Skrevet af <?php echo $data['author'] ?> den <?php echo date('j. F o', $data['date']); ?></small>
    
            <p>
                <?php echo $data[ 'body'] ?>
            </p>
    
            <a href="index.php">← Back</a>
        </div>
    </body>
    
    </html>
    
    	<?php } else { header('Location: index.php'); exit(); }	?>
    

    HTML+PHP part on index.php

    <li id="Nyheder">
        <div class="box1">
            <div class="inner">
                <a href="#" class="close" data-type="close"><span></span></a>
                <div class="news">
                    <h2>Senest nyt - Side 1</h2>
                    <?php foreach ($articles as $article) { ?>
                    <h1 class="newsh1"><a href="article.php?id=<?php echo $article['Id'] ?>"><?php echo $article['title'] ?></a></h1>
                    <p class="newstext">
                        <?php echo $article[ 'short'] ?>
                    </p>
                    <p class="newsby">Artikel skrevet af
                        <a class="newsauthor" href="#!/page_More">
                            <?php echo $article[ 'author'] ?>
                        </a>| <span class="newsdate"><?php echo date('j. F o', $article['date']); ?></span>
                    </p>
                    <div class="table"></div>
                    <?php } ?>
    
                </div>
                <div class="oldernews"><span class="newsold"><a href="#!/Nyheder_page2"><strong>Ældre artikler ></strong></a></span></span>
                </div>
            </div>
        </div>
    </li>
    
  15.  

    yeah, that white page meens that PHP has hit a parse error and error reporting / display errors is not set to show this on the screen.  For development always set error_reporting to E_ALL and display_errors to on.

     

    I have it set in the ini file on my development server, so I'm not sure on the runtime config, but I think sticking this at the top of the page, just under the first <?php should do it.

    error_reporting('E_ALL');
    display_errors = 1;

    These are already toggled on, so I believe it's not that which is the problem. :-(

     

    I distribute a fully loaded and functional contact form that submits using ajax with confirmation messages here

    http://amecms.com/article/Easy-to-use-contact-form-with-validation

    Thanks fastsol, I will have a look right away :-)

    EDIT: Damn, looks like just what i need but the download link is dead.. Any chance you can re-upload it? I be getting this error when trying to download source code:

    • Sorry the file requested is not available.
  16. AJAX can do it without a page change, but you would still need to add some form of output on the contact.php page for the AJAX to work with. It also meens you will need to learn the javascript (and prefferably JQuery) for processing AJJAX requests and responces on top of the PHP.

     

    Just to check, contact.php is showing as a blank page? Neither the success or the failure message are being displayed?

    oh damn, not sure what to do then.. Will try to read up some javascripting and jQuery, but this will most likely take a while.

    Heres a link to a live beta of my site, try the contact form - then you can see what i mean :-)

    http://beta.apartheid.dk/#!/Kontakt

  17.  

    Choices - in ascending order of work and complexity:

    1. have your contact.php echo out the success message on success with link and stuff
    2. have contact.php redirect to whatever page you like on success
    3. copy the contents of one page into the other page and have the PHP parser check if the form has been submitted and perform action depending on result of check

     

    Thanks for the answer Muddy_Funster

    Regarding the choice number 1: I don't seem to quite understand what you mean, can you explain it further?

    About number 2, the problem is that, I don't want it to change page at all. So that nothing goes loss.

    And about 3, didn't quite understand this one neither, but sounds like i would have to edit twice as much if i ever decided to change the site abit. So i might turn that one off.

     

    I did some research and I believe my issue can be "fixed" using something called AJAX. Which is javascript i believe, but i couldn't figure it out, as I'm not very good at javascript. Hope to hear from someone with more knowledge :-)

  18. Heya guys, i've been struggling with this for a while now, as I'm still a beginner in PHP and also Javascript / jQuery. Could anyone please help me out, would be much appreciated.

     

    I have made an Contact form using HTML and used "<form action="contact.php" to execute my php script, now whenever i click on my submit button, i get redirected to a blank page (contact.php) which is not what i wanna, i would like it to on the same page give me an alert saying whether the mail was sent or not.

    Basicly what I'm asking for is an solution to run a php script on same page, without being redirected.

     

    My HTML Code:

    <form action="contact.php" method="post" id="ContactForm">
    	<div>
    <div class="wrapper"><input name="cf_name" class="input" type="text" value="Navn" onblur="if(this.value=='') this.value='Navn'" onFocus="if(this.value =='Navn' ) this.value=''" ></div>
    <div class="wrapper"><input name="cf_email" class="input" type="text" value="Email" onblur="if(this.value=='') this.value='Email'" onFocus="if(this.value =='Email' ) this.value=''" ></div>
    <div class="textarea_box"><textarea name="cf_message" cols="1" rows="1" onBlur="if(this.value=='') this.value='Besked'" onFocus="if(this.value =='Besked' ) this.value=''"  >Besked</textarea></div>
    <input type="submit">
    <input type="reset">
    	</div>
    </form>
    

    My PHP Code: (Not sure whether i should or not post this as well, but i do anyway.)

    <?php
    $field_name = $_POST['cf_name'];
    $field_email = $_POST['cf_email'];
    $field_message = $_POST['cf_message'];
    
    $mail_to = 'my-email@live.dk';
    $subject = 'my message thingy '.$field_name;
    
    $body_message = 'From:\n '.$field_name."\n";
    $body_message .= 'E-mail:\n '.$field_email."\n";
    $body_message .= 'Message:\n '.$field_message;
    
    $headers = 'From: '.$field_email."\r\n";
    $headers .= 'Reply-To: '.$field_email."\r\n";
    
    $mail_status = mail($mail_to, $subject, $body_message, $headers);
    
    if ($mail_status) { ?>
    	<script language="javascript" type="text/javascript">
    		alert('Thank you for the message. We will contact you shortly.');
    	</script>
    <?php
    }
    else { ?>
    	<script language="javascript" type="text/javascript">
    		alert('Message failed. Please, send an email to my-email@gmail.com');
    	</script>
    <?php
    }
    ?>
    

    Thanks in advance

×
×
  • 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.