Jump to content

[SOLVED] PHP with Access Question


twilitegxa

Recommended Posts

I am using PHP to connect to Microsoft Access and I can't figure how to do two things:

 

First, I want to add three parts to a variable that will be pulled from my database:

 

birthdatemonth, birthdateday, and birthdateyear

 

So that they all display together as one date, like 12-05-1982, under one variable, $birthdate, but I can't figure out how to do this, but I know it can be done. I have had some help with PHP and MySQL from a friend in the past, and so I'm sure it can be done. Does anyone know how? My variable looks like this:

 

$birthdate=odbc_result($rs,"birthdatemonth");

 

and would diaply like this:

 

echo "<tr><td>Birthdate</td>";

echo "<td>$birthdate</td></tr>";

 

Can anyone help me out with this?

 

Second, I want to use CSS with my PHP page, but for some reason I cannot link to it, or use any internal or embedded CSS either. Can this be done? I have an external CSS set up that I would prefer to use, but if I can't then I can embed or use internal CSS if I have to to, I just need to know if it an be done and how. Can anyone help me out?

 

I really appreciate in advance any help with these two questions. Thanks!

Link to comment
Share on other sites

$birthdateday=odbc_result($rs,"birthdateday");
$birthdatemonth=odbc_result($rs,"birthdatemonth");
$birthdateyear=odbc_result($rs,"birthdateyear");

$birthdate = $birthdateday."-".$birthdatemonth."-".$birthdateyear;

 

Show us how you try to load external CSS file.

Link to comment
Share on other sites

I just tried to load it the same way I would any other HTML file:

 

<head>

<link href="main.css" rel="stylesheet" type="text/css" />

</head>

 

Since I have the PHP page in a table, could I not just have the CSS affect the td tag like this:

 

td {color: rgb(53, 115, 141);}

 

Or would I have to do it another way? I even have tried adding a paragraph tag and it wouldn't work either when I added a paragraph to my PHP page before the PHP code.

Link to comment
Share on other sites

How can I make the month or day appear as two digits, as in January appears as 01 instead of just 1?

 

Also, I have another database that is for a guestbook, and I want to include on the page that displays the contents of the database the time and date of when the person lef the comment. How can I do this? Does it need to be brought from the page they submit the comment that puts it into the database? Or do I do it some other way? I have also done with my MySQL before, but don't remember how it was done. Plus, someone actually wrote the script for me, so I really didn't know how they did it anyway.

Link to comment
Share on other sites

look the date format you want up then create the desired affect........

http://uk.php.net/date

 

what does this say from the manual

 

j  Day of the month without leading zeros  1 to 31

 

how to set the dates...........

<?php
// Assuming today is: March 10th, 2001, 5:16:18 pm

$today = date("F j, Y, g:i a");                 // March 10, 2001, 5:16 pm
$today = date("m.d.y");                         // 03.10.01
$today = date("j, n, Y");                       // 10, 3, 2001
$today = date("Ymd");                           // 20010310
$today = date('h-i-s, j-m-y, it is w Day z ');  // 05-16-17, 10-03-01, 1631 1618 6 Fripm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.');   // It is the 10th day.
$today = date("D M j G:i:s T Y");               // Sat Mar 10 15:16:08 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h');     // 17:03:17 m is month
$today = date("H:i:s");                         // 17:16:17
?>

Link to comment
Share on other sites

I have this code:

 

$birthdateday=odbc_result($rs,"birthdateday");

  $birthdatemonth=odbc_result($rs,"birthdatemonth");

  $birthdateyear=odbc_result($rs,"birthdateyear");

  $birthdate = $birthdatemonth."-".$birthdateday."-".$birthdateyear;

 

And I want the birthdateday and birthdatemonth to display with I guess it's called leading zeros (January displays as 01 and not just 1). How do I alter this code? The other codes will just set the current time and date it looks like.

 

My other question was, if I am using my other databse that is set for the guestbook, I have name, email, url, and comments, but I also want to display the time they submitted their comment. Will I need to have a code on the page they submit the comment that stores the current date and time into my database? If, so how would I do that? or is there another way to display this information?

Link to comment
Share on other sites

Okay, now I am trying to write the PHP page that actually sends the data to the database, but I can't get it to work properly. I tried following a tutorial, and it sneds the form, but doesn't actually add any data to the database, just a blank record. What code do I need to get started for the PHP page that would send the data to the database? Here is part of my form and tell me if this is right as well (I just borrowed the tutorial code and updated it to reflect my form data):

 

<?php

 

function HTML_Head() {

    echo "

    <HTML><HEAD>

    <TITLE>Processing Form</TITLE>

    </HEAD>

    <BODY BGCOLOR=\"#D5D5AB\">";

}

 

function HTML_Form() {

 

    echo "

    <FORM NAME = \"AccessInterface\" METHOD=post ACTION=\"DataAccess.php\">

    Please enter the details you wish to be inserted into the Access Database.<br>

    Identity:<input name=\"identity\" TYPE=\"text\" SIZE=\"25\"><br>

    Character Name:<input name=\"charactername\" TYPE=\"text\" SIZE=\"25\"><br>

    Element Of Influence: <input name=\"elementofinfluence\" TYPE=\"text\" SIZE=\"25\"><br>

    <INPUT type=\"Submit\">

    </form>

    ";

}

 

function HTML_Existing() {

    echo "Existing database entries";

}

 

function HTML_Foot() {

    echo "</body></html>";

}

 

HTML_Head();

HTML_Form();

HTML_Existing();

HTML_Foot();

 

?>

 

I don't know what code I actually need from the above example, other than the form itself, but I mean I know I don't need the part that is supposed to show the existing database entries, but when I try to remove that line of code, I get an error. Can someone help me with this,too?

 

Link to comment
Share on other sites

having all these functions seems like over kill for what you are trying to achieve.

 

you want some thing like this.

 

 

<?php
include("mysql_connect.inc.php");

if(isset($_POST['submit'])) {

$data1 = escape_data($_POST['data1']);
$data2 = escape_data($_POST['data2']);
$data3 = escape_data($_POST['data3']);


$sql = "INSERT INTO table (col1, col2, col3) VALUES ('$data1', '$data2', '$data3')";
$result = mysql_query($sql) or trigger_error("Query failed" . mysql_error());

}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Update DB</title>
</head>

<body>


<?php else { ?>
<form name="formName" action="" method="POST">

<input type="text" name="data1" /><br />
<input type="text" name="data2" /><br />
<input type="text" name="data3" /><br />

<input type="submit" name="submit" value="Update" />
<?php } ?>

</body>
</html>

 

This is the basics of adding info to a database. Obviously you can add extra things to make sure the info was added.

 

also note that you will have to create a escape_data() function usually using mysql_real_escape_string and trim

Link to comment
Share on other sites

sorry i miss read that...

 

got side tracked then came back to it and did not read the title lol.

 

well the principle is still the same you will just have to use access specific functions.

 

sorry i have never used php with access

 

 

Link to comment
Share on other sites

Well, I wanted to use PHP with MySQL, but for some reason I can't get it to connect with PHP on my computer or server, so I gave up for now and started trying with Access so I could at least get started on what I wanted to do. I might have to change everything later to MySQL, which I know will absolutely suck!

 

So, I can just have the PHP code that enters the information to the database on the same page as the HTML form? I thought it would need to be separate so that when the form was submitted it used the PHP as the action of how to post the information.

Link to comment
Share on other sites

I'm on Windows XP Home, but on a Mac (using BootCamp). I didn't know if being on a Mac could be a problem, so I thought I 'd mention it. I have the MySQL Server 5.0 installed, and MySQL Adminstrator, and I installed the the Connector/ODBC 5.1 and I can get connected just fine through everything on my machine by using the Administrator or Server for MySQL, but when I try to use a PHP page to connect, I always get an error. I can't figure out what I'm doing wrong. Something must be installed wrong or something.

Link to comment
Share on other sites

There's a nice Apache+PHP+MySQL all-in-one pack for Windows. It's called WampServer. I use it myself and never had any problems with it. It basically works out of the box. (One thing that's often an issue is that Skype is blocking port 80 on which Apache runs, but you can disable it in Skype's preferences).

 

I think it's worth to try. Just make sure to uninstall your current servers, so no that there's no interference.

Link to comment
Share on other sites

Can you give me a sample PHP nd MySQl script to try real quick to see if I can get connected? I just changed my ODBC to MySQL again and tested the connection in there and it says it connected, so I will try with PHP and see what happens this time, but it wouldn't work before.

Link to comment
Share on other sites

That should work as a simple test. It should display your mysql server version.

 

$username = "root"; //I supppose every mysql installation has it by default
$password = "";  //it might be diffirent for you

$mysqli = new mysqli("127.0.0.1",$username,$password);
echo $mysqli->server_info;

Link to comment
Share on other sites

The code you gave me didn't work, but I probably didn't do it right. I just looked up a code real quick for connecting and used this code and just changed my username and password:

 

<?php

$username = "pee_wee";

$password = "let_me_in";

$hostname = "localhost";

$dbh = mysql_connect($hostname, $username, $password)

or die("Unable to connect to MySQL");

print "Connected to MySQL<br>";

// you're going to do lots more here soon

mysql_close($dbh);

?>

 

 

But I received this error:

 

Fatal error: Call to undefined function mysql_connect() in C:\Documents and Settings\Liz\Desktop\Sailor Moon\testpage.php on line 5

 

Do you know what I am doing wrong?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.