Results 1 to 14 of 14

Thread: Insert into Mysql Table

  1. #1
    scoutt
    Guest
    do waht you have but just make things to a varialbe. if you are getting those from a form then it would look like this. I wouldn't put the image in the DB as that will make it big fast, jut put the path in it or the name
    PHP Code:
    <?php

    $connection 
    mysql_connect ("localhost","stickman373","******");
    mysql_select_db("stickman373_uk_db"); 
    $result mysql_query("INSERT INTO dvd (Title,Review,Image,Other) VALUES ('".$_REQUEST['Title']."','".$_REQUEST['Review']."','".$_REQUEST['image_name']."','"$_REQUEST['other']."' ) 
    "
    ); 

    if(!
    result

    echo 
    "INSERT unsuccessful: "mysql_error(); 
    exit; 


    else 

    print (
    "Thanks for submitting details."); 


    ?>

  2. #2
    Fanatic Member stickman373's Avatar
    Join Date
    Mar 2001
    Location
    MA
    Posts
    909
    how do I assign things to those variables? When i make a form to i set the submit button to the script?

  3. #3
    scoutt
    Guest
    easy, that is regular html. either you have it on the same page or on a different page it is all the same.

    <form action="yourpage.php" method="post">
    <input type=text name=Title>
    <textarea name=Review rows="6" cols="30"></textarea>
    <input type=text name=image>
    <input type=text name=Other>
    <input type=submit name=send value="Send Review">
    </form>

    the only problem is that if you want to upload an image you will have to add things to the form tag so you can. then you have to hve an upload script in your regular script.

    see the name of each input? that is th evariable name you use on the $_REQUEST[] variable. make since?

  4. #4
    Fanatic Member stickman373's Avatar
    Join Date
    Mar 2001
    Location
    MA
    Posts
    909
    thanks, that's what i needed, i'm just storing the URL for the images so it should be fine

  5. #5
    Fanatic Member stickman373's Avatar
    Join Date
    Mar 2001
    Location
    MA
    Posts
    909
    i'm getting an error with the script

    Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in insert.php on line 6

    PHP Code:
    <?php

    $connection 
    mysql_connect ("localhost","stickman373","******");
    mysql_select_db("stickman373_uk_db");

    mysql_query("INSERT INTO dvd (Title,Review,Image,Other) VALUES ('.$_REQUEST['Title'].','.$_REQUEST['Review'].','.$_REQUEST['image'].','$_REQUEST['other'].' );

    echo mysql_error(); 

    ?>
    calling it with this html on a different page

    <form action="insert.php" method="post">
    <input type=text name=Title>
    <textarea name=Review rows="6" cols="30"></textarea>
    <input type=text name=image>
    <input type=text name=Other>
    <input type=submit name=send value="Send Review">
    </form>
    Last edited by stickman373; Jul 16th, 2002 at 09:52 AM.

  6. #6
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    you forgot the double quotes in this statement:
    PHP Code:
    mysql_query("INSERT INTO dvd (Title,Review,Image,Other) VALUES ('".$_REQUEST['Title']."',
    '"
    .$_REQUEST['Review']."','".$_REQUEST['image']."','".$_REQUEST['other']."')"); 
    Last edited by cpradio; Jul 16th, 2002 at 10:01 AM.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  7. #7
    Fanatic Member stickman373's Avatar
    Join Date
    Mar 2001
    Location
    MA
    Posts
    909
    now i get this:

    Parse error: parse error in insert.php on line 6

  8. #8
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    I missed the quote at the very end right after the last .
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  9. #9
    Fanatic Member stickman373's Avatar
    Join Date
    Mar 2001
    Location
    MA
    Posts
    909
    you edited the code in you post above right? i tried it again and i still get Parse error: parse error in insert.php on line 6 what am i doing wrong

  10. #10
    Fanatic Member stickman373's Avatar
    Join Date
    Mar 2001
    Location
    MA
    Posts
    909
    sorry double post read above
    Last edited by stickman373; Jul 16th, 2002 at 09:37 AM.

  11. #11
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    Try it again, a . (period) was missing.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  12. #12
    Fanatic Member stickman373's Avatar
    Join Date
    Mar 2001
    Location
    MA
    Posts
    909
    almost there, what is wrong on line 1

    You have an error in your SQL syntax near '' at line 1

  13. #13
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    put a parenthesis after the last '
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  14. #14
    Fanatic Member stickman373's Avatar
    Join Date
    Mar 2001
    Location
    MA
    Posts
    909
    thanks it works

Posting Permissions

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



Click Here to Expand Forum to Full Width