Jump to content

zenix

Members
  • Posts

    29
  • Joined

  • Last visited

    Never

Everything posted by zenix

  1. Just curious, why wouldn't I want it in a text box rather than a drop down box? Just curious, very new to programming. Thanks!
  2. Thank you again, I'd actually like to know how to make it so I can click on an entry in the text box and have the fields populate with the associated data. I'd probably more of an AJAX or Javascript issue I guess. I was just hoping to be able to do it with php.
  3. I appreciate your input, thank you. My problem isn't the database...I have THAT working quite well. I would just like to see if I can have the names and maybe phone number of the contacts displayed in a text box so I can click on one and have all the information (address, phone, email etc...) appear in the form.
  4. Hello, I have been working hard this past year trying to learn php and mysql. I've even developed my own little database of contacts. Anyway, I thought it'd be neat (if possible) to have a textarea on the page my data form is on to display the first, last names and phone numbers of the contacts in the db, then have it so all I have to do is scroll through the list and click the one I'd like to have displayed in my form.. I don't know how to do this. My database works great, I just thought this could facilitate a little more learning...and it would be a nice addition. If anyone has any idea on how I might achieve this I'd really appreciate it if you'd let me know. Thanks!!
  5. Thank you for all your guidance, I'll try figuring it out from what you said. You have been a big help to me!
  6. I appreciate all your time and assistance on this, thank you. I tried your example and although it allows me to select an option from the drop down, I don't know how to get all the data associated with this person to be displayed in the form. I have the form all set up and working well, it includes address, address2 city, state and zip, is there a way to have this information populated in the correct fields for the person chosen? Thank you so much again!!
  7. Hello, I am trying to learn php and mysql, and making pretty good progress. I've developed a database for a make believe company and have it working correctly. I thought it'd be neat to have the data (such as last name, first name and phone) appear in a text area at the top or bottom of the form that I use to enter/modify and view my data. I'd like to make it so I can click on an entry in the text area and have the fields of the form populate with the relevant data. Someone mentioned I should use a drop down. I've tried this, I get the info into the drop down alright, but don't know how to go about making the data clickable so the info. fills out the form on the page. I think I'd really prefer a scrolling text area though, but when I try THIS approach I keep getting an error stating that the ...mysql_fetch_array ($result) is not a valid MySQL entry. If someone could help me out, I'd really appreciate it. I've learned a lot this year, apparently I have quite a ways to go. Here is the code I have for the drop down. <?php include("connect.php"); $result = mysql_query("SELECT lname, fname, phone FROM warrantydb ORDER BY lname ASC"); echo "<select name=\"DropData\">"; while($row = mysql_fetch_array( $result )) { //I figure there is a more refined way of doing this, but this works for me. Any thoughts would be appreciated. $Data=$row['lname']; $Data2=$row['fname']; $Data3=$row['phone']; echo "<option>$Data $Data2 $Data3</option>"; } echo "</select>"; ?>
  8. Thanks a lot!! it's something what a simple little typo can do!!
  9. Hi, I was experimenting and decided to try making tabs on a web page, made with php. I have it so the tabs initially display and the contents of tab one shows. When I click on tab 2 none of the contents for that tab show. If I click back on tab 1 there is no contents displayed. I've been wracking my head on this and can't see where my code is wrong. I'd really appreciate it if someone could take a look and help me out. Code for tabs: <?php error_reporting(1); $tabs =array(); function tabs_header() { ?> <style type="text/css"> .tab { border-bottom: 1px solid blue; text-align: center; font-family: arial, verdana; } .tab-active { border-left: 1px solid black; border-top: 1px solid black; border-right: 1px solid black; text-align: center; font-family: arial, verdana; font-weight: bold; } .tab-content { padding: 5px; border-left: 1px solid black; border-right: 1px solid black; border-bottom: 3px solid black; } </style> <?php } function tabs_start() { ob_start(); } function endtab() { global $tabs; $text = ob_get_clean(); $tabs[count($tabs)-1]['text']=$text; ob_start(); } function tab($title) { global $tabs; if(count($tabs)>0) endtab(); $tabs[] = array(title=>$title, text=>"test"); } function tabs_end() { global $tabs; endtab(); ob_end_clean(); $index =0; if($_GET['tabindex']) $index =$_GET['tabindex']; ?> <table width="100%" cellspacing="0" cellpadding="0"> <tr> <?php $baseuri =$_SERVER['REQUEST_URI']; $baseuri =preg_replace("/\?.*$/", "", $baseuri); $curindex =0; foreach($tabs as $tab) { $class ="tab"; if($index ==$curindex) $class ="tab_active"; ?> <td class="<?php echo($class);?>"> <a href=<?php echo($baseuri."?tabindex=".$curindex);?>"> <?php echo($tab['title']);?> </a></td> <?php $curindex +=1; } ?> </tr> <tr><td class="tab-content" colspan="<?php echo(count($tabs)+1);?>"> <?php echo($tabs[$index]['text']);?> </td></tr> </table><?php } ?> Code for index page: <?php error_reporting (1); include('tabs.php'); ?> <html><head><?php tabs_header();?></head> <body> <div style="width:600px;"> <?php tabs_start(); tab("tab one"); echo 'This is the first tab. I am just going to add a little text here to see if it makes any difference at all. '; tab("tab two"); echo "This is the second tab, this is the tab that isn't showing anyting for me when I click on it."; tabs_end();?> </div> </body></html>
  10. Thank you so much everyone!! It's been a headache.
  11. Hi, I am trying to learn php and have been making some pretty good progress. I've just run into a wall though and would REALLY appreciate it if someone could let me know what I am doing wrong. I have this fictitious order form that when filled out a new web page is displayed with the info. and the text is written in tab delimited style to a text file. I'd like to have it so each entry receives its own line. I have utilized \n to no avail, and have tried using <br /> and <p>, none of them give me a new line each time the form is submitted. Thank you in advance! Here is my code. <?php include ('error.php'); $modem = $_POST['modem']; $enet =$_POST['enet']; $sound =$_POST['sound']; $DOCUMENT_ROOT= $_SERVER['DOCUMENT_ROOT']; $fname = $_POST['fname']; $lname = $_POST['lname']; $address = $_POST['address']; $address2 = $_POST['address2']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; $phone = $_POST['phone']; ?> <br><br> <html><head><title>ZENIX COMPUTERS</title></head><body> <h1><i>ZENIX COMPUTERS</h1></i> <br> <h2>Order results</h2> <br><p>Order submitted: <?php echo date('H:i, F jS')?> <br><br> <?php $date = date('H:i, F jS'); $find = $_POST['find']; echo "You stated you were referred to us via <b><i> $find</b></i>"; ?> <br><br><?php echo "Your order is as follows:<br>"; echo $modem . 'Modem(s)<br>'; echo $enet .'Ethernet Card(s)<br>'; echo $sound .'Sound card(s)<br>'; ?> <br> <? echo "The subtotal of your order is $tamount";?> <br><? echo "The tax on this order will be $tax";?> <br><? echo "Bringing the total for your order to $grandt";?> <?php $total = 0; $total = $modem +$enet +$sound; if ($total == 0) { echo "You didn't order anyting"; } else { if($modem >0) echo $modem. 'Modem(s)'; if($enet >0) echo $enet. 'Ethernet card(s)'; if ($sound >0) echo $sound. 'Sound card(s)'; } $tamount = 0.00; define('modemp', 19.95); define ('enetp', 19.95); define('soundp', 24.95); $tamount = $modem * modemp + $enet * enetp + $sound * soundp; $tax = $tamount * .08; $grandt = $tamount + $tax; echo 'Items ordered: '.$total.'<br>'; echo 'Your sub total for this order is <font color="blue"><b><i>$'.number_format($tamount,2).'</font></b></i><br>'; echo 'The sales tax will be<b><i><font color="blue">$'.number_format($tax,2).'</font></b></i><br>'; echo '<br>Bringing your total order with tax to<b><i><u><font color="blue">$'.number_format($grandt,2).'</font></b></i></u>'; echo "<br><br>"; $output = '<p>'.$date. "\t".$modem." modem \t" .$enet." Ethernet card \t" .$sound." Sound card\t$" .$grandt." TOTAL\t".$lname." Last\t".$fname." First\t".$address." Address\t".$address2." Address 2\t".$city." City\t".$state." State\t".$zip." Zip\t".$phone."\n"; //append file $fp = fopen("DOCUMENT_ROOT/../orders/orders.txt", 'ab'); if (!$fp) { echo 'Your order could not be processed at this time, please try again later.'; exit; } fwrite($fp, $output, strlen($output)); if($fp) { echo 'DONE!!'; } fclose($fp); echo 'Order written to file'; ?>
  12. UNBELIEVABLE!! Thanks a lot man! Next time I will look a little harder for the obvious, I really appreciate your assistance!
  13. Hi, I am attempting to learn how to make a basic database that will allow input from a user of a web page to be entered into it. I am not the most efficient coder, but I'm learning and I'm new at this. Anyway, I keep getting this error that says for me to check the mysql manual for the right syntax to use near '(test_id) KEY testype(test_lname, test_fname))' at line 4. I can't see anything wrong with it. If someone could guide me in the right direction I'd really appreciate it! Here is the code I've made: ' <?php $conn = mysql_connect('localhost', 'root')or die(mysql_error()); $create = mysql_query("CREATE DATABASE IF NOT EXISTS testdb") or die(mysql_error()); mysql_select_db ("testdb"); //create table $testdb = 'CREATE TABLE test(test_id int (11) NOT NULL auto_increment, test_lname varchar(40) NOT NULL, test_fname varchar(40) NOT NULL PRIMARY KEY(test_id) KEY testype(test_lname, test_fname))'; $result = mysql_query($testdb) or die(mysql_error()); //Create test type table $testype = 'CREATE TABLE testype(testype_id int(11) NOT NULL auto_incrememnt, empl_pos NOT NULL, primary key (testtype_id))'; //create table others $others = 'CREATE TABLE others(others_id int (11) NOT NULL auto_increment, others_mom varchar(40) NOT NULL, others_dad varchar(40) NOT NULL others_bro varchar(40) NOT NULL others_sis varchar(40) NOT NULL PRIMARY KEY(others_id))'; $results = mysql_query($others) or die(mysql_error()); echo 'Database successfully created!'; ?>
  14. Could someone please let me know how to mark this resolved? I'm going to do more troubleshooting and studying. Probably learn better that way. Thank Maq for pointing out my typo. I appreciate all the comments here. Thanks a lot!
  15. Someone already told him that, apparently he did not want php's help in finding basic errors. Yes, I did insert the ini_set('display_errors' 1 ); error_reporting = (E_ALL); sorry it wasn't included here though. Someone told me that it doesn't need to be on every page so I omitted it. More than likely would have been better if I had just left it or even commented it out. Sorry. I also apologize for there having been so much code. I will try to pin point it a little btter in the future. I looked at the post this morning, yeah...it's too much with so many snippets.
  16. Hey, I am learning php right now. I have been attempting to make a simple database that would store just 2 fields of information. I thought this would be a place to start and it'd be something I could buil upon later as I learn more. Anyway, I have coded and re-coded this thing and whenever I attempt to view it in my browser I get a blank screen in Firefox and a 500 server error in IE. If someone would take a look at what I have and offer a suggestion or 2 I would REALLY appreciate it. The code is below, thank you in advance! This code is for viewing the table contents: <html> <head> <title>View Database</title> </head> <body> <?php //connect and select if($dbc = mysql_connect('localhost','root')); { if(!mysql_connect('database1')) { die('<p>Could not select to mysql because <b>' . mysql_error() . '</p></b>'); } } else { die('<p>Could not connect to mysql because:<b>' . mysql_error() . '</p></b>'); } //define query $query = 'SELECT * FROM db_entries ORDER BY date_entered DESC'; if($r = mysql_query($query)) { //retrieve and print records while($row = mysql_fetch_array($r)) { print "<p><h3>{$row['title']}</h3> {$row['entry']}<br/> <a href=\"edit_entry.php?id={$row['db_id']}\">Edit</a> <a href=\"delete_entry.php?id={$row['db_id']}\">Delete</a></p><hr/>\n"; } } else { //Query didn't run die('<p>Could not retrieve data because <b>' . mysql_error() . "the query was $query</b></p>"); } mysql_close(); ?> </body> </html> This coed is for adding the data: <html> <head> <title>Entry 2</title> </head> <body> <?php //Didn't show anything //ini_set('display_errors', 1); //error_reporting(E_ALL); if(isset($_POST['submit'])) { //connect and select if($dbc = mysql_connect ('localhost', 'root')) { if(!@mysql_select_db ('myblog')) { dir('<p>Could not select database because <b>' . mysql_error() . '</b></p>'); } } else { print "<p>Could not connect to database because <b>" . mysql_error() . "</b></p>"; } //define query $query = "INSERT INTO blog_entries (bog_id, title, entry, date_entered) VALUES(0, '{$_POST['title']}', '{$POST['entry']}', NOW())"; //execute query if(@mysql_query($query)) { print '<p>The blog entry has been added</p>'; } else { "<p>Could not add entry because: <b>" . mysql_error() . "</b>. The query was $query.</p>"; } } mysql_close(); ?> <form action ="add_entry.php" method ="post"> <p>Entry title: <input type ="text" name ="title" size ="40" maxsize ="100"/></p> <p>Entry text: <textarea name="entry" cols ="40" rows ="5"/></textarea></p> <br/> <input type ="submit" name ="submit" value ="Add my entry!"/> </form> </body> </html> This code is for creating the DB. I know not very efficient, but I am just learning now. <html> <head> <title>Database 10</title> </head> <body> <?php //attempt to connect to mysql if($dbc = mysql_connect('localhost', 'root')) { print '<p>Successfully connected!</p>'; if(mysql_query('CREATE DATABASE database1')) { print '<p>The database has been created!</p>'; } else { die('<p>Could not create database because: <b>' . mysql_error() . '</b></p>'); } if(mysql_select_db('database1')) { print '<p>The database has been selected!</p>'; } else { die('The database could not be slected because: <b>' . mysql_error() . "</b>The query being run was<b> $query</b>"); } mysql_close(); } else { die('<p> could not connect to mysql because<b>' . mysql_error . '</p></b>'); } ?> </body </html> </body> </html> AND creating the table <html> <head> <title>Create Table</title> </head> <body> <?php //connect and select if($dbc = @mysql_connect('localhost', 'root')) { if (!@mysql_select_db ('database1')) { die('<p>Could not select the database because<b>' . mysql_error() . '</b></p>'); } } else { die('<p>Could not connect to database because: <b>' . mysql_error() . '</b></p>'); } //define query $query = 'CREATE TABLE db_entries (db_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, title VARCHAR(100) NOT NULL, entry TEXT NOT NULL, date_entered DATETIME NOT NULL)'; //run query if(mysql_query($query)) { print '<p>The table has been created!</p>'; } else { die('<p>The table was not created because <b>.' . mysql_error() . '</b></p> <p> the query being run was:' . $query . '</p>'); } mysql_close(); ?> </body> </html>
  17. Thanks a lot for your help! Apparently I am blind to my own mistakes....NOW I understand better where my wife is coming from. I used to use phpD but recently switched to Dreamweaver CS4. I appreciate your advice!
  18. Hi, I am new to php and have been learning right along when suddenly my form pages don't display. All the other php pages display just fine. All I get is a 500 error in IE and a blank page in Firefox. If someone could lend some assistance I would really appreciate it. If the HTML is alone it displays perfectly. Here is the code: <head> <title>Entry 2</title> </head> <body> <?php //Didn't show anything //ini_set('display_errors', 1); //error_reporting(E_ALL); if(isset($_POST['submit'])) { //connect and select if($dbc = mysql_connect ('localhost', 'root')) { if(!@mysql_select_db ('myblog')) { dir('<p>Could not select database because <b>' . mysql_error() . '</b></p>'; } } else { print "<p>Could not connect to database because <b>" . mysql_error() . "</b></p>"; } //define query $query = "INSERT INTO blog_entries (bog_id, title, entry, date_entered) VALUES(0, '{$_POST['title']}', '{$POST['entry']}', NOW())"; //execute query if(@mysql_query($query)) { print '<p>The blog entry has been added</p>'; } else { "<p>Could not add entry because: <b>" . mysql_error() . "</b>. The query was $query.</p>" } mysql_close(); ?> <form action ="add_entry.php" method ="post"> <p>Entry title: <input type ="text" name ="title" size ="40" maxsize ="100"/></p> <p>Entry text: <text area name="entry" cols ="40" rows ="5"/></p> <br/> <input type ="submit" name ="submit" value ="Add my entry!"/> </form> </body> </html>
  19. I DID IT!! YAY!! Thank you so much for your help! Here is what I did. My log in code looks like this: <?php ob_start(); session_start(); //set page title and include header file define('TITLE', 'login2'); require('templates/header.htm'); print '<div id ="leftcontent"> <h1>Log in form</h1> <p> Please log in to your account</p>'; //check if form has been submitted if(isset($_POST['submit'])) { //handle form if((!empty($_POST['uname'])) && (!empty($_POST['pword']))) { if(($_POST['uname']=='tester') && ($_POST['pword'] == 'test')) { //Open session $_SESSION['uname'] = 'tester'; $_SESSION['loggedin'] = time('g:i A'); //redirect to welcome page header('location: welcome2.php'); exit(); //NOTHING IS BEING SENT TO THE WELCOME PAGE AFTER LOG IN } else { print '<p>Submitted log in not valid</p>'; } } else { //forgot a field print '<p>Please make sure all fields are completed</p>'; } } else { //Display the form print '<form action ="login2.php" method="post"><p> User name:<input type="text" name ="uname" size ="20"/> <br/> Password: <input type ="password" name ="pword" size ="20"/><br/> <input type="submit" name ="submit" value ="Submit my info!"/></p></form>'; } //complete formatting print '</div>'; require ('templates/footer.htm'); ob_end_flush(); ?> My welcome page code is this: <?php //start session session_start(); //Turn on output buffering //ob_start(); ini_set('display_errors', 1); error_reporting(E_ALL); define('TITLE', 'Welcome to the Zenix Computers test site!'); require ('templates/header.htm'); //print greeting print '<div id="leftcontent"> <h1>Welcome to the Zenix Computers test site, ' . ucfirst($_SESSION['uname']) . '!</h1>'; //print how long they've been logged in print '<p>You have been logged in since:<br/> ' . date ('g:i A', $_SESSION['loggedin']) . '</p>'; //Make log out link print '<p><a href ="logout.php">Click here to log out</a></p>'; print '</div>'; require( 'templates/footer.htm'); ?> This site (and you) are awesome!
  20. I experimentd a little, as I AM trying to learn here and changed my code in the log in page to include $_SESSION['loggedin'] = date ('g:i A');. Rather than a null Time() statement. It appears that I was srong, because nothing changed.
  21. Please excuse my extreme ignorance; how can I fix it? I'd really appreciate it if you could guide me just a little. Thanks a lot for your reply!
  22. I forgot about moving the error reporting code. Thanks for the heads up on this though, I will not make it a practice to have it there all the time.
  23. Thank you for the reply. I did away with the output buffering and the &~E_NOTICE. I get warnings saying that uname and logged in are undefined indexes. uname is defined in the html below. <?php //Turn on output buffering //ob_start(); ini_set('display_errors', 1); error_reporting(E_ALL); //start session session_start(); define('TITLE', 'Welcome to the Zenix Computers test site!'); require ('templates/header.htm'); //print greeting print '<div id="leftcontent"> <h1>Welcome to the Zenix Computers test site, ' . ucfirst($_SESSION['uname']) . '!</h1>'; //if (isset($_SESSION['loggedin'])) //{ //print how long they've been logged in print '<p>You have been logged in since:<br/> ' . date ('g:i A', $_SESSION['loggedin']) . '</p>'; //} //else //{ //header('location: login.php'); //} //Make log out link print '<p><a href ="logout.php">Click here to log out</a></p>'; print '</div>'; require( 'templates/footer.htm'); //Turn off buffering //ob_end_flush(); ?> The first bloack of code I provided the first time is the log in page, the second is the welcome2 page. This is the modified welcome2.php page that is throwing the warnings. Thanks again!
  24. Hi, apparently I am missing something some place. I have been playing around/experimenting to sharpen my php skills and better understand the language. I made a (what was supposed to be a) very simple log in form and a welcome page. On the welcome page I have it set to state what time the person logged in. This is only a pretend page solely for the purpose of me learning. If someone could set me straight I'd REALLY appreciate it. Here is the log in page code: <?php //Turn on output buffering ob_start(); ?> <!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" /> </head> <body> <?php ini_set('display_errors', 1); error_reporting(E_ALL &~E_NOTICE); //Set page title define ('TITLE', 'Login'); require ('templates/header.htm'); print '<div id ="leftcontent"> <h1>Login Form</h1> <p> Please log in to access your account</p>'; //check if form submitten if(isset($_POST['submit'])) { //handle the form if((!empty($_POST['uname']))&&(!empty($_POST['pword']))) { if(($_POST['uname']=='testing')&&($_POST['pword']=='test')) { //session stuff session_start(); $_SESSION['uname'] = 'testing'; $_SESSION['loggedin'] = time(); //Redirect to the welcome page header('location: welcome2.php'); exit(); } else { print '<p>The user name and/or password is not right.</p>'; } } else { print '<p>Please make sure all the fields are fill out.</p>'; } } else { //display form print'<form action ="welcome2.php" method ="post"><p> <br/> User name: <input type="text" name ="uname" size ="30"/> <br/> Password: <input type ="password" name ="pword" size ="30"/> <br/> <br/> Favorite Color: <input type ="text" name ="color" size ="15" /><br/> <br/> Age: <input type ="text" name ="age" size ="3" /><br/> <input type ="submit" name ="submit" value ="Log me in!"/></p> </form>'; } print '<div>'; require ('templates/footer.htm'); //Turn off buffering ob_end_flush(); ?> </body> </html> And the welcome page code: <?php //Turn on output buffering ob_start(); ini_set('display_errors', 1); error_reporting(E_ALL & ~E_NOTICE); //start session session_start(); define('TITLE', 'Welcome to the Zenix Computers test site!'); require ('templates/header.htm'); //print greeting print '<div id="leftcontent"> <h1>Welcome to the Zenix Computers test site, ' . ucfirst($_SESSION['uname']) . '!</h1>'; //if (isset($_SESSION['loggedin'])) //{ //print how long they've been logged in print '<p>You have been logged in since:<br/> ' . date ('g:i A', $_SESSION['loggedin']) . '</p>'; //} //else //{ //header('location: login.php'); //} //Make log out link print '<p><a href ="logout.php">Click here to log out</a></p>'; print '</div>'; require( 'templates/footer.htm'); //Turn off buffering ob_end_flush(); ?> I left everything I did to figure out what was going wrong. The commented out code starting with if (isset... was placed there to verify if any session information was being sent to the page at all. Before adding this code the welcome page always said that I've been logged in since 7:00 PM...even though it's only just after 10:AM. The footer is encoded to display the current date and time and it is correct there. I'd REALLY appreciate a little guidance! Thanks in advance!!
  25. Hi, I am learning this and doing alright (well...until now), I have hit a wall that seems to define logic. If someone could help me out I would REALLY appreciate it. The code is below, the error I get is "Undefined variable $movie_details. The first instance of the variable works well, but the second one comes up undefined. The table I am attempting to display does show, but so does the error in the upper left of the screen.Thanks a lot in advance! Sorry my coding isn't very efficient, I will improve in time right now I am just trying to learn. while($row = mysql_fetch_array($result)) { $movie_name = $row['movie_name']; $movie_director = $row['movie_director']; $movie_leadactor = $row['movie_leadactor']; $movie_details .=<<<EOD <tr> <td>$movie_name</td> <td>$movie_director</td> <td>$movie_leadactor</td> </tr> EOD; } $movie_details .=<<<EOD <tr> <td> </td> </tr> <tr> <td>Total :$num_movies Movies</td> </tr> EOD;
×
×
  • 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.