Jump to content

Hoping to glean some pearls of wisdom from the graybeards...


Recommended Posts

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
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.
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.

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 .php
Do 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 .php

Here'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.
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.
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]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 .php

php 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 this

If 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
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.