help....new starter

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
butty22
Forum Newbie
Posts: 8
Joined: Tue Apr 21, 2009 2:23 pm

help....new starter

Post by butty22 »

i have created a form on MS word and saved it as html. the html version has now been saved on a subdomain on my site. i managed to incorporate the submit button into the form and asked it to send the data on the form to an email address. i have also created about 7 tables on the mysql database to correspond to the fields on the form.

my question/help is that what do i need to do to get the data filled on the form written to the database once the submit is clicked as well as emailing to the email address?

this is the code i tried for a section of the form but it didnt work.

Code: Select all

<?php
 
if (isset($_POST['submitbutton']))
{
  $name=proposeduni = mysql_real_escape_string($_POST['name=proposeduni']);
  $name=proposedcourse = mysql_real_escape_string($_POST['name=proposedcourse']);
 
  mysql_query("INSERT INTO table courses (proposed coluni, proposed course) VALUES ('$name=proposeduni', '$name=proposedcourse')");
}
 
?>
 
thanks
Last edited by Benjamin on Sat Apr 25, 2009 1:48 am, edited 1 time in total.
Reason: Changed code type from text to php
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: help....new starter

Post by JAB Creations »

Whoa! Do not use Microsoft Word for any sort of coding period! It will add tons of junk that will only work in Internet Explorer and screw up the rendering in standards compliant browsers. You should use a plain text editor such as notepad or something specifically designed for coders. Check out this thread for editors people use...
viewtopic.php?f=6&t=81100

I personally use SuperEdi at the moment and have for a couple years at least now.

Check PHP's mail function which will usually only work on live servers so you will not be able to successfully test it on your own system.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: help....new starter

Post by califdon »

I agree with ~JAB Creations and would point out further that you really need to start with something simpler, to gain an appreciation of what HTML is, what PHP is, what MySQL is. I'm going to assume that it was just a terminology error when you said that you have "created about 7 tables on the mysql database to correspond to the fields on the form." You sure don't want to do THAT! Undoubtedly you need several fields in A table, but not 7 tables.

I suggest that you read some online tutorials about basic web page creation (NOT using Word or any word processing software!), and PHP and MySQL. There's no point in trying to answer your questions at this point, because we would have to tell you absolutely every line of code to write. Use Google to search for terms like html basic tutorial, php tutorial, mysql tutorial. There are some good ones out there.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: help....new starter

Post by Benjamin »

You ought to be connecting to the MySQL server and selecting a database before you attempt to run mysql_query. Reference mysql_connect and mysql_select_db in the manual. You should not have spaces in your table field names, and you need to remove the word table from your query. Only the table name should be there, not table tablename.
butty22
Forum Newbie
Posts: 8
Joined: Tue Apr 21, 2009 2:23 pm

Re: help....new starter

Post by butty22 »

thanks all for your advice but i would like to point out that this form in question was initially designed to be a word document... as time went by we were advised we could save it as html and put it on our site! which is what we did... yes i do agree that word does add alot of junk to the code but the nature of the form is developed such that everyone is reluctant to start designing another form to match the same fields on the existing form. but at the moment the form currently works perfectly on IE and Firefox.
thanks everyone for help and advice, greatly appreciated and taken on board...any future forms would be done using a php editor and not MS word.

at the moment, i have tried connecting to my database using the code below and i get the attached screen shot...help, what i done wrong?

Code: Select all

<?php
function MySQLDB(){
      /* Make connection to database */
      $this->connection = mysql_connect(localhost, x_n, x) or die(mysql_error());
      mysql_select_db(db $this->connection) or die(mysql_error());
 
if (isset($_POST['submitbutton']))
{
  $name=uni = mysql_real_escape_string($_POST['name=uni']);
  $name=course = mysql_real_escape_string($_POST['name=course']);
  mysql_query("INSERT INTO courses (proposed_coluni, proposed_course) VALUES ('$name=uni', '$name=course')")or die(mysql_error();
}
?>
<HTML>
<HEAD><TITLE></TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
 
Last edited by butty22 on Tue Apr 28, 2009 6:24 am, edited 2 times in total.
eskio
Forum Commoner
Posts: 66
Joined: Tue Apr 01, 2008 1:00 am

Re: help....new starter

Post by eskio »

Try this

Code: Select all

<?php
if (isset($_POST['submitbutton']))
{
 $connection = mysql_connect('localhost', 'x_n','x') or die(mysql_error());
 mysql_select_db('spearventures_n', $connection) or die(mysql_error());
  $proposeduni = mysql_real_escape_string($_POST['proposeduni']);
  $proposedcourse = mysql_real_escape_string($_POST['proposedcourse']);
  mysql_query("INSERT INTO courses (proposed_coluni, proposed_course) VALUES ('$proposeduni', '$proposedcourse')")or die(mysql_error();
}
?>
Last edited by Benjamin on Sat Apr 25, 2009 1:49 am, edited 1 time in total.
Reason: Changed code type from text to php
butty22
Forum Newbie
Posts: 8
Joined: Tue Apr 21, 2009 2:23 pm

Re: help....new starter

Post by butty22 »

thanks for the reply, i have pasted it as suggested, the error message earlier as now cleared of but its still not writing the database.... i also tried pasting it within the form where i have form action but still not writing as well... what do i do now?
eskio
Forum Commoner
Posts: 66
Joined: Tue Apr 01, 2008 1:00 am

Re: help....new starter

Post by eskio »

Code: Select all

<?php
if (isset($_POST['submitbutton']))
{
 $connection = mysql_connect('localhost', 'x_n','x') or die(mysql_error());
 mysql_select_db('spearventures_n', $connection) or die(mysql_error());
  $proposeduni = mysql_real_escape_string($_POST['proposeduni']);
  $proposedcourse = mysql_real_escape_string($_POST['proposedcourse']);
  $query = "INSERT INTO courses (proposed_coluni, proposed_course) VALUES ('$proposeduni', '$proposedcourse')";
  if (mysql_query($query)) {
     print 'Successfully inserted<br />';
 } else {
     print 'Not inserted<br />';
  } // mysql_query
}
?>
When you click the submit button, you should have one of the message.
Last edited by Benjamin on Sat Apr 25, 2009 1:49 am, edited 1 time in total.
Reason: Changed code type from text to php
butty22
Forum Newbie
Posts: 8
Joined: Tue Apr 21, 2009 2:23 pm

Re: help....new starter

Post by butty22 »

right am starting to feel really stupid here... this is my code now, still no error message received...

Code: Select all

<FORM action="http://www.abc.com/cgi-bin/FormMail.pl " method=post><INPUT type=hidden value=a@abc.com name=recipient> <INPUT type=hidden value="Form" name=subject> <INPUT type=hidden value=http://www.abc.com name=redirect><action="input.php"> 
 
my inout.php code is

Code: Select all

<?php
if (isset($_POST['submitbutton']))
{
 $connection = mysql_connect("localhost", "x","v");
if (!$connection)
  {
 die('Could not connect: ' . mysql_error());
  }
mysql_select_db("y", $connection) or die(mysql_error());
  $uni = mysql_real_escape_string($_POST['uni']);
  $course = mysql_real_escape_string($_POST['proposedcourse']);
  $query = "INSERT INTO courses (proposed_coluni, proposed_course) VALUES ('$uni', '$course')";
  if (mysql_query($query)) {
     print 'Successfully inserted<br />';
 } else {
     print 'Not inserted<br />';
  } // mysql_query
}
?>
cant seem to figure the error there now :cry:
Last edited by butty22 on Tue Apr 28, 2009 6:27 am, edited 2 times in total.
eskio
Forum Commoner
Posts: 66
Joined: Tue Apr 01, 2008 1:00 am

Re: help....new starter

Post by eskio »

your form action should be
action='inout.php'
instead of
(this is a PERL script???)
butty22
Forum Newbie
Posts: 8
Joined: Tue Apr 21, 2009 2:23 pm

Re: help....new starter

Post by butty22 »

i changed my action to input.php as advised and got rid of the perl script...all i get when the submit button is clicked is a blank screen...nothing happens and no emails are received...
eskio
Forum Commoner
Posts: 66
Joined: Tue Apr 01, 2008 1:00 am

Re: help....new starter

Post by eskio »

for the moment just use one page. leave the Action attribute of the form empty ("") and paste the code of inout.php at the top of the page. When you submit, the same page will reload and in this case you should have one of the message:

Code: Select all

if (mysql_query($query)) {
      print 'Successfully inserted<br />';
  } else {
      print 'Not inserted<br />';
   } // mysql_query
Last edited by Benjamin on Sat Apr 25, 2009 1:50 am, edited 1 time in total.
Reason: Changed code type from text to php
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: help....new starter

Post by Benjamin »

butty22 wrote:i changed my action to input.php as advised and got rid of the perl script...all i get when the submit button is clicked is a blank screen...nothing happens and no emails are received...
A blank screen is indicative of a parse error or fatal error. Enable error reporting to view it.
Post Reply