Gwhiz Posted January 6, 2007 Share Posted January 6, 2007 I'm trying to use dtb4free.net to store the names and firms of people who visit a law blog, http://lawdepartmentmanagement.typepad.com/.I'm a novice at writing any kind of code and was wondering how to make a code that would record the data these people enter and store them in the Database for me.any pointers would be immensely helpful.Also, is it possible to have multiple form actions for one form? If so, how?Any and all help is much appreciated.thanks,Gwhiz Quote Link to comment https://forums.phpfreaks.com/topic/33126-hoping-to-glean-some-pearls-of-wisdom-from-the-graybeards/ Share on other sites More sharing options...
.josh Posted January 6, 2007 Share Posted January 6, 2007 http://www.phpfreaks.com/tutorials/142/0.php Quote Link to comment https://forums.phpfreaks.com/topic/33126-hoping-to-glean-some-pearls-of-wisdom-from-the-graybeards/#findComment-154335 Share on other sites More sharing options...
Gwhiz Posted January 7, 2007 Author Share Posted January 7, 2007 Thanks for the link, I had a few questions about it.First, what does it mean to retrieve the information? All I want to do is record information in a database and access it in that database. Secondly, It does not work yet. All I did was change the variables username, password, host, etc. was that all I needed to do? Finally, when I submit information in this form it becomes an http 404 error, why is this?Again, any and all help is much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/33126-hoping-to-glean-some-pearls-of-wisdom-from-the-graybeards/#findComment-154602 Share on other sites More sharing options...
DarkendSoul Posted January 7, 2007 Share Posted January 7, 2007 Retrieving the information is basically accessing that information and saving it in some way.The 404 may be because the fact that you are not actually editing the information in the tutorial, try to change where the form submits to the correct information.Theres probably a lot more you need to do then just change variables, read the tutorial top to bottom and make sure that you understand the content, if you do not you may need to read other tutorials. Learning a scripting language will take some time. Quote Link to comment https://forums.phpfreaks.com/topic/33126-hoping-to-glean-some-pearls-of-wisdom-from-the-graybeards/#findComment-154618 Share on other sites More sharing options...
Gwhiz Posted January 7, 2007 Author Share Posted January 7, 2007 Just to make sure I do not have any fundamental misconceptions ...Do I have to have php installed on my computer to use it online?Where do I put the actual php script?reading another tutorial I saw that the HTML has a reference to a file that ends in .phpDo I somehow create an additional file wiht the script in it?I do not have php on my computer so I am unsure exactly how to create a .php file and reference it.however, in the form tutorial that Crayon Violet so generously took the time to point out to me I did not see a .phpHere's the code I used:<?php // database information $host = 'I'; $user = 'changed'; $password = 'these'; $dbName = 'variables'; // connect and select the database $conn = mysql_connect($host, $user, $password) or die(mysql_error()); $db = mysql_select_db($dbName, $conn) or die(mysql_error()); // insert new entry in the database if entry submitted if (isset($_POST['newEntry']) && trim($_POST['newEntry']) != '') { // for easier variable handling... $newEntry = $_POST['newEntry']; // insert new entry into database $sql = "insert into testTable (someField) values ('$newEntry')"; $result = mysql_query($sql, $conn) or die(mysql_error()); } // end if new entry posted // select all the entries from the table $sql = "select someField from testTable"; $result = mysql_query($sql, $conn) or die(mysql_error()); // echo out the results to the screen while ($list = mysql_fetch_array($result)) { echo "{$list['someField']} <br>"; } // end while // echo out the form to add a new entry echo <<<FORMENT <br> Make a new entry: <br> <form action = "{$_SERVER['PHP_SELF']}" method = "post"> <input type = "text" name = "newEntry" maxlength="20" size = "10"> <input type = "submit" value = "Add Entry"> </form> FORMENT;I see nowhere besides where I typed where I could change anything... I'm a rank newbie..As always, any and all help is much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/33126-hoping-to-glean-some-pearls-of-wisdom-from-the-graybeards/#findComment-154673 Share on other sites More sharing options...
c4onastick Posted January 7, 2007 Share Posted January 7, 2007 The actual PHP script needs to reside on the server that's hosting it, which could be your personal computer if you're using it as a server, and no, you don't have to have PHP installed to write a PHP script on your computer. If you want to actually [b]run[/b] it, you [b]will[/b] need PHP installed. The ".php" extension is purely for the web server to know to run it through the PHP parser before sending it to the client. I've got scripts I've written for command line use (CLI) that don't have any extension! You code looks pretty good, if this is on a public website you're going to want to implement some kind of check on the form data that's submitted (A mood point at this juncture). You'll need to add some HTML tags to get the display right in a browser. [code]<html><body><?php // database information $host = 'I'; $user = 'changed'; $password = 'these'; $dbName = 'variables'; // connect and select the database $conn = mysql_connect($host, $user, $password) or die(mysql_error()); $db = mysql_select_db($dbName, $conn) or die(mysql_error()); // insert new entry in the database if entry submitted if (isset($_POST['newEntry']) && trim($_POST['newEntry']) != '') { // for easier variable handling... $newEntry = $_POST['newEntry']; // insert new entry into database $sql = "insert into testTable (someField) values ('$newEntry')"; $result = mysql_query($sql, $conn) or die(mysql_error()); } // end if new entry posted // select all the entries from the table $sql = "select someField from testTable"; $result = mysql_query($sql, $conn) or die(mysql_error()); // echo out the results to the screen while ($list = mysql_fetch_array($result)) { echo $list['someField']."\n"; } // end while // echo out the form to add a new entry?>Make a new entry:<br> <form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method = "post"> <input type = "text" name = "newEntry" maxlength="20" size = "10"> <input type = "submit" value = "Add Entry"></form></body></html>[/code]In order to create a ".php" file, just grab Visual N++ (Notepad) and save it as type "All files" then save it as "yourscript.php" then upload it to your server, and point your browser at it. I find its easier (more readable) just to drop out of PHP than to do the "echo <<<Tag" thing. Quote Link to comment https://forums.phpfreaks.com/topic/33126-hoping-to-glean-some-pearls-of-wisdom-from-the-graybeards/#findComment-154696 Share on other sites More sharing options...
Gwhiz Posted January 7, 2007 Author Share Posted January 7, 2007 Thanks a lot for the help.I'm using this script on a typepad blog, so in that case is typepad the server? What I've done so far is created the MySQL database and put the code in the HTML for the blog and that does not work. So what else do I need to do to make it work? Quote Link to comment https://forums.phpfreaks.com/topic/33126-hoping-to-glean-some-pearls-of-wisdom-from-the-graybeards/#findComment-155064 Share on other sites More sharing options...
Gwhiz Posted January 9, 2007 Author Share Posted January 9, 2007 :) Quote Link to comment https://forums.phpfreaks.com/topic/33126-hoping-to-glean-some-pearls-of-wisdom-from-the-graybeards/#findComment-156310 Share on other sites More sharing options...
chronister Posted January 9, 2007 Share Posted January 9, 2007 [quote]I'm using this script on a typepad blog, so in that case is typepad the server? [/quote]yes, this is the server[quote]What I've done so far is created the MySQL database and put the code in the HTML for the blog and that does not work.[/quote]make sure the file ends in .phpphp cannot be parsed in a .html file unless the server is specially configured to do so. Most commercial servers are not.To ensure that your page is php and that php is going to be parsed in the file simply echo something[code]<?php echo "The server is working otherwise I could not see this"; ?>[/code]This will output onscreen: The server is working otherwise I could not see thisIf you cannot see that message or whatever you want to put between the " " then php is not parsing that page. Try that and let us know what you find Quote Link to comment https://forums.phpfreaks.com/topic/33126-hoping-to-glean-some-pearls-of-wisdom-from-the-graybeards/#findComment-156333 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.