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.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Help passing variables back to their original form textareas...

    Hi All,

    I have an addbook.php form for my clients. This information gets posted to the submitbook.php page that connects to the MySQL database and adds the records. Then sends them back to a blank addbook.php form to add another record. I would like some of the variables to be sent back to the original Input.php form so the client can add another record without 're-entering' everything all over again.

    Code Snipets----------

    addbook.php
    *************

    <?
    if ($subject == "") {
    echo '<input name="theme" type="text" id="theme" value="children" maxlength="20">';

    } else {
    What can I put here...or do I need anything here???
    }
    ?>
    ***************

    submitbook.php
    ***************

    <?php
    $title=$HTTP_POST_VARS['title'];
    $isbn=$HTTP_POST_VARS['isbn'];
    $author=$HTTP_POST_VARS['author'];
    $publisher=$HTTP_POST_VARS['publisher'];
    $commentary=$HTTP_POST_VARS['commentary'];
    $image=$HTTP_POST_VARS['image'];
    $theme=$HTTP_POST_VARS['theme'];
    $recommend=$HTTP_POST_VARS['recommend'];
    $referenceNum=$HTTP_POST_VARS['referenceNum'];
    $pricePub=$HTTP_POST_VARS['pricePub'];
    $priceAct=$HTTP_POST_VARS['priceAct'];
    $day=$HTTP_POST_VARS['day'];
    $month=$HTTP_POST_VARS['month'];
    $year=$HTTP_POST_VARS['year'];
    $trackingNumber=$HTTP_POST_VARS['trackingNumber'];
    $gradeLevel=$HTTP_POST_VARS['gradeLevel'];
    $copies=$HTTP_POST_VARS['copies'];
    $shippingDelay=$HTTP_POST_VARS['shippingDelay'];
    $distributor=$HTTP_POST_VARS['distributor'];
    $display=$HTTP_POST_VARS['display'];
    $date=$year."-".$month."-".$day;

    $tempdate = getdate( );
    $entryDate = $tempdate['year'].'-'.$tempdate['mon'].'-'.$tempdate['mday'];

    //Connect to database
    $database=mysql_pconnect('localhost','jandj_root');
    if (!$database)
    {
    header('Location: errorbook?type=1.php');
    exit;
    }

    mysql_select_db('books');
    $query="select * from jandj_jandj.books";
    $result=mysql_query($query);
    $column=mysql_fetch_array($result);
    $i = 0;
    while ($i<$copies) {
    $submit="INSERT INTO jandj_jandj.books VALUES ('','".$title."','".$isbn."','".$author."','".$date."','".$commentary."','','".$image."','','".$them e."','".$recommend."','".$referenceNum."','".$pricePub."','".$priceAct."','".$publisher."','".$track ingNumber."','".$gradeLevel."','".$shippingDelay."','".$distributor."','".$display."','".$entryDate. "')";
    $i++;
    $result=mysql_query($submit);
    }


    if ($result)
    {
    // Data submitted. Returning to main book page.';
    header('Location: addbook.php');
    Should I have anything here to send the variables back??

    } else {
    // header('Location: errorbook.php?type=2');
    echo 'Error submitting book info!<br>
    $submit = '.$submit;
    }



    ?>
    <p>&nbsp;</p>
    </body>
    </html>
    *************

    How can I get a variable sent back to the 'addbook.php' form and populated in it's respective field??

    Please let me know...I have been looking all over for a week now and have even posted this question in other forums with no responses.

    Thanks in advance,


    M

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,762
    Thanks
    19
    Thanked 155 Times in 146 Posts
    I would create/start a session here and store your reused values in SESSION variables (create the SESSION variables in submitbook.php, then recall them in addbook.php)...

    A link on SESSION variabels: http://us3.php.net/manual/en/ref.session.php

    a tutorial: http://codewalkers.com/tutorials/32/1.html
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #3
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your quick response,

    I am getting the following error:

    Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/jandj/public_html/jandjpanel/addbook.php:11) in /home/jandj/public_html/jandjpanel/addbook.php on line 122

    Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/jandj/public_html/jandjpanel/addbook.php:11) in /home/jandj/public_html/jandjpanel/addbook.php on line 122

    Here is what I have so far:

    addbook.php
    **********

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Add book</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="../jandj.css" rel="stylesheet" type="text/css">
    </head>

    <body>
    <?php
    global $title,$author,$subject,$month,$year,$subject,$publisher,$commentary;

    $title = $author = $subject = $month = $year = $subject = $publisher = $commentary ="";

    $isbn=$HTTP_POST_VARS['isbn'];
    if ($isbn != "") {
    include 'xmlparser_rc2.php';
    }
    ?>


    <div align="center"><font face="Verdana, Arial, Helvetica, sans-serif">Add book</font></div>
    <form name="lookupform" method="post" action="addbook_lookup.php">
    <span class="formcontent">ISBN new:</span>
    <? echo '<input name="isbn" type="text" value="'.$isbn.'" id="isbn">'; ?>
    <input type="submit" name="Submit2" value="Lookup">
    </form>

    <form name="form1" method="post" action="submitbook.php">
    <p><b></b></p>
    <table width="100%" border="0">

    <tr>
    <td><input type="submit" name="Submit" value="Submit"></td>
    <td>
    <? echo '<input name="isbn" type="hidden" value="'.$isbn.'">'; ?>

    </td>
    </tr>

    <tr>
    <td><span class="formcontent">J&amp;J Price:</span></td>
    <td><input name="priceAct" type="text" id="priceAct" maxlength="20"></td>
    </tr>
    <tr>
    <td><span class="formcontent">Publisher Price:</span></td>
    <td><input name="pricePub" type="text" id="pricePub" maxlength="20"></td>
    </tr>
    <tr>
    <td><span class="formcontent">Number of copies:</span></td>
    <td><input name="copies" type="text" id="copies" size="4" maxlength="3"></td>
    </tr>
    <tr>
    <td width="22%"><span class="formcontent">Title:</span> </td>
    <td width="78%">
    <?
    echo '<input name="title" type="text" id="title" size="50" value="'.$title.'">';
    ?>
    </td>
    </tr>
    <tr>
    <td><span class="formcontent">Author:</span></td>
    <td>
    <?
    echo '<input name="author" type="text" id="author" size="50" value="'.$author.'" maxlength="200">';
    ?>
    </td>
    </tr>
    <tr>
    <td><span class="formcontent">Publisher:</span></td>
    <td>
    <?
    echo '<input name="publisher" type="text" id="publisher" size="50" value="'.$publisher.'" maxlength="100">';
    ?>
    </td>
    </tr>
    <tr>
    <td><span class="formcontent">Distributor:</span></td>
    <td>
    <?
    echo '<input name="distributor" type="text" id="distributor" size="50" value="'.$distributor.'" maxlength="100">';
    ?>
    </td>
    </tr>
    <tr>
    <td><span class="formcontent">Date:</span></td>
    <td>
    <?
    echo '
    <input name="month" type="text" id="month" value="'.$month.'" size="3" maxlength="2">
    /
    <input name="year" type="text" id="year" value="'.$year.'" size="3" maxlength="2">';
    ?>
    (month/year)</td>
    </tr>
    <tr>
    <td><span class="formcontent">Commentary:</span></td>
    <td><textarea name="commentary" cols="50" rows="5" id="commentary"><? echo $commentary ?></textarea></td>
    </tr>
    <tr>
    <td><span class="formcontent">Image</span></td>
    <td>
    <?
    if ($isbn == "") {
    echo '<input name="image" type="text" id="image" value="na.gif" maxlength="50">';
    } else {
    echo '<input name="image" type="text" id="image" value="'.$isbn.'.jpg" maxlength="50">';
    }
    ?>
    </td>
    </tr>
    <tr>
    <td><span class="formcontent">Published</span></td>
    <td><input name="published" type="checkbox" id="published" value="checkbox"></td>
    </tr>
    <tr>
    <td><span class="formcontent">Theme:</span></td>
    <td>

    <?
    session_start();
    if (isset ($_SESSION['theme'])) {
    echo '<input name="theme" type="text" id="theme" value="'.$_SESSION['theme'].'">';
    } else {
    echo '<input name="theme" type="text" id="theme" value="children" maxlength="20">';
    }
    ?> />




    </td>
    </tr>
    <tr>
    <td><span class="formcontent">Recommended:</span></td>
    <td><input name="recommend" type="checkbox" id="recommend" value="1"></td>
    </tr>
    <tr>
    <td><span class="formcontent">Reference Num:</span></td>
    <td><input name="referenceNum" type="text" id="referenceNum" value="0" maxlength="20"></td>
    </tr>
    <tr>
    <td><span class="formcontent">Tracking Num:</span></td>
    <td><input name="trackingNumber" type="text" id="trackingNumber" value="000000000000" maxlength="20"></td>
    </tr>
    <tr>
    <td><span class="formcontent">Grade Level:</span></td>
    <td><input name="gradeLevel" type="text" id="gradeLevel" value="PreK-2" maxlength="20"></td>
    </tr>
    <tr>
    <td><span class="formcontent">Shipping Delay:</span></td>
    <td><input name="shippingDelay" type="text" id="shippingDelay" value="2" size="4" maxlength="4"></td>
    </tr>
    <tr>
    <td><span class="formcontent">Display on Site: </span></td>
    <td><select name="display" id="display">
    <option value="MB" selected>Madrid Books</option>
    <option value="JJ">J and J</option>
    <option value="Both">Both</option>
    <option value="None">Neither</option>
    </select>
    </td>
    </tr>
    </table>
    <p>&nbsp; </p>
    </form>

    </body>
    </html>
    ****************

    submitbook.php
    ****************

    <?php
    $title=$HTTP_POST_VARS['title'];
    $isbn=$HTTP_POST_VARS['isbn'];
    $author=$HTTP_POST_VARS['author'];
    $publisher=$HTTP_POST_VARS['publisher'];
    $commentary=$HTTP_POST_VARS['commentary'];
    $image=$HTTP_POST_VARS['image'];
    $theme=$HTTP_POST_VARS['theme'];
    $recommend=$HTTP_POST_VARS['recommend'];
    $referenceNum=$HTTP_POST_VARS['referenceNum'];
    $pricePub=$HTTP_POST_VARS['pricePub'];
    $priceAct=$HTTP_POST_VARS['priceAct'];
    $day=$HTTP_POST_VARS['day'];
    $month=$HTTP_POST_VARS['month'];
    $year=$HTTP_POST_VARS['year'];
    $trackingNumber=$HTTP_POST_VARS['trackingNumber'];
    $gradeLevel=$HTTP_POST_VARS['gradeLevel'];
    $copies=$HTTP_POST_VARS['copies'];
    $shippingDelay=$HTTP_POST_VARS['shippingDelay'];
    $distributor=$HTTP_POST_VARS['distributor'];
    $display=$HTTP_POST_VARS['display'];
    $date=$year."-".$month."-".$day;

    $tempdate = getdate( );
    $entryDate = $tempdate['year'].'-'.$tempdate['mon'].'-'.$tempdate['mday'];

    session_start();
    $_SESSION["theme"] = "$theme";



    //Connect to database
    $database=mysql_pconnect('localhost','jandj_root');
    if (!$database)
    {
    header('Location: errorbook?type=1.php');
    exit;
    }

    mysql_select_db('books');
    $query="select * from jandj_jandj.books";
    $result=mysql_query($query);
    $column=mysql_fetch_array($result);
    $i = 0;
    while ($i<$copies) {
    $submit="INSERT INTO jandj_jandj.books VALUES ('','".$title."','".$isbn."','".$author."','".$date."','".$commentary."','','".$image."','','".$them e."','".$recommend."','".$referenceNum."','".$pricePub."','".$priceAct."','".$publisher."','".$track ingNumber."','".$gradeLevel."','".$shippingDelay."','".$distributor."','".$display."','".$entryDate. "')";
    $i++;
    $result=mysql_query($submit);
    }


    if ($result)
    {
    // Data submitted. Returning to main book page.';
    header('Location: addbook.php');


    } else {
    // header('Location: errorbook.php?type=2');
    echo 'Error submitting book info!<br>
    $submit = '.$submit;
    }



    ?>
    <p>&nbsp;</p>
    </body>
    </html>
    **************

    I sense I've done something wrong here, I'm just not sure what. Can you give me any ideas?

    Thank you,

    M

  • #4
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,762
    Thanks
    19
    Thanked 155 Times in 146 Posts
    you only need to call session_start() once for each file that uses SESSION variables, and it should appear at the very beginning of your file before any HTTP header output has been sent to the browser....like this:

    PHP Code:
    <? session_start(); ?>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>

    ...and code continues here...
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #5
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok...slowly but surely...

    I'm no longer getting the error. I have placed the session_start() at the begining of the page. However, now that the variable is set, I can't seem to change it unless I clear cookies. How can this session variable be reset if the user begins entering new data?

    Ex:

    User has 30 books under the theme of 'Mystery'

    After they've entered these 30 they now have 15 under 'Children'

    However the variable is still set to 'Mystery' and it appears the only way to clear the current variable is to clear cookies or close the browser.

    I'm almost there...and you've already helped out imensely...

    Thanks,

    M

  • #6
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,762
    Thanks
    19
    Thanked 155 Times in 146 Posts
    well you could do a couple of things:

    1) you could just reassign the SESSION variable a different value every time the value changes....so, i.e., if $_SESSION['pet'] == 'dog', then you could change the value with this statement:

    PHP Code:
    $_SESSION['pet'] = 'cat'
    I think that should work, but if it doesn;t try #2...

    2) every time the value of, i.e., $_SESSION['pet'] changes, you could unset the variable and recreate it with a new value...so again, if $_SESSION['pet'] == 'dog', then:

    PHP Code:
    unset($_SESSION['pet']);
    $_SESSION['pet'] = 'cat'
    And when you want to kill the SESSION entirely, use session_destroy():

    PHP Code:
    // Unset all of the session variables.
    $_SESSION = array();

    // If it's desired to kill the session, also delete the session cookie.
    // Note: This will destroy the session, and not just the session data!
    if (isset($_COOKIE[session_name()])) {
       
    setcookie(session_name(), ''time()-42000'/');
    }

    // Finally, destroy the session.
    session_destroy(); 
    http://us3.php.net/manual/en/functio...on-destroy.php
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #7
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well...your option #1...I think I have that already. It looks to me like it should be working.

    Here is what I have, perhaps you can see my mistake:

    Code:

    addbook.php
    *************
    <? session_start(); ?>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Add book</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="../jandj.css" rel="stylesheet" type="text/css">
    </head>

    <body>
    <?php
    global $title,$author,$theme,$month,$year,$subject,$publisher,$commentary;

    $title = $author = $theme = $month = $year = $subject = $publisher = $commentary ="";

    $isbn=$HTTP_POST_VARS['isbn'];
    if ($isbn != "") {
    include 'xmlparser_rc2.php';
    }
    ?>


    <div align="center"><font face="Verdana, Arial, Helvetica, sans-serif">Add book</font></div>
    <form name="lookupform" method="post" action="addbook_lookup.php">
    <span class="formcontent">ISBN new:</span>
    <? echo '<input name="isbn" type="text" value="'.$isbn.'" id="isbn">'; ?>
    <input type="submit" name="Submit2" value="Lookup">
    </form>

    <form name="form1" method="post" action="submitbook.php">
    <p><b></b></p>
    <table width="100%" border="0">

    <tr>
    <td><input type="submit" name="Submit" value="Submit"></td>
    <td>
    <? echo '<input name="isbn" type="hidden" value="'.$isbn.'">'; ?>

    </td>
    </tr>

    <tr>
    <td><span class="formcontent">J&amp;J Price:</span></td>
    <td><input name="priceAct" type="text" id="priceAct" maxlength="20"></td>
    </tr>
    <tr>
    <td><span class="formcontent">Publisher Price:</span></td>
    <td><input name="pricePub" type="text" id="pricePub" maxlength="20"></td>
    </tr>
    <tr>
    <td><span class="formcontent">Number of copies:</span></td>
    <td><input name="copies" type="text" id="copies" size="4" maxlength="3"></td>
    </tr>
    <tr>
    <td width="22%"><span class="formcontent">Title:</span> </td>
    <td width="78%">
    <?
    echo '<input name="title" type="text" id="title" size="50" value="'.$title.'">';
    ?>
    </td>
    </tr>
    <tr>
    <td><span class="formcontent">Author:</span></td>
    <td>
    <?
    echo '<input name="author" type="text" id="author" size="50" value="'.$author.'" maxlength="200">';
    ?>
    </td>
    </tr>
    <tr>
    <td><span class="formcontent">Publisher:</span></td>
    <td>
    <?
    echo '<input name="publisher" type="text" id="publisher" size="50" value="'.$publisher.'" maxlength="100">';
    ?>
    </td>
    </tr>
    <tr>
    <td><span class="formcontent">Distributor:</span></td>
    <td>
    <?
    echo '<input name="distributor" type="text" id="distributor" size="50" value="'.$distributor.'" maxlength="100">';
    ?>
    </td>
    </tr>
    <tr>
    <td><span class="formcontent">Date:</span></td>
    <td>
    <?
    echo '
    <input name="month" type="text" id="month" value="'.$month.'" size="3" maxlength="2">
    /
    <input name="year" type="text" id="year" value="'.$year.'" size="3" maxlength="2">';
    ?>
    (month/year)</td>
    </tr>
    <tr>
    <td><span class="formcontent">Commentary:</span></td>
    <td><textarea name="commentary" cols="50" rows="5" id="commentary"><? echo $commentary ?></textarea></td>
    </tr>
    <tr>
    <td><span class="formcontent">Image</span></td>
    <td>
    <?
    if ($isbn == "") {
    echo '<input name="image" type="text" id="image" value="na.gif" maxlength="50">';
    } else {
    echo '<input name="image" type="text" id="image" value="'.$isbn.'.jpg" maxlength="50">';
    }
    ?>
    </td>
    </tr>
    <tr>
    <td><span class="formcontent">Published</span></td>
    <td><input name="published" type="checkbox" id="published" value="checkbox"></td>
    </tr>
    <tr>
    <td><span class="formcontent">Theme:</span></td>
    <td>

    <?

    if (!($_SESSION['theme'] == "")) {
    echo '<input name="theme" type="text" id="theme" value="'.$_SESSION['theme'].'">';
    } else {
    echo '<input name="theme" type="text" id="theme" value="" maxlength="20">';
    }
    ?>




    </td>
    </tr>
    <tr>
    <td><span class="formcontent">Recommended:</span></td>
    <td><input name="recommend" type="checkbox" id="recommend" value="1"></td>
    </tr>
    <tr>
    <td><span class="formcontent">Reference Num:</span></td>
    <td><input name="referenceNum" type="text" id="referenceNum" value="0" maxlength="20"></td>
    </tr>
    <tr>
    <td><span class="formcontent">Tracking Num:</span></td>
    <td><input name="trackingNumber" type="text" id="trackingNumber" value="000000000000" maxlength="20"></td>
    </tr>
    <tr>
    <td><span class="formcontent">Grade Level:</span></td>
    <td><input name="gradeLevel" type="text" id="gradeLevel" value="PreK-2" maxlength="20"></td>
    </tr>
    <tr>
    <td><span class="formcontent">Shipping Delay:</span></td>
    <td><input name="shippingDelay" type="text" id="shippingDelay" value="2" size="4" maxlength="4"></td>
    </tr>
    <tr>
    <td><span class="formcontent">Display on Site: </span></td>
    <td><select name="display" id="display">
    <option value="MB" selected>Madrid Books</option>
    <option value="JJ">J and J</option>
    <option value="Both">Both</option>
    <option value="None">Neither</option>
    </select>
    </td>
    </tr>
    </table>
    <p>&nbsp; </p>
    </form>

    </body>
    </html>
    *************

    submitbook.php
    *************
    <?php
    $title=$HTTP_POST_VARS['title'];
    $isbn=$HTTP_POST_VARS['isbn'];
    $author=$HTTP_POST_VARS['author'];
    $publisher=$HTTP_POST_VARS['publisher'];
    $commentary=$HTTP_POST_VARS['commentary'];
    $image=$HTTP_POST_VARS['image'];
    $theme=$HTTP_POST_VARS['theme'];
    $recommend=$HTTP_POST_VARS['recommend'];
    $referenceNum=$HTTP_POST_VARS['referenceNum'];
    $pricePub=$HTTP_POST_VARS['pricePub'];
    $priceAct=$HTTP_POST_VARS['priceAct'];
    $day=$HTTP_POST_VARS['day'];
    $month=$HTTP_POST_VARS['month'];
    $year=$HTTP_POST_VARS['year'];
    $trackingNumber=$HTTP_POST_VARS['trackingNumber'];
    $gradeLevel=$HTTP_POST_VARS['gradeLevel'];
    $copies=$HTTP_POST_VARS['copies'];
    $shippingDelay=$HTTP_POST_VARS['shippingDelay'];
    $distributor=$HTTP_POST_VARS['distributor'];
    $display=$HTTP_POST_VARS['display'];
    $date=$year."-".$month."-".$day;

    $tempdate = getdate( );
    $entryDate = $tempdate['year'].'-'.$tempdate['mon'].'-'.$tempdate['mday'];

    session_start();
    $_SESSION["theme"] = "$theme";



    //Connect to database
    $database=mysql_pconnect('localhost','jandj_root');
    if (!$database)
    {
    header('Location: errorbook?type=1.php');
    exit;
    }

    mysql_select_db('books');
    $query="select * from jandj_jandj.books";
    $result=mysql_query($query);
    $column=mysql_fetch_array($result);
    $i = 0;
    while ($i<$copies) {
    $submit="INSERT INTO jandj_jandj.books VALUES ('','".$title."','".$isbn."','".$author."','".$date."','".$commentary."','','".$image."','','".$them e."','".$recommend."','".$referenceNum."','".$pricePub."','".$priceAct."','".$publisher."','".$track ingNumber."','".$gradeLevel."','".$shippingDelay."','".$distributor."','".$display."','".$entryDate. "')";
    $i++;
    $result=mysql_query($submit);
    }


    if ($result)
    {
    // Data submitted. Returning to main book page.';
    header('Location: addbook.php');


    } else {
    // header('Location: errorbook.php?type=2');
    echo 'Error submitting book info!<br>
    $submit = '.$submit;
    }



    ?>
    <p>&nbsp;</p>
    </body>
    </html>
    *************

    With what I have so far, the 'theme' field comes up empty everytime I come back to the form to add another entry. What am I missing??

    Thanks,


    M

  • #8
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,762
    Thanks
    19
    Thanked 155 Times in 146 Posts
    try changing this code:

    PHP Code:
    <?

    if (!($_SESSION['theme'] == "")) {
    echo 
    '<input name="theme" type="text" id="theme" value="'.$_SESSION['theme'].'">';
    } else {
    echo 
    '<input name="theme" type="text" id="theme" value="" maxlength="20">';
    }
    ?>
    to:

    PHP Code:
    <?

    if (!empty($_SESSION['theme'])) {
    echo 
    '<input name="theme" type="text" id="theme" value="'.$_SESSION['theme'].'">';
    echo 
    '<br>the session variable is NOT empty';   // just some error checking here
    } else {
    echo 
    '<input name="theme" type="text" id="theme" value="" maxlength="20">';
    echo 
    '<br>the session variable is empty';    // more error checking
    }
    ?>
    if this prints 'the session variable is empty', then try printing the value of $_SESSION['theme'] to the browser...if its still empty, then in this line of code here:

    $_SESSION["theme"] = "$theme";
    it is likely that $theme doesn;t have a value or is empty....which means $HTTP_POST_VARS['theme'] is empty...se where I'm going with this....

    Moral of the story: you can print out all of your variables to the browser to find out which variables have values and which dont, and thus isolate the problem to particular section of code...


    And please use PHP tags when displaying your code in this post, it makes it easier to read: Please wrap PHP codes using the [PHP][/PHP] tag
    Last edited by chump2877; 06-12-2006 at 09:38 PM.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #9
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    FINALLY!!

    I think I've got it now!!

    This is what I've ended up with:

    addbook.php
    PHP Code:
    <?

    if (isset ($_SESSION['theme'])) {
    echo 
    '<input name="theme" type="text" id="theme" value="'.$_SESSION['theme'].'">';
    echo 
    '<br>the session variable is NOT empty';
    } else {
    echo 
    '<input name="theme" type="text" id="theme" value="" maxlength="20">';
    echo 
    '<br>the session variable is empty';
    }
    ?>
    AND

    submitbook.php
    PHP Code:
    <?php

    session_start
    ();

    $title=$HTTP_POST_VARS['title'];
    $isbn=$HTTP_POST_VARS['isbn'];
    $author=$HTTP_POST_VARS['author'];
    $publisher=$HTTP_POST_VARS['publisher'];
    $commentary=$HTTP_POST_VARS['commentary'];
    $image=$HTTP_POST_VARS['image'];
    $theme=$HTTP_POST_VARS['theme'];
    $recommend=$HTTP_POST_VARS['recommend'];
    $referenceNum=$HTTP_POST_VARS['referenceNum'];
    $pricePub=$HTTP_POST_VARS['pricePub'];
    $priceAct=$HTTP_POST_VARS['priceAct'];
    $day=$HTTP_POST_VARS['day'];
    $month=$HTTP_POST_VARS['month'];
    $year=$HTTP_POST_VARS['year'];
    $trackingNumber=$HTTP_POST_VARS['trackingNumber'];
    $gradeLevel=$HTTP_POST_VARS['gradeLevel'];
    $copies=$HTTP_POST_VARS['copies'];
    $shippingDelay=$HTTP_POST_VARS['shippingDelay'];
    $distributor=$HTTP_POST_VARS['distributor'];
    $display=$HTTP_POST_VARS['display'];
    $date=$year."-".$month."-".$day;

    $tempdate getdate( );
    $entryDate $tempdate['year'].'-'.$tempdate['mon'].'-'.$tempdate['mday'];

    //Connect to database
    $database=mysql_pconnect('localhost','jandj_root');
    if (!
    $database)
        { 
        
    header('Location: errorbook?type=1.php');  
        exit;
        }

    mysql_select_db('books');
    $query="select * from jandj_jandj.books";
    $result=mysql_query($query);
    $column=mysql_fetch_array($result);
    $i 0;
    while (
    $i<$copies) {
        
    $submit="INSERT INTO jandj_jandj.books VALUES ('','".$title."','".$isbn."','".$author."','".$date."','".$commentary."','','".$image."','','".$theme."','".$recommend."','".$referenceNum."','".$pricePub."','".$priceAct."','".$publisher."','".$trackingNumber."','".$gradeLevel."','".$shippingDelay."','".$distributor."','".$display."','".$entryDate."')";
        
    $i++;
        
    $result=mysql_query($submit);
    }


        if (
    $result)
        {
        
    // Data submitted.  Returning to main book page.';
                      
             
    $_SESSION["theme"] = "$theme";
             
    header('Location: addbook.php');

        
        } else {
        
    // header('Location: errorbook.php?type=2');  
        
    echo 'Error submitting book info!<br>
        $submit = '
    .$submit;
        }



    ?>
    Thank you for all of your help!!


    M


  •  

    Posting Permissions

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