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 10 of 10
  1. #1
    New Coder
    Join Date
    Apr 2009
    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts

    What do i have Wrong (Data not being added to DB)

    PHP 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=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    <?php
    include ("config.php"); 
    mysql_select_db ("$dbname") or die ("Cannot Connect to the Database") ;
    $adddata "INSERT INTO `db_data` (
                            `title`, 
                            `subtitle`, 
                            `text`, 
                            `moretext`) 
                            VALUES ( '$title', '$subtitle', '$text', '$moretext' )"
    ;
    if(isset(
    $newpost) && $newpost=="yes") {
    mysql_query($adddata) or die("Could not complete posting") ; 
     
    $adddata2 "INSERT INTO `db_data` (
                            `title`, 
                            `subtitle`, 
                            `text`, 
                            `moretext`) 
                            VALUES ( 'title', 'subtitle', 'text', 'moretext' )"
    ;
    if(isset(
    $newpost) && $newpost=="test") {
    mysql_query($adddata2) or die("Could not complete posting") ; 
     
    ?>
    What is wrong with that? All i get is

    Code:
    Parse error: syntax error, unexpected $end in /home/content/k/i/n/kingdomworks1/html/geeklog/phptest/index.php on line 28
    *After reading the forum rules i edited my title to make it more relevant. ,well at least to the below post
    Last edited by jman888; 04-29-2009 at 08:26 PM.

  • #2
    Regular Coder
    Join Date
    Apr 2009
    Location
    somewhere over the rainbow
    Posts
    105
    Thanks
    2
    Thanked 14 Times in 14 Posts
    you are missing the `if` ends -> }

  • #3
    New Coder
    Join Date
    Apr 2009
    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Eran View Post
    you are missing the `if` ends -> }
    then what should it look like

  • #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,304
    Thanks
    4
    Thanked 204 Times in 201 Posts
    You're missing the closing braces for both of your if statements.

    PHP Code:
    if(isset($newpost) && $newpost=="yes") {
    mysql_query($adddata) or die("Could not complete posting") ; 
     
    $adddata2 "INSERT INTO `db_data` (
                            `title`, 
                            `subtitle`, 
                            `text`, 
                            `moretext`) 
                            VALUES ( 'title', 'subtitle', 'text', 'moretext' )"
    ;
    // <-- This was missing
    if(isset($newpost) && $newpost=="test") {
    mysql_query($adddata2) or die("Could not complete posting") ;
    // <-- This was missing 
    Dave .... HostMonster for all of your hosting needs

  • Users who have thanked djm0219 for this post:

    jman888 (04-29-2009)

  • #5
    New Coder
    Join Date
    Apr 2009
    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Ok now another Question.
    www.deadant.org/phptest/index.php?newpost=test

    Why doesnt it insert anything into my DB?

  • #6
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,304
    Thanks
    4
    Thanked 204 Times in 201 Posts
    The link doesn't help at all. You have no form values in what you posted nor is there anything that is retrieving, checking or setting the variables you're trying to use in your SQL.
    Dave .... HostMonster for all of your hosting needs

  • #7
    New Coder
    Join Date
    Apr 2009
    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Config.php
    PHP 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=iso-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>
    </body>
    </html>
    <?php
    $dbname 
    "" 
    $dbpass "" 
    $dbuser "" 
    $dbhost "" 
    $connect mysql_connect($dbhost$dbuser$dbpass) or die("Cannot Connect") ;
    ?>
    index.php
    PHP 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=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    <?php
    include ("config.php"); 
    mysql_select_db ("$dbname") or die ("Cannot Connect to the Database") ;
    $adddata "INSERT INTO `db_data` (
                            `title`, 
                            `subtitle`, 
                            `text`, 
                            `moretext`) 
                            VALUES ( '$title', '$subtitle', '$text', '$moretext' )"
    ;
    if(isset(
    $newpost) && $newpost=="yes") {
    mysql_query($adddata) or die("Could not complete posting") ; 
     
    $adddata2 "INSERT INTO `db_data` (
                            `title`, 
                            `subtitle`, 
                            `text`, 
                            `moretext`) 
                            VALUES ( 'title', 'subtitle', 'text', 'moretext' )"
    ;
    // <-- This was missing
    if(isset($newpost) && $newpost=="test") {
    mysql_query($adddata2) or die("Could not complete posting") ;
    // <-- This was missing   
    ?>
    im starting on a new website, wanting it to be kinda like a cms but mostly just something that looks like static html but if logged in i can just edit my pages.
    And i was testing out to see if it can insert into my db and its not working.
    i want index.php?newpost=yes to add the basic data just for testing for now

    ie, i wanna be able to go to ?newpost=test and have it just insert the names of the normally would be variables.
    Last edited by jman888; 04-29-2009 at 10:21 PM. Reason: clarifying

  • #8
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts
    You need to create a form where you will insert the values into your form. Then you'll pass those values to your script to add them to the database.

    Take is slow, and you'll begin to understand things a little better.

    Your want to add/insert things into a database. Yet you haven't created a form to tell your script what values you want to insert.

  • #9
    New Coder
    Join Date
    Apr 2009
    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Isnt that done with something like

    PHP Code:
    $value=$_POST['formvalue']; 
    ??

  • #10
    New Coder
    Join Date
    Jan 2009
    Posts
    91
    Thanks
    17
    Thanked 1 Time in 1 Post
    Read this

    Also your names for your input fields would be:

    $title
    $subtitle
    $text
    $moretext


  •  

    Posting Permissions

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