SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Feb 2003
    Location
    Shropshire
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problems with PHP connecting to MySQL

    I have been developing a database driven area to a new client's site using Kevin Yank's book and another book as a guide as I am new to PHP and MySQL. I am having problems now I have uploaded the pages for testing on the remote server.

    I am getting errors regarding not being able to connect to the database etc, but also I have some of the scripting showing on the page.

    I have only checked 2 pages so far and keep looking through the code but can't see any errors and I am hoping someone here will be able to help me.

    The code for the 2 pages and there url's so you can see what is happening are below.


    Code1 - view at www.ajcgroup.co.uk/admin/vacancies/vacancies.php

    PHP Code:
     <?php
    $cnx 
    mysql_connect('mysql.echocd.co.uk','username','password');
    if (!
    $cnx) {
       echo (
    '<p>Could not connect to MySQL server</p>');
       exit;
    }
    $db=mysql_select_db('conman',$cnx);
    if (!
    $db) {
       echo (
    '<p>Could not change into the database</p>');
       exit;
    }
    $sql = @mysql_query('SELECT job_id, job_title FROM vacancies');
    if (!
    $sql) {
       die(
    '<p>Error retrieving vacancies from database!<br />'.
            
    'Error: ' mysql_error() . '</p>');
    }
    while (
    $sql mysql_fetch_array($sql)) {
       
    $id $sql['job_id'];
       .
    $title htmlspecialchars($sql['job_title']);
       echo(
    "<li>$job_title ".
            
    "[a href="editvacancy.php?id=$id">Edit</a>|".
      
    "<a href="deletevacancy.php?id=$id">Delete</a>]</li>");
    }
    ?>
    Code 2 - view at www.ajcgroup.co.u/admin/vacancies/newvac.php

    PHP Code:
    <?php
    if (isset($_POST['submit']);
    $dbcnx mysql_connect('mysql.echocd.co.uk:3306','username','password');
    mysql_select_db('conman');
      
    $title $_POST['job_title'];
      
    $desc $_POST['job_description'];
      
    $salary $_POST['salary'];
      
    $loc $_POST['job_location'];
      
    $closing $_POST['closing_date'];
      
    $ref $_POST['vacancies_reference_no'];
      
    $sql "INSERT INTO vacancies SET
           Title='
    $title',
        Description='
    $desc',
        Salary='
    $salary',
        Location='
    $loc',
        Closing='
    $colsing',
        Reference='
    $ref',";
       if (@
    mysql_query($sql)) {
          echo(
    '<p>New Vacancy added successfully</p>');
       }  else {
          echo(
    '<p>Error adding new Vacancy: ' .
             
    mysql_error() . '</p>');
       }
       
    ?>
    <p align="center"><a href="<?=$_SERVER['PHP_SELF']?>">Add another Vacancy</a></p>
    <p align="center"><a href="vacancies.php">Return to Managing Vacancies</a></p>
    <?php
    else: //Aloow user to enter ne vacancy
    ?>
    Thank you in advance for any help you can offer.
    Emma
    Last edited by platinum; May 16, 2003 at 07:58.

  2. #2
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just edited out your username/password from your code

    Is PHP installed properly? The pages just appear to be printing the code rather than running it?

  3. #3
    SitePoint Addict
    Join Date
    Feb 2003
    Location
    Shropshire
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that - I was having so many IE crashes trying tto insert the code I forgot.

    That is the one thing that crossed my mind - I will get it checked out.

    Cheers
    Emma

  4. #4
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    indeed, PHP doesn't seem to be parsing the code. (I'd remove those links, because you can see your MySQL user/pass in them as well.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.


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
  •