SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast bjoddn's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can't use INSERT INTO table SET

    I recently put MySql and PHP on my PC at home and it works except for I can't upload text and stuff from my browser, I always have to use phpMyAdmin and that is a bummer.

    I have tried using the same script on my virtual host and there it all works like a charm so I guess it's something I may have done wrong when I installed.

    Here is the form I am using:

    PHP Code:
    <form action="<?PHP_SELF?>" method="post">
    <p>Fyrirsögn:<br />
    <input type="text" name="fyrirsogn" size="40"><br />
    <p>Texti:<br />
    <textarea name="texti" rows="10" cols="40"></textarea><br />
    <input type="submit" name="senda" value="SUBMIT"><br />
    </p>
    </form>

    <?php
        
    //Tengi mig við databeis með $dbcnx
        
    $dbcnx = @mysql_connect("localhost""bjoddn_bjoddn""ectivers");

        if(!
    $dbcnx)  {
            echo (
    "<p>Get ekki tengst gagnagrunni</p>");
        exit();
        }

        
    //Velja databeis
        
    if(! @mysql_select_db("bjoddn_gabriella") ) {
            echo(
    "<p>Get sko ekki tengst gagnagrunni</p>");
        exit();
        }

        
    //útbúa þannig að formið lesi enterstrokes og þv_uml_kt
        
    $texti ereg_replace("\r","",$texti);
        
    $texti ereg_replace("\n\n","</p><p>",$texti);
        
    $texti ereg_replace("\n","<br>",$texti);

    if (
    $senda == "SUBMIT") {
            
    $sql "INSERT INTO dagbok SET
                fyrirsogn='
    $fyrirsogn',
                texti='
    $texti',
                dagsetning=CURDATE()"
    ;


              if (@
    mysql_query($sql)) {
                echo(
    "<p>Færslu hefur verið bætt við</p>");
              } else {
                echo(
    "<p>Villa: " .
                 
    mysql_error() . "</p>");
            }
        }

    ?>
    And the thing is, I don't get any error message, the text in the form just dissapears when I push SUBMIT and nothing happens.


    And there is more that might be related.

    when I use this stuff here :

    PHP Code:
    <?
    include("../config.php");

    //Tengjast grunni
     
    $connection mysql_connect("$servername""$dbusername""$dbpassword") or die ("Unable to connect!");

     
    //Velja töflu
     
    mysql_select_db("$dbname") or die ("Unable to select database!");


    //Velja allar færslur úr databeis
    $query "SELECT fyrirsogn, texti, dagsetning FROM hugleidingar WHERE id='$id'";
    $result mysql_query($query) or die ("Error in query: $query. " mysql_error());

    // Fá niðurstöðu sem object
     
    $row mysql_fetch_object($result);

     include_once(
    "function.php");

     
    // Prenta draslið
    if ($row)
    {

    echo(
    "<b>$row->fyrirsogn</b><br><br>");
    echo(
    "$row->texti<br><br>");
    echo 
    "" db_to_form($row->dagsetning".");



    }else{

    echo(
    "Hér er ekkert til að skoða.");

    }
    // Loka grunni
     
    mysql_close($connection);
     
    ?>
    it doesn't read what's in my table. But when I skip the WHERE id='$id' in the SELECT clause, it gives me the first row no matter what ID I want to see.


    This is getting long enough.

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    Svj
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    register_globals=Off in php.ini?

    Then $senda & $id are empty
    Use $senda = $_POST["senda"] etc to get the form values

  3. #3
    SitePoint Enthusiast bjoddn's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried the register_globals=Off thing.
    I tried changing it to register_globals=On and
    I tried changing it to ;register_globals=Off
    Nothing worked

    Just to make things clear, I find it hard to belive this problem has anything to do with the code, since it always works on my host, just not on my PC.

    Here you can see an examle of what I mean :
    This is on my host

    This is on my PC

    Now when you press the blue links, an article should come up but on my PC the message for nothing being in my database just shows up.

    It must be something I did wrong when I installed or configured or whatever. Could somebody post an example file for my.cnf, my.ini and php.ini so I can compare or just send it to me at bjorni@bjoddn.net.

    I am using Win2K pro, PHP 4.2.3 and MySql 3.29.39


    Thanx

  4. #4
    SitePoint Enthusiast bjoddn's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well...nevermind, I got it to work although I don't actually know how.

  5. #5
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    Svj
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Restarted the web server? (no, of course you did that before, when you changed php.ini)


Bookmarks

Posting Permissions

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