Results 1 to 7 of 7

Thread: Adding info

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2003
    Location
    Auckland
    Posts
    1,139

    Exclamation Adding info

    I have this code but nothing will add to my database... any ideas what is wrong?

    PHP Code:
    <?php

    mysql_connect 
    (localhostrootpassword);
    mysql_select_db (Database);

    ?>


    <?php

    if ($action == "save")
    {
    $result mysql_query ("INSERT INTO News Values ('','$header','$author','$body','$result_id','$attachimg','$BCC','$WLG','$AKL','$CHC','$NPL','$DUD','$PMR','$TRG','$OHA','$NZL','$KWI','$NZW')");

    ?>

    <font face="Verdana" size="2">
    <b><a href="index.php">Click here to return to the main index</a></b>

    <?php
    } else {
    ?>


    <form method="POST" action="add.php?action=save">


    <p>
    <font face="Verdana" size="1">

           

           <b>Header: </b>

           <input TYPE="text" NAME="header" SIZE="95"> <a href="javascript:popupPage3()">(help)</a></font></p>
        <p>

           

           <font face="Verdana" size="1">

           <b>Author: </b><input TYPE="text" NAME="author" SIZE="40" value="<?php echo $user_fullname?>"> 

           (Optional)&nbsp;&nbsp; <a href="javascript:popupPage4()">(help)</a></font></p>
        <p>

               <b><font face="Verdana" size="1">Result_id: 

               <input type="text" name="result_id" size="5">

               </font>

               </b>

               <font face="Verdana" size="1"><a href="javascript:popupPage7()">(help)</a></font></p>
        <p>
    <b><font face="Verdana" size="1">Image to show next to news item, just select the best option:</font><font face="arial" size="2"> </font>

               </font> 

               &nbsp;<select size="1" name="attachimg">

           <option selected value=""></option>

                  </select>

               </b>

               <font face="Verdana" size="1"><a href="javascript:popupPage8()">(help)</a></font></p>
        <p>
    <textarea rows="24" name="body" cols="117"></textarea></p>

               <p><b></p>

               <hr color="#000000" size="1">

               

                 

                <p><font face="Verdana" size="1">Your news item will automatically 

                be added to the front page of the site so if it does not need to go 

                on a sub section don't click any of these boxes. </font></b>

                <font face="Verdana" size="1"><a href="javascript:popupPage9()">(help)</a></font><b><font face="Verdana" size="1"> </font></p>

           <p><font face="Verdana" size="1">

                <input type="checkbox" name="BCC" value="1"></font></b><font size="1" face="Verdana">Bartercard 

                Cup&nbsp; | </font><b><font face="Verdana" size="1">

                <input type="checkbox" name="WLG" value="1"></font></b><font size="1" face="Verdana"> 

                Wellington | </font><b><font face="Verdana" size="1">

                <input type="checkbox" name="AKL" value="1"> </font></b>

                <font face="Verdana" size="1">Auckland | </font>           

               <b><font face="Verdana" size="1">

                <input type="checkbox" name="CHC" value="1"></font></b><font size="1" face="Verdana">Cantbuery&nbsp; 

                | </font><b><font face="Verdana" size="1">

                <input type="checkbox" name="NPL" value="1"></font></b><font size="1" face="Verdana"> 

                Taranaki | <b>

                <input type="checkbox" name="DUD" value="1"> </b>Otago (Southern 

                Alliance) | </font>           

               <b><font face="Verdana" size="1">

                <input type="checkbox" name="PMR" value="1"></font></b><font face="Verdana" size="1">Western 

                Alliance&nbsp; </font></p>

           <p><b><font face="Verdana" size="1">

           <input type="checkbox" name="TRG" value="1"></font></b><font size="1" face="Verdana"> 

           WaiCoa Bay | <b>

           <input type="checkbox" name="OHA" value="1"> </b>Defence |            

               <b><input type="checkbox" name="NZL" value="1"></b>International&nbsp; 

           | </font><b><font face="Verdana" size="1">

           <input type="checkbox" name="KWI" value="1"></font></b><font size="1" face="Verdana"> 

           Kiwis | <b><input type="checkbox" name="NZW" value="1"> </b>Warriors

           </font></p>

               <p>
    <font face="Verdana" size="1">

           

           <br>

           &nbsp;</font></p>

    <input type="submit" value="Submit" name="save"></p>

        </form>
    <?php
    }

    ?>

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    or die(mysql_error()); will save your life. Seriously.

    Code:
    $result = mysql_query ("INSERT INTO News Values  ('','$header','$author','$body','$result_id','$attachimg','$BCC','$WLG','$AKL','$CHC','$NPL','$DUD', '$PMR','$TRG','$OHA','$NZL','$KWI','$NZW')") or die(mysql_error());
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    By the way, that should produce an error, if anything is wrong. If you get no error, the problem isn't with the code.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2003
    Location
    Auckland
    Posts
    1,139
    Originally posted by The Hobo
    By the way, that should produce an error, if anything is wrong. If you get no error, the problem isn't with the code.
    Do you think it will be a problem with the way my database it set up? I get no errors?

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    How are you checking to see if the data is added? Is there possibly another SQL call somewhere that might be deleting the record?

    Do you have phpMyAdmin? If so, do something like this in your code:

    Code:
    $sql = "INSERT INTO News VALUES  ('','$header','$author','$body','$result_id','$attachimg','$BCC','$WLG'";
    $sql .= ",'$AKL','$CHC','$NPL','$DUD','$PMR','$TRG','$OHA','$NZL','$KWI','$NZW')";
    
    echo $sql;
    
    $result = mysql_query($sql) or die(mysql_error());
    That way it'll print out your SQL statement with the values in it. Copy what it outputs, and paste it into phpMyAdmin and see if it works that way. If it does, you'll know that there's nothing wrong with your SQL statement.

    If you still haven't figured it out, post a dump of your table layout and maybe we can find something there causing it.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    This is a long shot, but does this actually connect to your DB?
    PHP Code:
    mysql_connect (localhostrootpassword); 
    mysql_select_db (Database); 
    I'm guessing you changed the values, but if you're passing values like that, I don't know if you're even connecting, but then again, you'd probably get an error if you weren't, so !?
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  7. #7
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by ober0330
    This is a long shot, but does this actually connect to your DB?
    PHP Code:
    mysql_connect (localhostrootpassword); 
    mysql_select_db (Database); 
    I'm guessing you changed the values, but if you're passing values like that, I don't know if you're even connecting, but then again, you'd probably get an error if you weren't, so !?
    If he was trying to run a query without being connected to the database, he'd get an error.
    My evil laugh has a squeak in it.

    kristopherwilson.com

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