maxwell@'s Profile User Rating: -----

Reputation: 0 Apprentice
Group:
Members
Active Posts:
45 (0.05 per day)
Joined:
23-March 11
Profile Views:
668
Last Active:
User is offline Jul 11 2012 03:20 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   maxwell@ has not set their status

Posts I've Made

  1. In Topic: Page not displaying correctly after re-direct

    Posted 15 Jul 2011


    Hi

    Using GET and action="comment_confirm.php">

    everything works the way I want it to, apart
    from the fact that no form data is inserted
    into the database.
    My INSERT statement totally relies on POST


    if(isset($_POST['submit'])) {
    $mysql = new mysqli('localhost','tutor','password','tutor') or die('There was a problem connecting to the database');
    if($stmt = $mysql->prepare('INSERT INTO guest(name, email, comment, software_id) VALUES (?,?,?,?)')) {

    $stmt->bind_param('sssi',$_POST['name'],$_POST['email'],$_POST['comment'],$_POST['software_id']);

    $stmt->execute();
    $stmt->close();
    header('Location: fulltitle.php');
    } else {
    echo 'error: ' . $mysql->error;
    }
    }


    If I change all POSTs to GET the insert works, but when I refresh
    the form data is re-entered into the database, which the whole
    re-direct is supposed to avoid. Also all of the form data shows
    in the URL which I believe is a security risk!

    Regards Maxwell
  2. In Topic: Page not displaying correctly after re-direct

    Posted 15 Jul 2011

    Can you point me to information (tutorial, article) on using the GET array
    to pass and capture variables?

    Best regards Maxwell
  3. In Topic: Page not displaying correctly after re-direct

    Posted 14 Jul 2011

    Hi

    My comments form is now redirecting the way I want it to,
    the proper GET variables make my comments page appear the
    way it should.

    Unfortunately it is using the GET method. This has caused
    my database INSERT to stop working as it depends on POST

    I also know you can't use GET when changing anything on the server.

    Is there a way to change my code to POST while allowing it to
    work the way it is now!



    comments page code -


    try {  
    
    $pdo = new PDO("mysql:host=$hostname;dbname=tutor", $username, $password); 
    
    }catch (PDOExeption $e){  
    
     echo $e->getMessage();  
     } 
     
    // extract $_GET values from URL
    
    $_def_soft_id = 1;
    $_def_id = 9876;
    
    $_soft_id = isset($_GET['software_id']) ? $_GET['software_id'] : $_def_soft_id;
    $_id = isset($_GET['id']) ? $_GET['id'] : $_def_id;
    
    //$_action = $_SERVER['PHP_SELF'] . '?id=' . $_id . '&software_id=' . $_soft_id;
    
    //////////////////////////////////////////////////
    
    // insert contents of form fields into the database
     
    if(isset($_POST['submit'])) {
    $mysql = new mysqli('localhost','tutor','password','tutor') or die('There was a problem connecting to the database');
    if($stmt = $mysql->prepare('INSERT INTO guest(name, email, comment, software_id) VALUES (?,?,?,?)')) {
    
    $stmt->bind_param('sssi',$_POST['name'],$_POST['email'],$_POST['comment'],$_POST['software_id']);
    	
    $stmt->execute();
    $stmt->close();
    } else {
      echo 'error: ' . $mysql->error;
    }
    }
    ////////////////////////////////////////////
    
    // display database contents on in table
    
    $dbh = $pdo->prepare("SELECT `date`, `name`, `email`, `comment`, `software_id` FROM `guest` WHERE `software_id` = ? ORDER BY `date` DESC"); 
    
    $dbh->bindValue(1, $_GET['software_id'], PDO::PARAM_INT); // assuming it's an integer    
    
    $dbh->execute();   
    $dbh->setFetchMode(PDO::FETCH_ASSOC); 
    
    while($row = $dbh->fetch()) {echo '<table width="100%" cellspacing="0" cellpadding="3" class="tablebg">
            <tr class="formlabels">
              <td align="left" class="tl" width="40%">Author:&nbsp;'.$row['name'].'</td>
              <td width="45%" align="left">Date:&nbsp;'.$row['date'].'</td>
              <td width="15%" align="center" class="tr"><a href="mailto:'.$row['email'].'">Email Author</a></td>
              </tr>
            <tr class="formlabels">
              <td colspan="4" class="bl">'.$row['comment'].'</td>
              </tr>
          </table>';
    	  }
    ?>
    <html>
    <head>
    <link rel="stylesheet" href="styles.css" type="text/css" media="screen" />
    </head>
    <body>
    <hr />
    <form method="GET" action="comment_confirm.php">
    	<table>
      <input type="hidden" name="id" value="<?php echo $_id; ?>"/>
    	  <br/>
    	 <input type="hidden" name="software_id" value="<?php echo $_soft_id; ?>"/>
         <tr><td>Name:</td></tr>
    	  <tr>
    	    <td> <input name="name" type="text" value="" size="45" /></td></tr>
           <tr><td>Email:</td></tr>
            <tr><td><input type="text" name="email" value="" size="45" /></td></tr>
            <tr><td>Comment:</td></tr>
       <tr><td><textarea cols="80" rows="6" name="comment" value="" ></textarea></td></tr>    
       <tr><td><input type="submit" name="submit" value="Add Comment" /></td><td>&nbsp;</td></tr>
      </table>
    </form>
    <br />
    <br />
        </body>
    </html>
    


    re-direct page code

    if(isset($_GET['software_id']))    header('Location: fulltitle.php?software_id='.$_GET['software_id'] . '&id=' . $_GET['id'] );
    


    Best regards Maxwell
  4. In Topic: Page not displaying correctly after re-direct

    Posted 13 Jul 2011

    Hi

    I now realize my form isn't redirecting at all.

    I removed the

    header('Location: computers_staff.php');

    from report_confirm.php and added an HTML link to computers_staff.php

    When I submitted the comment form in computers_staff.php the comments form
    and previous comments disapeared leaving just the included banner heading.

    Could you possibly pin point where I should place the header function re-directing to
    report_confirm.php

    I can then deal with either re-directing or adding an HTML link back to computers_staff.php

    Best regards Maxwell
  5. In Topic: Page not displaying correctly after re-direct

    Posted 11 Jul 2011


    I placed

    ini_set('display_errors', true);
    error_reporting( E_ALL );

    at the top of computers_staff.php and received this error


    Warning: Cannot modify header information - headers already sent by (output started at /htfiles/online/public/tutor/computers_staff.php:10) in /htfiles/online/public/tutor/computers_staff.php on line 56

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

maxwell@ hasn't added any friends yet.

Comments

maxwell@ has no profile comments yet. Why not say hello?