All pastes #614330 Raw Edit

Stuff

public text v1 · immutable
·published 2007-07-11 14:16 UTC
rendered paste body
/*** connect to the database ***/
$link = @mysql_connect($hostname, $username, $password);

/*** check if the link is a valid resource ***/
if(is_resource($link))
    {
    /*** if we are successful ***/
    echo 'Connected successfully<br />';

    /*** select the database we wish to use ***/
    if(mysql_select_db("ComNet", $link) === TRUE)
        {
        /*** sql to INSERT a new record ***/
    $sql = "INSERT INTO units (`Name`)
        VALUES (`$var`)";

        /*** run the sql query ***/
        if(mysql_query($sql, $link))
            {
            echo 'New record created successfully<br />';
            }
        else
            {
            echo 'Unable to INSERT data: <br />' . $sql .'<br />' . mysql_error();
            }
        }
    /*** if we are unable to select the database show an error ***/
    else
        {
        echo 'Unable to select database';
        }
    /*** close the connection ***/
    mysql_close($link);
    }
else
    {
    /*** if we fail to connect ***/
    echo 'Unable to connect';
    }
?>



using http://localhost/addunit.php?unit=g6

respownds with

Connected successfully
Unable to INSERT data: 
INSERT INTO units (`Name`) VALUES (`G6`)
Unknown column 'G6' in 'field list'