Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP question

  • 25-02-2004 5:36pm
    #1
    Closed Accounts Posts: 414 ✭✭


    Hey can anybody tell me whats wrong with this code. Whenever i press the submit button it does not seem to execute anything. I am using foxserve as my localhost and i am logged into MYSQLadmin as sleekfx. Can anybody shed some much needed light on the matter.


    Thanks.


    <HTML>
    <HEAD>
    <TITLE>Putting data</TITLE>
    </HEAD>
    <BODY>
    <?php
    /* This program enters news items into a database */

    if(isset($submit)) {

    $db = mysql_connect ("localhost", "sleekfx");

    mysql_select_db ("DBNAME", $db);

    $date = date("Y-m-d");

    $sql = "INSERT INTO news

    VALUES (NULL, '$heading','$body', '$date',
    '$auth', '$auth_email')";

    mysql_query($sql);

    print("<h2>The data has been entered.</h2>");
    print("<b>You can add another news story below</b>");

    }
    ?>

    <h1>Enter your news item into the database</h1>
    <form action="data_in.php" method="post"><br>
    Name:<br> <input type ="text" name="auth"> <br>
    Email:<br> <input type ="text" name="auth_email"><br>
    Heading:<br> <input type ="text" name="auth"> <br>
    News:<br> <input type ="text" name="body"> <br>

    <input type="submit" name="submit" value="Submit News!">
    </form>
    </body>
    </html>


Comments

  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    My guess would be that you have to remove the ' from the variable names in the SQL statement. It could think that you are trying to insert literals and not variable values...


  • Banned (with Prison Access) Posts: 16,659 ✭✭✭✭dahamsta


    Is DBNAME the actual name of the database? Are you getting any output at all?

    Try turning error reporting up full by adding this at the top of your script:

    [PHP]error_reporting(E_ALL);[/php]adam


  • Registered Users, Registered Users 2 Posts: 912 ✭✭✭chakotha


    Put
    if (!mysql_query($sql)) {
    die("Problems with the query: ".mysql_error());
    }

    instead of
    mysql_query($sql);


  • Closed Accounts Posts: 414 ✭✭Divine


    no dooddle_sketch that is not the problem, i considered that ages ago.

    I have tried the other suggestions but nothing seems to be happening at all? Can anyone put it through their own localhost and see what happens. yes the name of the database is DBNAME but nothings ****ING HAPPENING AND IVE BEEN AT IT FOR THE LAST 6 ****ING HOURS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


  • Registered Users, Registered Users 2 Posts: 912 ✭✭✭chakotha


    You haven't provided a password. Try

    [PHP]
    $dbcnx = @mysql_connect ("localhost", "sleekfx", "your_mysql_password");

    if (!$dbcnx){
    echo("<P>Unable to connect to the server at this time.</P>");
    exit();
    }
    //select the database
    if ( ! @mysql_select_db(&quot;DBNAME")){
    echo("<P>Unable to locate the database at this time.</P>");
    exit();
    }
    [/PHP]

    If your password is "" it might be worth trying anyway to see if you can connect to MySQL


  • Advertisement
  • Closed Accounts Posts: 414 ✭✭Divine


    ok i just tried that but i am getting no sort of response at all. I give up i dont know what to do. This is for a dating website so i was wondering could anyone recommend a book that would teach you PHP and include functions you would be likely to find included in a dating site.

    Thanks,


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    In fairness, you seem to have bitten off more than you can chew. Either lower your targets or farm it out.


  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m


    Originally posted by Divine
    <HTML>
    <HEAD>
    <TITLE>Putting data</TITLE>
    </HEAD>
    <BODY>
    <?php
    /* This program enters news items into a database */

    if(isset($submit)) {

    $db = mysql_connect ("localhost", "sleekfx");

    mysql_select_db ("DBNAME", $db);

    $date = date("Y-m-d");

    $sql = "INSERT INTO news

    VALUES (NULL, '$heading','$body', '$date',
    '$auth', '$auth_email')";

    mysql_query($sql);

    print("<h2>The data has been entered.</h2>");
    print("<b>You can add another news story below</b>");

    }
    ?>

    <h1>Enter your news item into the database</h1>
    <form action="data_in.php" method="post"><br>
    Name:<br> <input type ="text" name="auth"> <br>
    Email:<br> <input type ="text" name="auth_email"><br>
    Heading:<br> <input type ="text" name="auth"> <br>
    News:<br> <input type ="text" name="body"> <br>

    <input type="submit" name="submit" value="Submit News!">
    </form>
    </body>
    </html>

    OK had a quick look and the thing that strikes me are these:

    1.The variable you are passing, would be called $auth, $auth_email, $auth and $body
    So first of all you got two fields of the form named the same - that is a problem


    2. The php code for feeding information for the database uses variables called:
    $heading, $body, $date, $auth, $auth_email

    Where is the $heading variable in your form??


  • Registered Users, Registered Users 2 Posts: 1,023 ✭✭✭[CrimsonGhost]


    To start with for each of your mysql_<functionname> calls do something like
    mysql_query($sql) or die(mysql_error());
    This will hopefully show up any problems you have connecting/talking to the database.

    Are you getting any error messages at all?


  • Closed Accounts Posts: 2,028 ✭✭✭oq4v3ht0u76kf2


    [PHP]
    if(isset($submit)) {
    [/PHP]

    Are you sure register_globals is turned on? If not, you may have to specify $_POST rather than just using $submit... try changing that before you mess with anything else. All modern builds come with register_globals turned off by default... you'll also have to change all other references to variables to $_POST.


  • Advertisement
  • Closed Accounts Posts: 2,028 ✭✭✭oq4v3ht0u76kf2


    Here, this code should work for you. It is basically the same as your code except slightly cleaner and, um, works. I tested it myself. Make sure you set the action value in the form tag to point to the file itself. Good luck.

    [PHP]<html>
    <?php
    /* news.php, for Divine by Bob Burke
    You must define these variables */
    $dbHost = ""; // Database host, e.g. "localhost"
    $dbUser = ""; // Database username, e.g. "bob"
    $dbPass = ""; // Database password
    $dbName = ""; // Database name, e.g. "products"
    ?>

    <html>
    <head>
    <title>Putting data</title>
    </head>
    <body>

    <?php
    if(isset($_POST)) {

    mysql_connect($dbHost, $dbUser, $dbPass) or die("Database error: ".mysql_error());
    mysql_select_db($dbName) or die("Database error: ".mysql_error());

    $date = date("Y-m-d");

    $sql = "INSERT INTO `news` "
    . "VALUES (NULL, '".$_POST."', "
    . "'".$_POST."', '".$date."', "
    . "'".$_POST."', '".$_POST."');";

    $query = mysql_query($sql) or die("Database error: ".mysql_error());

    print("<h2>The data has been entered.</h2><br />");
    print("<b>You can add another news story below</b><br />");

    }
    ?>

    <h1>Enter your news item into the database</h1>
    <form action="./news.php" method="post"><br>
    Name:<br> <input type ="text" name="auth"> <br>
    Email:<br> <input type ="text" name="auth_email"><br>
    Heading:<br> <input type ="text" name="heading"> <br>
    News:<br> <input type ="text" name="body"> <br>

    <input type="submit" name="submit" value="Submit News!">
    </form>
    </body>
    </html>[/PHP]


  • Closed Accounts Posts: 414 ✭✭Divine


    ok Orange_Rhino i have tried that but there still does not seem to be anything happening. What i did was:

    Log into phpmyAdmin as "sleekfx" with a password of "password1".

    I set up a database called "des" that only i have access to when i am logged in as "sleekfx".

    I set up a table called news and inserted the required fields.

    I have made alterations to the code you have given me but still nothing seems to be happening. When i press the submit button the information just vanishes but nothing actually happens. I do not get the message saying "The data has been entered". In fact nothing happens at all. I do not get any error messages or anything as [CrimsonGhost] mentioned. My screen just stays the same except the information disappears.

    Oh and also the register_globals is in fact turned off whether or not that actually makes a differance with the new code you have given me. Below is the code you gave me and the changes i have made to it. Any more ideas id really appreciate it.

    Thanks,

    Des.



    <html>
    <head>
    <title>Putting data</title>
    </head>
    <body>

    <?php
    if(isset($_POST)) {

    mysql_connect($localhost, $sleekfx, $password1) or die("Database error: ".mysql_error());
    mysql_select_db($des) or die("Database error: ".mysql_error());

    $date = date("Y-m-d");

    $sql = "INSERT INTO `news` "
    . "VALUES (NULL, '".$_POST."', "
    . "'".$_POST."', '".$date."', "
    . "'".$_POST."', '".$_POST."');";

    $query = mysql_query($sql) or die("Database error: ".mysql_error());

    print("<h2>The data has been entered.</h2><br />");
    print("<b>You can add another news story below</b><br />");

    }
    ?>

    <h1>Enter your news item into the database</h1>
    <form action="data_in.php" method="post"><br>
    Name:<br> <input type ="text" name="auth"> <br>
    Email:<br> <input type ="text" name="auth_email"><br>
    Heading:<br> <input type ="text" name="heading"> <br>
    News:<br> <input type ="text" name="body"> <br>

    <input type="submit" name="submit" value="Submit News!">
    </form>
    </body>
    </html>


  • Closed Accounts Posts: 2,028 ✭✭✭oq4v3ht0u76kf2


    Try:

    mysql_connect("localhost", "sleekfx", "password1") or die("Database error: ".mysql_error());
    mysql_select_db("des") or die("Database error: ".mysql_error());

    Instead of your corresponding lines.


Advertisement