twilitegxa Posted August 17, 2008 Share Posted August 17, 2008 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! Quote Link to comment Share on other sites More sharing options...
Mchl Posted August 17, 2008 Share Posted August 17, 2008 $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. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted August 18, 2008 Author Share Posted August 18, 2008 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. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted August 18, 2008 Author Share Posted August 18, 2008 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. Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 18, 2008 Share Posted August 18, 2008 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 ?> Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted August 18, 2008 Author Share Posted August 18, 2008 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? Quote Link to comment Share on other sites More sharing options...
Bendude14 Posted August 18, 2008 Share Posted August 18, 2008 When inserting there comment etc you would need to have a field for storing the time they submit it. set that field as a TIMESTAMP and this will automatically store the current time date etc Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted August 18, 2008 Author Share Posted August 18, 2008 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? Quote Link to comment Share on other sites More sharing options...
Bendude14 Posted August 18, 2008 Share Posted August 18, 2008 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 Quote Link to comment Share on other sites More sharing options...
Mchl Posted August 18, 2008 Share Posted August 18, 2008 <?php include("mysql_connect.inc.php"); [...] usually using mysql_real_escape_string and trim That'll hardly work with MS Access... Quote Link to comment Share on other sites More sharing options...
Bendude14 Posted August 18, 2008 Share Posted August 18, 2008 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 Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted August 18, 2008 Author Share Posted August 18, 2008 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. Quote Link to comment Share on other sites More sharing options...
Mchl Posted August 18, 2008 Share Posted August 18, 2008 I think you should try mySQL once more. What OS are you on? PHP + Access combination is very rare, and not many people will be able to help you. (Not to mention that Access storage engine suck). Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted August 18, 2008 Author Share Posted August 18, 2008 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. Quote Link to comment Share on other sites More sharing options...
Mchl Posted August 18, 2008 Share Posted August 18, 2008 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. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted August 18, 2008 Author Share Posted August 18, 2008 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. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted August 18, 2008 Author Share Posted August 18, 2008 So I need to uninstall all of the MySQL stuff? The Server, Administrator, and the Connector? And how would I disable the port 80 in Skype's settings? Quote Link to comment Share on other sites More sharing options...
Mchl Posted August 18, 2008 Share Posted August 18, 2008 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; Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted August 18, 2008 Author Share Posted August 18, 2008 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? Quote Link to comment Share on other sites More sharing options...
Mchl Posted August 18, 2008 Share Posted August 18, 2008 It seems you don't have mysql extension enabled in your PHP installation. You can enable it in php.ini file... But if you decide to install WampServer you'll have it done for you... Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted August 18, 2008 Author Share Posted August 18, 2008 Do you enable it by deleting the ; in front of that extension? Quote Link to comment Share on other sites More sharing options...
Mchl Posted August 18, 2008 Share Posted August 18, 2008 Yup. And restarting web server afterwards. You can also enable mysqli. They can be enabled at one time. Mysqli is just 'mysql improved'. A bit more advanced and convenient. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.