Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    Regular Coder
    Join Date
    Apr 2013
    Posts
    136
    Thanks
    3
    Thanked 0 Times in 0 Posts

    php form values not being passed through?!

    PHP Code:
    <form action="edit-blog-script.php?id=<?php echo $id ?>" method="POST" name="form">
            <div data-role="fieldcontain">
                <label for="textinput1">
                    Title
                </label>
                <input name="title" id="textinput1" placeholder="" value="<?php echo $title;?>" type="text">
                <input name="id" placeholder="" value="<?php echo $id;?>" type="hidden">
            </div>
            <div data-role="fieldcontain">
                <label for="textinput2">
                    Date
                </label>
                <input name="date" id="textinput2" placeholder="" value="<?php echo $date;?>" type="text">
            </div>
            <div data-role="fieldcontain">
                <label for="textinput3">
                    Article
                </label>
                <textarea name="article" id="textarea1" placeholder=""><?php echo $article;?></textarea>
            </div>
                <img src="<?php echo $image1;?>" alt="image" width="288" >
                <img src="<?php echo $image2;?>" alt="image" width="288" >
                <img src="<?php echo $image3;?>" alt="image" width="288" >
            <input data-theme="b" value="Submit" type="submit">
            </form>
    PHP Code:

    $thistitle 
    $_GET['title'];
    $new_id=mysql_real_escape_string(stripslashes($_REQUEST['id']));
    $new_title=mysql_real_escape_string(stripslashes($_REQUEST['title']));
    $new_article=mysql_real_escape_string(stripslashes($_REQUEST['article']));

    echo 
    $thistitle;
    echo 
    'This is the ID:'.$new_id.'<br />';
    echo 
    'This is the Title:'.$new_title.'<br />';
    echo 
    'This is the article:'.$new_article.'<br />'

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,025
    Thanks
    2
    Thanked 314 Times in 306 Posts
    Which of the form values are not working?

    Your form should be submitting $_GET['id'], $_POST['title'], $_POST['id'], $_POST['date'] and $_POST['article'].

    If the missing values are those you are escaping, you likely don't have a database connection and the mysql_real_escape_string() function is returning nulls. A database connection is required before you call any database functions.

    By using $_REQUEST, you are potentially seeing only the last value from GPC (get, post, cookie), so if you have any cookies with those same names, you may not be seeing the actual form data. You should only use the actual $_GET or $_POST from your form.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    Regular Coder
    Join Date
    Apr 2013
    Posts
    136
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I am including database connection now
    and now I am getting:


    Notice: Undefined index: title
    Notice: Undefined index: article

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    There's no guarantee that $_REQUEST will ever be populated. The default request_order is nothing, and the default variable_order is EGPCS. These are both modifyable by the ini configurations and can include nothing. Request has always been unreliable at best, and a threat at worst.

    First step is to stop using request and use the appropriate $_GET/$_POST when needed. Debug your $_POST input to see what has been provided. If $_POST is empty, than edit-blog-script.php isn't receiving POST (which can be checked both server side and client side), and that, from what you have here, could only occur if you are using incorrect rewrite rules.

    It doesn't make sense that 'id' doesn't toss the same error though. If id is valid, than so should both title and article.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    Regular Coder
    Join Date
    Apr 2013
    Posts
    136
    Thanks
    3
    Thanked 0 Times in 0 Posts
    The ID is being passed through in the URL

    hmm, this is easy stuff, I've had it working before with a login?!

    Please help!

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by jarv81178 View Post
    The ID is being passed through in the URL

    hmm, this is easy stuff, I've had it working before with a login?!

    Please help!
    Ah yes of course it is. That makes sense now.
    And the results of your POST debug is?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #7
    Regular Coder
    Join Date
    Apr 2013
    Posts
    136
    Thanks
    3
    Thanked 0 Times in 0 Posts
    the errrors I am getting are:
    Notice: Undefined index

    i am using jquery mobile if that helps

    here

  • #8
    Regular Coder
    Join Date
    Apr 2013
    Posts
    136
    Thanks
    3
    Thanked 0 Times in 0 Posts
    here is my code:

    my form
    PHP Code:
    <?php
    session_start
    ();
    $_SESSION['ThisSiteID'] = $_GET['SiteID'];
    $_SESSION['PageID'] = $_GET['PageID'];
    $con=mysqli_connect("xxx","xxx","xxx","xxx");
    // Check connection
    if (mysqli_connect_errno())
      {
      echo 
    "Failed to connect to MySQL: " mysqli_connect_error();
      }
    mysql_connect("xxx""xxx""xxx");
    mysql_select_db("xxx");

    $id $_GET['id'];

    $query1 "SELECT * FROM app1_blog";
    $result1 mysql_query($query1);

    $qry="SELECT id,title,date,article,image1,image2,image3 FROM app1_blog WHERE id = '$id'";
    $cur=mysql_query($qry);
    while(
    $i=mysql_fetch_row($cur))
    {
    $id=$i[0];
    $title=$i[1];
    $date=$i[2];
    $article=$i[3];
    $image1=$i[4];
    $image2=$i[5];
    $image3=$i[6];
    }



    ?> 
    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
      <meta name="apple-mobile-web-app-capable" content="yes">
      <meta name="apple-mobile-web-app-status-bar-style" content="black">
      <title></title>
      
      
      
      <link rel="stylesheet" href="https://d10ajoocuyu32n.cloudfront.net/mobile/1.3.1/jquery.mobile-1.3.1.min.css">
      
      <!-- Extra Codiqa features -->
      <link rel="stylesheet" href="codiqa.ext.css">
      
      <!-- jQuery and jQuery Mobile -->
      <script src="https://d10ajoocuyu32n.cloudfront.net/jquery-1.9.1.min.js"></script>
      <script src="https://d10ajoocuyu32n.cloudfront.net/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>

      <!-- Extra Codiqa features -->
      <script src="https://d10ajoocuyu32n.cloudfront.net/codiqa.ext.js"></script>
       
    </head>
    <body>
    <!-- Home -->
    <div data-role="page" id="page<?php echo $id;?>">
        <div data-theme="a" data-role="header">
            <h3>
                Edit blog post
            </h3>
        </div>
        <div data-role="content">
            <h2>
                Blog
            </h2>
            <form method="post" action="edit-blog-script.php" name="form">
            <div data-role="fieldcontain">
                <label for="textinput1">
                    Title
                </label>
                <input name="title" id="textinput1" placeholder="" value="<?php echo $title;?>" type="text">
                <input name="id" placeholder="" value="<?php echo $id;?>" type="hidden">
            </div>
            <div data-role="fieldcontain">
                <label for="textinput2">
                    Date
                </label>
                <input name="date" id="textinput2" placeholder="" value="<?php echo $date;?>" type="text">
            </div>
            <div data-role="fieldcontain">
                <label for="textinput3">
                    Article
                </label>
                <textarea name="article" id="textarea1" placeholder=""><?php echo $article;?></textarea>
            </div>
                <img src="<?php echo $image1;?>" alt="image" width="288" >
                <img src="<?php echo $image2;?>" alt="image" width="288" >
                <img src="<?php echo $image3;?>" alt="image" width="288" >
            <input data-theme="b" value="Submit" type="submit">
            </form>
        </div>
    </div>
    </body>
    </html>

    edit code
    PHP Code:
    <?php
    include_once('config.php');

    $title=$_POST['title'];
    echo 
    $_POST['title'];
    $new_id=$_POST['id'];
    $title=$_POST['title'];
    $new_article=$_POST['article'];

    echo 
    'This is the ID:'.$new_id.'<br />';
    echo 
    'This is the Title:'.$title.'<br />';
    echo 
    'This is the article:'.$new_article.'<br />';
    //$sql = "UPDATE app1_blog SET title='$title',article='$article' WHERE id = '$id'";

    //$msg = 'Blog edited';
    //$result = mysql_query($sql,$link) or die('Error: ' . mysql_error() . '<br>SQL: ' . $sql);
    //header("Location: edit.php?msg=$msg&id=$id");
    //mysql_close($link);

    ?>

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Yep, its your JS. Fix that up instead:
    Code:
    aThis is the ID:10
    This is the Title:a
    This is the article:Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam porttitor risus arcu, auctor venenatis augue aliquet eget. Donec sed rhoncus urna. Nulla elit eros, facilisis nec semper id, luctus in eros. Sed sit amet pharetra metus. In purus erat, pretium et risus non, bibendum imperdiet turpis. Morbi tempor gravida suscipit. Maecenas porta libero eu nibh accumsan lobortis. Vestibulum justo nunc, luctus a feugiat sit amet, eleifend quis massa. Praesent nec vestibulum metus. Sed in urna leo. Praesent eget fringilla erat. Proin lacinia egestas lacus.
    Is what I see on submit.

    Edit:
    BTW, if nobody has mentioned this before I may as well now.
    Your PHP code should work *before* you add any javascript. That way when you add JS and it doesn't work, you know that its the JS that causes this.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #10
    Regular Coder
    Join Date
    Apr 2013
    Posts
    136
    Thanks
    3
    Thanked 0 Times in 0 Posts
    ok, so I have moved everything inside one page, I submit the form and it comes back blank?! grr


    here is my page

    PHP Code:
    <?php
    session_start
    ();
    $con=mysqli_connect("xxx","xxx","xxx","xxx");
    // Check connection
    if (mysqli_connect_errno())
      {
      echo 
    "Failed to connect to MySQL: " mysqli_connect_error();
      }
    mysql_connect("xxx""xxx""xxx");
    mysql_select_db("xxx");

    $id $_GET['id'];

    $query1 "SELECT * FROM app1_blog";
    $result1 mysql_query($query1);

    $qry="SELECT id,title,date,article,image1,image2,image3 FROM app1_blog WHERE id = '$id'";
    $cur=mysql_query($qry);
    while(
    $i=mysql_fetch_row($cur))
    {
    $id=$i[0];
    $title=$i[1];
    $date=$i[2];
    $article=$i[3];
    $image1=$i[4];
    $image2=$i[5];
    $image3=$i[6];
    }



    ?> 
    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
      <meta name="apple-mobile-web-app-capable" content="yes">
      <meta name="apple-mobile-web-app-status-bar-style" content="black">
      <title></title>
      
      
      
      <link rel="stylesheet" href="https://d10ajoocuyu32n.cloudfront.net/mobile/1.3.1/jquery.mobile-1.3.1.min.css">
      
      <!-- Extra Codiqa features -->
      <link rel="stylesheet" href="codiqa.ext.css">
      
      <!-- jQuery and jQuery Mobile -->
      <script src="https://d10ajoocuyu32n.cloudfront.net/jquery-1.9.1.min.js"></script>
      <script src="https://d10ajoocuyu32n.cloudfront.net/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>

      <!-- Extra Codiqa features -->
      <script src="https://d10ajoocuyu32n.cloudfront.net/codiqa.ext.js"></script>
       
    </head>
    <?php
    if(isset($_POST['submit'])){
    $new_title=mysql_real_escape_string(stripslashes($_POST["title"]));
    $new_article=mysql_real_escape_string(stripslashes($_POST["article"]));

    $sql "UPDATE app1_blog SET title='$new_title',article='$new_article' WHERE id = '$id'";

    $msg 'Blog edited';
    $result mysql_query($sql,$link) or die('Error: ' mysql_error() . '<br>SQL: ' $sql);
    header("Location: edit.php?msg=$msg&id=$id");
    }
    ?>
    <body>
    <!-- Home -->
    <div data-role="page" id="page<?php echo $id;?>">
        <div data-theme="a" data-role="header">
            <h3>
                Edit blog post
            </h3>
        </div>
        <div data-role="content">
            <h2>
                Blog
            </h2>
            <form method="post" action="<?php print $_SERVER["PHP_SELF"]; ?>" name="form">
            <div data-role="fieldcontain">
                <label for="textinput1">
                    Title
                </label>
                <input name="title" id="textinput1" placeholder="" value="<?php echo $title;?>" type="text">
                <input name="id" placeholder="" value="<?php echo $id;?>" type="hidden">
            </div>
            <div data-role="fieldcontain">
                <label for="textinput2">
                    Date
                </label>
                <input name="date" id="textinput2" placeholder="" value="<?php echo $date;?>" type="text">
            </div>
            <div data-role="fieldcontain">
                <label for="textinput3">
                    Article
                </label>
                <textarea name="article" id="textarea1" placeholder=""><?php echo $article;?></textarea>
            </div>
                <img src="<?php echo $image1;?>" alt="image" width="288" >
                <img src="<?php echo $image2;?>" alt="image" width="288" >
                <img src="<?php echo $image3;?>" alt="image" width="288" >
            <input data-theme="b" value="Submit" type="submit">
            </form>
        </div>
    </div>
    </body>
    </html>

  • #11
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    I am confused, you connect using the mysqli extension, but never use that connection ($con). Then you connect using mysql, but you don't specify a handle to continue using THAT connection, but you use mysql functions for querying, etc, throughout instead of mysqli...

    HTH
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #12
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,309
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Quote Originally Posted by whizard View Post
    I am confused
    Indeed you may think you are but you are not. It is actually Jarv who is confused

    See Jarv is a bit of an old skool legend around here who refuses to learn to debug, refuses to use var_dump($_POST), refuses to use print __LINE__ to test execution flow and never looks at error logs yet seems to continue taking php jobs while asking us to fix his errors for free lol.

    So whizard, fear not my friend, what may seem like symptoms of your grey matter disappearing is actually nothing to worry about

    Despite helping jarv personally many times and begging him to learn to debug and even showing in my signature not to use the $_POST['submit'] thing, jarv still ignores all advice and in his own posted code has just used the $_POST['submit'] thing again
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #13
    Regular Coder
    Join Date
    Apr 2013
    Posts
    136
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I'm sorry TangoForce but I didn't see your signature... duh, silly me!

    As for debugging.... I have been doing lots of that, I tried echoing out 'Form submitted' inside the conditional for isset submit

    It's not getting into that conditional therefore i can't get the form values?!

    and whizard, thanks but I'm not using the connection ($con) in this piece of code so I can remove that. thanks

  • #14
    Regular Coder
    Join Date
    Apr 2013
    Posts
    136
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Cool

    Can anyone please help me here?! xx

  • #15
    Regular Coder
    Join Date
    Apr 2013
    Posts
    136
    Thanks
    3
    Thanked 0 Times in 0 Posts
    hello?


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •