Jump to content

pluto

Members
  • Posts

    20
  • Joined

  • Last visited

About pluto

  • Birthday 02/08/1987

Profile Information

  • Gender
    Male

pluto's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. You are a total legend!! Thank you so very much
  2. Hi guys, Me once again, I'm working with a PHP page, which the output I'd like to be formatted by a css file. This is the code I have so far. <?php session_start(); require("con_mgr.php"); $chapSelect = $_POST['chapSelect']; $_SESSION['wordArray']=$get_field; $_SESSION['currentWord']=$value; $result = mysql_query("SELECT GreekWord FROM WORD where Chapter >= $chapSelect"); $num_rows = mysql_num_rows($result); $get_field = mysql_fetch_row($result); foreach($get_field as $value) { $display="<HTML>"; $display.="<link rel=\"stylesheet\" type=\"text/css\" href=\"test.css\">"; $display.="<div id=\"testWord\">"; $display.="<?php echo $value; ?>"; $display.="</div>"; $display.="</HTML>"; } echo($display); //header("Location:http://localhost/SessionDemo/demo2.php"); ?> I have a css file called test.css which has a div section that formats the text as red, and makes the font quite big. At least that's the plan. I've tried everything I can think of, but it won't return anything at all. And I'm not sure why it's not doing that. Or ideally I'd like the variable to be passed to a HTML (or the value thereof, I'm thinking like a Java coder again!!!) Any help would be awesome. Thanks Pluto
  3. Hi guys, I have a PHP file that gets two fields out of a data base. Then what I'd like to do is use that field in another PHP file to carry out some evaluation on it based on a user's input from a HTML form. I don't have the first clue how to do it. Any suggestions? I know this is not much information, but I've not started coding it as of yet, I've looked around and not found much on Google, however I'm going to keep trying. Thanks in advance Pluto
  4. Hi there, believe it or not, it finally worked. i'm not sure what I did, but I kept testing the code changing bits and bobs, and tried various things, and all of a sudden it worked. Not sure why. Just wanted to say thanks for all your help. Pluto
  5. Hi DarkLink, Thank you so much for taking the time to look at my code, I've not had a chance to test it as of yet, but here's the code I used to create the database table. CREATE TABLE `test`.`word` ( `idword` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, `GreekWord` VARCHAR(45) CHARACTER SET greek COLLATE greek_general_ci NOT NULL, `GreekDefinition` VARCHAR(45) CHARACTER SET greek COLLATE greek_general_ci NOT NULL, `EnglishWord` VARCHAR(45) NOT NULL, `EnglishDefinition` VARCHAR(45) NOT NULL, `Chapter` VARCHAR(45) NOT NULL, `Sections` VARCHAR(45) NOT NULL, PRIMARY KEY (`idword`) ); Thanks once again for your time Pluto
  6. Hi DarkLink, thanks for that, i did that, and got the following errors: Notice: Undefined index: EnglishWord in C:\xampp\htdocs\NinjaTuna\addWord.php on line 9 Notice: Undefined index: EnglishDefinition in C:\xampp\htdocs\NinjaTuna\addWord.php on line 10 Notice: Undefined index: EnglishWord in C:\xampp\htdocs\NinjaTuna\addWord.php on line 15 Notice: Undefined index: EnglishDefinition in C:\xampp\htdocs\NinjaTuna\addWord.php on line 17 Word added Thing is though, that they are in the HTML (see first post) and they are spelt correctly, or am I missing something really obvious here? I've spent the last 40 minutes trying to figure out what's going on. Thanks Pluto
  7. Ok, I tried that and it didn't echo anything back, which would lead me to suggest that somehow it's not reading what's been put in the text boxes. But I'm not sure why, I've checked everything and it all looks ok... Pluto
  8. Good afternoon all, I'm having something of a problem with a PHP page I'm developing. I've managed to keep the HTML and the PHP seperate so it's a bit easier to manage, however, I'm trying to add a record to a data base and most of the fields are getting in to the DB excpet EnglishWord and EnglishDefinition, and I can't figure out what's wrong due to my lack of experience in PHP. The word table is structured thus: wordId, GreekWord, GreekDefinition, EnglishWord, EnglishDefinition, Chapter,Section The code is posted below for your perusal. any help would be awesome. Thanks. addWord.php <?php /** PHP code inserted here */ $greekWord = $_POST['GreekWord']; $greekDef = $_POST['GreekDefinition']; $englishWord = $_POST['EnglishWord']; $englishDef = $_POST['EnglishDefinition']; $chapter = $_POST['chapter']; $section = $_POST['section']; echo "connection to the DB section of the code"; $conn = @mysql_connect("localhost", "root") or die("Could not connect to the data base"); $db = @mysql_select_db("test",$conn) or die("Error in selecting the data base."); echo "setting the SQL variables up"; // This is so the SQL statement is correctly formatted. $grkWrd = "'".$greekWord."'"; $grkDef = "'".$greekDef."'"; $engWrd = "'".$englishWord."'"; $engDef = "'".$englishDef."'"; $chptr = "'".$chapter."'"; $sctn = "'".$section."'"; echo "the query is here"; $query = "INSERT INTO word (GreekWord, GreekDefinition, EnglishWord, EnglishDefinition, Chapter, Sections) values ($grkWrd,$grkDef,$engWrd,$engDef,$chptr,$sctn)"; echo "exuctuing the query"; $exec = @mysql_query($query, $conn) or die ("Cannot add the word to the database"); echo "query execution successful"; if($exec) { //echo "<a href=\"javascript:history.back();\">Please go back and fill out the missing fields</a>"; echo "Word added"; //header("Location:http://localhost/ninjatuna/wordAdded.html"); } else { if($errmsg!="") { echo($errmsg); echo "<a href=\"javascript:history.back();\">Please go back and fill out the missing fields</a>"; exit; } } ?> addword.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <link rel="stylesheet" type="text/css" href="layout.css"> <script type="text/javascript" src="translator.js"></script> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Welcome to LearnGreek.com (Work title)</title> </head> <body> <div id="header"> <h1>Welcome to LearnGreek.com</h1> </div> <div id="nav"> <ul> <li><a href="index.html">Home</a></li> <li><a href="Login.html">Login</a></li> <li><a href="Register.html">Register</a></li> <li><a href="Links.html">Links</a></li> </ul> </div> <div id="main"> <p> <form name="addwrd" action="addWord.php" method="post"> Greek Word: <input type="text" onkeyup="trans(this.id)" id="greek_word" name="GreekWord" size=20><br><br> Greek Definition: <input type="text" onkeyup="trans(this.id)" id="greek_definition" name="GreekDefinition" size=20><br><br> English Word: <input type="text" name="EnglishWord" size=30><br><br> English Definition: <input type="text" name="EnglishDefinition" size=20><br><br> Chapter: <input type="text" name="chapter" size=20><br><br> Section: <input type="text" name="section" size=20><br><br> <input type="submit" name="addword" value="Submit"> </form> </p> </div> </body> </html> Once again, many many thanks for taking the time to look at this. I'm aware it's not secure code as of yet, but i'm focussing on getting it runnning before I start to lock it all down.
  9. Alas, When I tried the header, I got the following error: word exists Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\insert_word.php:9) in C:\xampp\htdocs\insert_word.php on line 11 This is my code... <?php // Open the data base connection $conn = mysql_connect("localhost","root",""); mysql_select_db("test",$conn); // check that the word exists first. $check = "SELECT * FROM TEST2 where word = '$_POST[word]"; if($check==true) { echo "word exists"; // load the previous page again header('Location:http://localhost/insert_test.html'); exit; } else { $sql = "INSERT INTO test2 values ('','$_POST[word]','$_POST[definition]','$_POST[chapter]','$_POST[section]')"; if(mysql_query($sql, $conn)) { // check that the word doesn't already exists echo "record added"; } else { echo "Error in entering the record"; } } ?> Ideally, I'd like the warning to come in red under the text box in the HTML page, but that'll come with further practice I'm sure, and that's a different issue. Thanks in advance Pluto
  10. Dear all, I've managed to do the bits I've wanted in terms of adding words to data bases, and ensuring that they don't exist etc. However, I've come across an interesting problem. Ideally, I'd like the screen to go back to the HTML input form once a record has been added, but I can't seem to work out how to do that. I've read about URLREFERER or something like that somewhere, but I was wondering if anyone had other ideas? Many thanks Pluto
  11. Ah ok Maq, Sorry, my bad. You can mark this as solved if you wish? Or is that something I do?
  12. You should create a new thread for this particular problem. I was going to have a stab at it myself first before posting. I've gotta learn to do it, or at least have a go, or I'll learn nothing, and it'll be like others writing the code for me, and that's not good. But if it comes to it, there will be another thread.
  13. Thanks Maq, Now to check if the word is already in the data base... fun... Pluto
  14. Dear all, I have since resolved the issue. I found a good book on the subject, and figured I'd follow their example. They seperated the HTML from the PHP, so that way, it would be clearer to edit and maintain. So I now have two seperate files. Their code is as follows. insert_test.html - This will be re-written to include java script at some point. As I'm going to be doing things in different languages. <!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Insert a record one word at a time</title> </head> <body> <FORM ACTION="insert_word.php" METHOD=POST> <p> Text to add:<br/> <input type=text name="word" size=30><br> <input type=text name="definition" size=30><br> <input type=text name="chapter" size=30><br> <input type=text name="section" size=30><br> <p><input type=submit name="submit" value="Insert Record"></input> </FORM> </body> </html> insert_word.php <?php // Open the data base connection $conn = mysql_connect("localhost","root",""); mysql_select_db("test",$conn); $sql = "INSERT INTO test2 values ('','$_POST[word]','$_POST[definition]','$_POST[chapter]','$_POST[section]')"; if(mysql_query($sql, $conn)) { echo "record added"; } else { echo "Error in entering the record"; } ?> So I would like to thank everyone for their help. You've certainly got me on the right track, and I figured I should try and keep front and back end stuff seperate where possible. This is the first step of the system I'm writing, so I'm sure you're going to see some more posts from me. I'm looking forward to being part of the community. Thanks once again Pluto
  15. My understanding is that they're superglobals, so I don't need to define them anywhere. And my (limited) understanding was that you use the $_POST on the variables you want to add to the POST request to the server. Or am I wrong? Sorry, this is the first thing I've ever written in PHP
×
×
  • 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.