Jump to content

Database Help


njmorgan

Recommended Posts

I am trying to send contact information from a website to a sql database.  All the code that I have here has worked for the past 6 months and all of a sudden, nothing gets passed but blank fields to the database.  I also had some other coding errors that were already cleaned up.  I'm thinking there was some sort of PHP or Server update that could have caused this.  Could someone just make sure that there isn't something that might need touched up for it to work again.  Thanks!
Link to comment
Share on other sites

<?php

if($submit)
{
$db=mysql_connect ("localhost", "hfarmour_test", "test") or die ('I cannot connect to the database because: ' . mysql_error());

mysql_select_db("hfarmour_students",$db);
$sql = "INSERT INTO Students (fname, lname, address, city, state, zip, PhoneNum, email, contact) VALUES ('$fname', '$lname', '$address','$city','$state', '$zip', '$PhoneNum', '$email', '$contact')";
$result = mysql_query($sql);
echo "Thank you! Information entered. We will be contacting you shortly.";
}
else
{
?>

Link to comment
Share on other sites

<p>Please enter your personal information if you would like to be contacted with further information: </p>
            <FORM method="post" action="input.php">
              <table width="100%" border="0" cellspacing="1">
  <tr>
    <td width="35%">Name: </td>
    <td width="65%"><input type="text" name="fname" size="25" maxlength="25" value="first name" /> <input type="text" name="lname" size="25" maxlength="25" value="last name" /></td>
  </tr>
  <tr>
    <td>Addresss: </td>
    <td><input type="text" name="address" size="50" maxlength="50" /></td>
  </tr>
  <tr>
    <td>City:</td>
    <td><input type="text" name="city" size="25" maxlength="50" /></td>
  </tr>
  <tr>
    <td>State/Province:</td>
    <td><input type="text" name="state" size="15" maxlength="20" /></td>
  </tr>
  <tr>
    <td>Zip: </td>
    <td><input type="text" name="zip" size="10" maxlength="10" /></td>
  </tr>
  <tr>
    <td>Phone Number: </td>
    <td><input type="text" name="PhoneNum" size="12" maxlength="12" /></td>
  </tr>
  <tr>
    <td>Email Address: </td>
    <td><input type="text" name="email" size="25" maxlength="50" /></td>
  </tr>
  <tr>
    <td>Preferred Way of Contact: </td>
    <td><label>
      <input type="radio" name="contact" value="Telephone" />
Telephone</label></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><label>
      <input type="radio" name="contact" value="Mail" />
Mail</label></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><label>
      <input type="radio" name="contact" value="Email" />
Email</label></td>
  </tr>
</table>

  <center>
  <input name="submit" type="Submit" value="Enter information">
  <input name="reset" type="reset" value="Reset Form">
  </center>
  </FORM>
 
<?
}
?>
Link to comment
Share on other sites

FILE INPUT.PHP

<?php

session_start();
require_once('common.php');

$sql = "INSERT INTO Students (fname, lname, address, city, state, zip, PhoneNum, email, contact) VALUES ('$fname', '$lname', '$address','$city','$state', '$zip', '$PhoneNum', '$email', '$contact')";
$result = mysql_query($sql);
echo "Thank you! Information entered. We will be contacting you shortly.";

?>
<HTML>
</HTML>
Link to comment
Share on other sites

It looks like register_globals may have been switched off on your server.  Instead of using variables directly, like [code=php:0]$fname[/code], you can use the alternative syntax [code=php:0]$_REQUEST['fname'][/code].  That will work for variables from both POST and GET forms.

Like this:

[code=php:0]$sql = "INSERT INTO Students (fname, lname, address, city, state, zip, PhoneNum, email, contact) VALUES ('{$_REQUEST['fname']}', '{$_REQUEST['lname']}', ...[/code]


You may also need to check [code=php:0]$_REQUEST['submit'][/code] instead of [code=php:0]$submit[/code]
Link to comment
Share on other sites

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.