Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 16
  1. #1
    Member
    Join Date
    Mar 2012
    Posts
    55
    Member #
    31209
    I seem to have a problom posting to my my sql database.
    Can someone help me?

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Untitled Form</title>
    <link rel="stylesheet" type="text/css" href="view.css" media="all">
    <script type="text/javascript" src="view.js"></script>
     
    </head>
    <body id="main_body" >
       
        <img id="top" src="top.png" alt="">
        <div id="form_container">
       
            <h1><a>Untitled Form</a></h1>
            <form id="form_610728" class="appnitro"  method="post" action="postbook.php">
                        <div class="form_description">
                <h2>Untitled Form</h2>
                <p>This is your form description. Click here to edit.</p>
            </div>                       
                <ul >
               
                        <li id="li_2" >
            <label class="description" for="bname">Book Title </label>
            <div>
                <input id="element_2" name="bname" class="element text medium" type="text" maxlength="255" value=""/>
            </div><p class="guidelines" id="guide_2"><small>What is the book called?</small></p>
            </li>        <li id="li_1" >
            <label class="description" for="author">Author </label>
            <div>
                <input id="element_1" name="author" class="element text medium" type="text" maxlength="255" value=""/>
            </div><p class="guidelines" id="guide_1"><small>What is the authors name?</small></p>
            </li>        <li id="li_3" >
            <label class="description" for="desc">Give a brief description of the book. </label>
            <div>
                <textarea id="element_3" name="desc" class="element textarea medium"></textarea>
            </div><p class="guidelines" id="guide_3"><small>Please give a brief description of the book. It does not have to be exact. Please use spell-check and proper punctuation.</small></p>
            </li>        <li id="li_4" >
            <label class="description" for="series">Is this book part of a series? If so, What is the name? </label>
            <div>
                <input id="element_4" name="series" class="element text medium" type="text" maxlength="255" value=""/>
            </div><p class="guidelines" id="guide_4"><small>Is this book part of a series? If so, What is the name?</small></p>
            </li>
               
                        <li class="buttons">
                    <input type="hidden" name="form_id" value="610728" />
                   
                    <input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
            </li>
                </ul>
            </form>   
                </div>
        <img id="bottom" src="bottom.png" alt="">
    <br>
    <br>
    <table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
    <tr>
    <td>
    </td>
    </tr>
    </table>
        </body>
    </html>
    Code:
    <?php
     
    $host="localhost"; // Host name
    $username="____"; // Mysql username
    $password="-----"; // Mysql password
    $db_name="......"; // Database name
    $tbl_name="books"; // Table name
     
    // Connect to server and select database.
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");
     
    // Get values from form
    $bname=$_POST['bname'];
    $author=$_POST['author'];
    $desc=$_POST['desc'];
    $series=$_POST['series'];
     
    // Insert data into mysql
    $sql="INSERT INTO $tbl_name(bname, author, desc, series)VALUES('$bname', '$author', '$desc', 'series')";
    $result=mysql_query($sql);
     
    // if successfully insert data into database, displays message "Successful".
    if($result){
    echo "Successful";
    echo "<BR>";
    echo "<a href='newbook.php'>Back to main page</a>";
    }
     
    else {
    echo "ERROR";
    }
    ?>
     
    <?php
    // close connection
    mysql_close();
    ?>
    CREATE TABLE `books` (
    `bname` varchar(30) NOT NULL,
    `author` varchar(30) NOT NULL,
    `desc` text NOT NULL,
    `series` varchar(30) NOT NULL
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;

  2.  

  3. #2
    WDF Staff AlphaMare's Avatar
    Join Date
    Oct 2009
    Location
    Montreal, Canada
    Posts
    4,570
    Member #
    20277
    Liked
    878 times
    What error message are you getting?
    yoshee08 likes this.
    Good design should never say "Look at me!"
    It should say "Look at this." ~ David Craib


    http://digitalinsite.ca ~ my current site . . info@digitalinsite.ca ~ my email

    If you feel that someone's post helped you fix your problem, answered your question, or just made you feel better, feel free to "Like" their post. The "Like" link is at the bottom right of each post, along side the "reply" link. And if you are being helped here, try to help someone else - pass it on!

  4. #3
    Member
    Join Date
    Mar 2012
    Posts
    55
    Member #
    31209
    Sorry, I forgot to say. I get nothing. Nothing happens. There is no Error message, success message, and the data is not posted to the database. I'm not sure what is going on. http://phpcodechecker.com/ does not say anything is wrong.

  5. #4
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,716
    Member #
    5580
    Liked
    718 times
    See some changes below ... in red ...

    You are not expecting results from your query (you are updating it),
    so you only need to die if something goes wrong.

    If you do a select on the other hand, and expect results, then you
    check the number of rows in the result. (zero(0) = no results found).
    http://php.net/manual/en/function.mysql-num-rows.php

    real escape string sanitizes any incoming variables before injecting them into MySQL.


    <?php

    $host="localhost"; // Host name
    $username="____"; // Mysql username
    $password="-----"; // Mysql password
    $db_name="......"; // Database name
    $tbl_name="books"; // Table name

    // Connect to server and select database.
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");

    // Get values from form
    $bname=mysql_real_escape_string($_POST['bname']);
    $author=mysql_real_escape_string($_POST['author']);
    $desc=mysql_real_escape_string($_POST['desc']);
    $series=mysql_real_escape_string($_POST['series']);

    // Insert data into mysql
    $sql="INSERT INTO $tbl_name(bname, author, desc, series)VALUES('$bname', '$author', '$desc', '$series')";
    $result=mysql_query($sql) or die(mysql_error());

    echo "Successful";
    echo "<BR>";
    echo "<a href='newbook.php'>Back to main page</a>";
    mysql_close();
    ?>


  6. #5
    Member
    Join Date
    Mar 2012
    Posts
    55
    Member #
    31209
    So can I just use what you posted? Or do I have to add anything to it?

  7. #6
    Member
    Join Date
    Mar 2012
    Posts
    55
    Member #
    31209
    OK. I've done some progress. Using the script you gave me, it outputted an error. Using google, I came up with the answer to remove " or die(mysql_error())" from line 21 and add : $result = mysql_query($sql);
    if(!
    $result)
    {
    error_log("Query error ($sql): " . mysql_error());
    echo
    "<p class='error'>Sorry, there was a database error . . . blah, blah, blah</p>";
    echo
    "</body></html>";
    exit;
    }


    Now it gives me the Error code (that ^)

  8. #7
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,716
    Member #
    5580
    Liked
    718 times
    Relist your script and explain what the error code says ... (that ^) ??? don't know what that means.


  9. #8
    Member
    Join Date
    Mar 2012
    Posts
    55
    Member #
    31209
    <?php

    $host="localhost"; // Host name
    $username="____"; // Mysql username
    $password="-----"; // Mysql password
    $db_name="......"; // Database name
    $tbl_name="books"; // Table name

    // Connect to server and select database.
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");

    // Get values from form
    $bname=mysql_real_escape_string($_POST['bname']);
    $author=mysql_real_escape_string($_POST['author']);
    $desc=mysql_real_escape_string($_POST['desc']);
    $series=mysql_real_escape_string($_POST['series']);

    // Insert data into mysql
    $sql="INSERT INTO $tbl_name(bname, author, desc, series)VALUES('$bname', '$author', '$desc', '$series')";
    $result=mysql_query($sql) or die(mysql_error());

    echo "Successful";
    echo "<BR>";
    echo "<a href='newbook.php'>Back to main page</a>";
    mysql_close();
    ?>

    Above is my current script. Changing what you suggested, it now gives the output error marked in red. So it looks like that it can connect to the database, but for some reason, it is not posting the stuff into the database. I have checked all my spelling (book,books, ETC.) and everything looks fine.

    I'm not sure what to do next.

  10. #9
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,716
    Member #
    5580
    Liked
    718 times
    Change this line:
    $result=mysql_query($sql) or die(mysql_error());

    To this:
    mysql_query($sql) or die(mysql_error());


  11. #10
    Member
    Join Date
    Mar 2012
    Posts
    55
    Member #
    31209
    It responds with this. "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc, series)VALUES('test', 'stuff', 'blah blah blah', 'ttttt')' at line 1"


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

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

Search tags for this page

localhost 31209 basic form

Click on a term to search for related topics.
All times are GMT -6. The time now is 10:22 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com