Results 1 to 3 of 3

Thread: Having problems writing to mySQL using PHP

  1. #1
    Senior Member
    Join Date
    Apr 2005
    Location
    Bournemouth, Dorset
    Posts
    1,631
    Thanks
    13
    Thanked
    2 times in 2 posts

    Having problems writing to mySQL using PHP

    basically iam doing a simple news posting system, i did previously do one where the news articles are saved into a file and then read+formatted.
    now i want to use a database.
    i put a test story on the database and wrote the script to display the news table on the database, this works fine but its the posting iam having problems with.
    i post the news in the form - it then says posted and takes me to the page were the news is but theres no news and i cant really understand why
    addnews.php
    PHP Code:
    <?php
    if (!$_POST['submit'])
    {
    ?>

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
      <p>Title<input size="50" maxlength="250" type="text" name="title">
        <br>
        Contact info
        <input size="50" maxlength="250" type="text" name="contact">
      </p>
      <p>Story        <br>
          <textarea name="content" cols="40" rows="10"></textarea>
        <br>
        <input type="submit" name="submit" value="Add">
      </p>
    </form>
    <?php
    }
    else
    {
    $title $_POST['title'];
    $content $_POST['content'];
    $contact $_POST['contact'];
    include (
    'database_details.php');
    $query "INSERT INTO news(title, content, contact, timestamp) VALUES('$title', '$content', '$contact', NOW())";
    echo 
    'News added <a href=news.php>Click here to see your message</a>';
    mysql_close($connect);
    }
    ?>

    database_details.php
    PHP Code:
    <?php
    $connect 
    mysql_connect('host''username''passy') or die ('No connection could be made');
    mysql_select_db('database') or die ('unable to find database');
    ?>
    iam not sure if there is an error in the code or its my dodgy hosting playing up
    wont have to put up with that crap hosting for much longer though
    Last edited by Ramedge; 12-10-2005 at 09:16 PM.

  2. #2
    Senior Member
    Join Date
    Apr 2005
    Location
    Bournemouth, Dorset
    Posts
    1,631
    Thanks
    13
    Thanked
    2 times in 2 posts
    just realised that iam missing a input box in that form
    will just edit the code in my first post to update what i have changed.
    Last edited by Ramedge; 12-10-2005 at 09:13 PM.

  3. #3
    Senior Member Kezzer's Avatar
    Join Date
    Sep 2003
    Posts
    4,863
    Thanks
    12
    Thanked
    5 times in 5 posts
    $query = "INSERT INTO news(title, content, contact, timestamp) VALUES('$title', '$content', '$contact', NOW())";

    You're not doing a query to the database, you're simply assigning some values to a variable called query

    mysql_query("your query here");


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. My experience with Windows XP Pro x64 Edition
    By Paul Adams in forum Software
    Replies: 7
    Last Post: 20-04-2007, 11:59 PM
  2. Making PHP and MySQL Talk?
    By Dav0s in forum Software
    Replies: 4
    Last Post: 18-09-2005, 10:53 PM
  3. mySQL problems
    By Vini in forum Software
    Replies: 2
    Last Post: 22-08-2005, 01:01 PM
  4. PHP and MySQL
    By Kezzer in forum Software
    Replies: 4
    Last Post: 28-10-2003, 02:59 PM

Posting Permissions

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