0

I need some help with this project. I've gone as far as I can go, with no results, The inquiry form works, but I need to populate it with my sql table. I could only screen shot my sql and I have no idea of how to put it on here. The following is the scenerio: Uploading Information Directly into the Inquiry Table

In this scenario you will be using the inquiry form created in project 3, and the table named inquiry created in project 4. User responses’ must be uploaded into the inquiry table by using the MySQL statements. Add the code to upload the information to the inquiry table on the email.php file (the file used to send the emails from the inquiry form). To test that the results were uploaded into the table, use an if…else statement to display to the screen if the results were uploaded or not. Add at least 3 inquiry responses.

NOTE: Be sure the fields names of the inquiry form match the values variable names created to ensure the results are uploaded into the table. If problems with uploading the results, first look at the names of the fields, and order listed.This is my inquiry.php:

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>Untitled Document</title>

</head> 

<body>





 <?php

$name = $_POST ['name'];

$address = $_POST ['address'];

$city = $_POST ['city'];

$state = $_POST ['state'];

$zip = $_POST ['zip'];

$phone = $_POST ['phone'];

$email = $_POST ['email'];

$major = $_POST ['major'];

$year = $_POST ['year'];

$semester = $_POST ['semester'];



$to="bmunn@mail.niagara.edu, therock691@gmail.com"; //an email is sent to your email account and to 



$message="To Whom It May Concern, <br>";

$message.="My information is listed below: <br><br>";

$message.="Name: $name<br>";

$message.="Address: $address<br>";

$message.="City: $city<br>";

$message.="State: $state<br>";

$message.="Zip: $zip<br>";

$message.="Phone: $phone<br>";

$message.="Email: $email<br>";

$message.="Major: $major<br><br>";

$message.="I plan to enter in the $semester of $year. <br>";

$message.="Please assist me in this matter.<br><br>";

$message.="Respectfully,<br>";

$message.="B Munn<br>";



$subject="University - Inquiry Form";//The subject of the email is �University - Inquiry Form�



$headers = "MIME-Version: 1.0" . "\r\n";

$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";



$headers .= "From: <therock691@gmail.com>" . "\r\n";//the email should like it was sent from the person contacting University





$response=mail($to,$subject,$message,$headers);



if($response)

{

                Echo "Email sent successfully";

}

else //

{

                Echo "Error Occured while sending email";           

}



$hostname = "localhost";

$username = "vde_bmunn";

$password = "s0123456";

$database = "bmunn";

$table = "inquiry";



mysql_connect($hostname, $username, $password) or die("Unable to connect to database");

mysql_select_db($database) or die ("Unable to select db");



$fields = "id, name, address, city, state, zip, phone, email, major, semester year";

$values = "'$id', '$name', '$address', '$city', 'state', 'zip', 'phone', 'email', 'major'. 'semester', 'year'";



$query = "INSERT INTO $table ($fields) VALUES ($values)";

$result = mysql_query($query);



if($result)

                echo "Thank you for completing the Inquiry Form";

else

                echo "Sorry, this is not currently working";





?>

<br>

<br>

<a href='inquiry.html'>Go back to contact form</a></body>

</html>



HTML Document:



<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>Untitled Document</title>

<script type="text/javascript">

function MM_validateForm() { //v4.0

  if (document.getElementById){

    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;

    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);

      if (val) { nm=val.name; if ((val=val.value)!="") {

        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');

          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';

        } else if (test!='R') { num = parseFloat(val);

          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';

          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');

            min=test.substring(8,p); max=test.substring(p+1);

            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';

      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }

    } if (errors) alert('The following error(s) occurred:\n'+errors);

    document.MM_returnValue = (errors == '');

} }

</script>

</head>



<body>

<form action="inquiry.php" method="post" name="form1" id="form1">

  <h2>Niagara University Enrollment Form</h2>

  <table width="500" border="1">

    <tr>

      <td width="171"><label for="name">Name:</label></td>

      <td width="313"><input name="name" type="text" id="name" form="form1" title="name"></td>

    </tr>

    <tr>

                  <td width="171"><label for="name">Street Address:</label></td>

      <td width="313"><input type="text" name="address" id="address"></td>

    </tr>

    <tr>

                  <td width="171"><label for="name">City:</label></td>

      <td width="313"><input type="text" name="city" id="city"></td>

    </tr>

    <tr>

                  <td width="171"><label for="name">State:</label></td>

      <td width="313"><input type="text" name="state" id="state"></td>

    </tr>

    <tr>

                  <td width="171"><label for="name">Zip Code:</label></td>

      <td width="313"><input type="text" name="zip" id="zip"></td>

    </tr>

    <tr>

                  <td width="171"><label for="name">Telephone:</label></td>

      <td width="313"><input name="phone" type="text" id="phone" onBlur="MM_validateForm('name','','R','address','','R','city','','R','state','','R','zipcode','','RisNum','phone','','R','email','','RisEmail','major','','R');return document.MM_returnValue"></td>

    </tr>

    <tr>

                  <td width="171"><label for="name">Email Address:</label></td>

      <td width="313"><input type="text" name="email" id="email"></td>

    </tr>

    <tr>

                  <td width="171"><label for="name">Intended Major:</label></td>

      <td width="313"><input type="text" name="major" id="major"></td>

    </tr>

    <tr>

      <td>&nbsp;</td>

      <td>&nbsp;</td>

    </tr>

    <tr>

      <td><label for="select">Year:</label></td>

      <td><select name="year" id="year" >

        <option value="">Select Year</option>

          <option value="2014">2014</option>

          <option value="2015">2015</option>

          <option value="2016">2016</option>

          <option value="2017">2017</option>

      </select></td>

        <label for="select3"></label>

    <tr>

      <td><label for="select">Semester:

      </label></td>

      <td width="313"><select name="semester" id="semester"  title="semester">

        <option value="">Select Semester</option>

        <option value="Spring">Spring</option>

        <option value="Summer">Summer</option>

        <option value="Fall">Fall</option>

      </select>        </td>

    </tr>

    <tr>

      <td>&nbsp;</td>

      <td>&nbsp;</td>

    </tr>

    <tr>

                  <td width="171"><input name="submit" type="submit" id="submit" onClick="MM_validateForm('name','','R','address','','R','city','','R','state','','R','zip','','RisNum','phone','','R','email','','NisEmail','major','','R');return document.MM_returnValue" value="Submit"></td>

    </tr>

  </table>

</form>

</body>


</html>

Edited by diafol: unformatted code block to exclude intro

2
Contributors
8
Replies
24
Views
3 Years
Discussion Span
Last Post by burt.munn
0

You are missing dollar signs for the correct variables in your $values

Can you be a little more specific about what works and what does not?

Edited by pritaeas

0

This is the message I get when I submit the form: Email sent successfully
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'vdevine'@'localhost' (using password: NO) in /home/vdevine/public_html/bmunn/php/inquiry.php on line 64
Unable to connect to database

0

my database credentials are correct. In my first project I made a cotact form using html and php and the form worked correct. In my next project I made a database in putty that has all the same fields as my contact form. I'm not sure if my last step of adding the script in php to upload my sql information into the form is correct.Can you tell me if that information is correct and I will verify my user information again. Thanks

0

my database credentials are correct

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'vdevine'@'localhost' (using password: NO) in /home/vdevine/public_html/bmunn/php/inquiry.php on line 64

The above states otherwise.

0

Is the script correct then other than my credentials? This is what I get now:
Email sent successfullySorry, this is not currently working

Go back to contact form

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.