Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Contact Form PHP & MySql
Old 03-01-2008, 02:30 PM Contact Form PHP & MySql
Novice Talker

Posts: 10
Name: Matthew Hartshorn
Trades: 0
Hello,

I am very new to writing PHP script and am more a designer. I have a contact form with an action to use a php page to query the MySQL DB. First I did not set up the DB(the client did and is a network guru...trying to save some pride before having him look at the code) and I have not been able to connect to the database with MySQL admin either due to my IP being not allowed with the server or my internet service provider. After hours of copy pasting and editing scripts I finally was able to get the php page to function but it won't let me connect and not sure if my placement of the redirect is correct.

Is this a MySQL login or PHP code problem? I figure I would try here first, since I am new to writing code. I know I have more than one issue here, but not networked with any coders to let me know. Humbly I would really just like to be educated rather than have someone do it for me.

here's my code for the PHP page.

Code:
<?php
$db_host = "host";
$db_user = "user";
$db_pwd = "password";
$db_name = "dbname";
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name) or die( "Unable to select database");
mysql_query($query);
 
$sql="INSERT INTO evwslg (fname, lname, email, typeofservice, address, city, state, zip, mphone, hphone, besttocall)
VALUES
('$_POST[fname]','$_POST[lname]','$_POST[email]' ,'$_POST[typeofservice]' ,'$_POST[address]' ,'$_POST[city]' ,'$_POST[state]' ,'$_POST[zip]' ,'$_POST[mphone]' ,'$_POST[hphone]' ,'$_POST[besttocall]')";
header("location: http://www.spicyfud.com/evwslg/contact/thankyou.html"); 
mysql_close($conn);
?>
Here's what the form looks like I'm using Dreamwaever CS3.

Code:
<form action="insert.php" method="post" name="form1" id="form1">
      <label>First Name<br />
      <input name="fname" type="text" id="fname" maxlength="30" />
      </label>
      <p>Last name<br />
              <label>
              <input name="lname" type="text" id="lname" maxlength="30" />
              </label>
      </p>
<p>
              <label>E-Mail<br />
              <input name="email" type="text" id="email" maxlength="50" />
              </label>
      </p>
<p>
  <label>Type Of Service<br />
  <select name="typeofservice" id="typeofservice">
    <option>Laser Hair Reduction</option>
    <option>Affirm Skin Rejuvenation</option>
    <option>Wrinkle Reduction</option>
    <option>Photo Facials</option>
    <option>Vein reduction</option>
    <option>Pigmented lesion Reduction</option>
    <option>Skin Tightening</option>
    <option>Acne Treatment</option>
    <option>Stretch Mark Reduction</option>
    <option>Medical Chemical Peels</option>
    <option>DNA Repair Facials</option>
    <option>Organic Facials</option>
    <option>Waxing</option>
    <option>Specialty Treatments for Expecting Moms</option>
    </select>
  </label>
</p>
<p>
  <label>Street Address<br />
  <input name="address" type="text" id="address" maxlength="20" />
  </label>
</p>
<p>
  <label>City<br />
  <input name="city" type="text" id="city" maxlength="25" />
  </label>
</p>
<p>
  <label>State<br />
  <select name="state" id="state">
    <option>AL</option>
    <option>AK</option>
    <option>AS</option>
    <option>AZ</option>
    <option>AR</option>
    <option>CA</option>
    <option>CO</option>
    <option>CT</option>
    <option>DE</option>
    <option>DC</option>
    <option>FM</option>
    <option>FL</option>
    <option>GA</option>
    <option>GU</option>
    <option>HI</option>
    <option>ID</option>
    <option>IL</option>
    <option>IN</option>
    <option>IA</option>
    <option>KS</option>
    <option>KY</option>
    <option>ME</option>
    <option>MH</option>
    <option>MD</option>
    <option>MA</option>
    <option>MI</option>
    <option>MN</option>
    <option>MS</option>
    <option>MO</option>
    <option>MT</option>
    <option>NE</option>
    <option>NV</option>
    <option>NH</option>
    <option>NJ</option>
    <option>NM</option>
    <option>NY</option>
    <option>NC</option>
    <option>ND</option>
    <option>MP</option>
    <option>OH</option>
    <option>OK</option>
    <option>OR</option>
    <option>PW</option>
    <option>PA</option>
    <option>PR</option>
    <option>RI</option>
    <option>SC</option>
    <option>SD</option>
    <option>TN</option>
    <option>TX</option>
    <option>UT</option>
    <option>VT</option>
    <option>VI</option>
    <option>VA</option>
    <option>WA</option>
    <option>WV</option>
    <option>WI</option>
    <option>WY</option>
  </select>
  </label>
</p>
<p>
  <label>Zip Code<br />
  <input name="zip" type="text" id="zip" maxlength="12" />
  </label>
</p>
<p>
              <label>Mobile Phone<br />
              <input name="mphone" type="text" id="mphone" maxlength="13" />
          </label>
      </p>
<p>Home Phone<br />
  <label>
  <input name="hphone" type="text" id="hphone" maxlength="13" />
  </label>
</p>
<p>
  <label>Best time to Call<br />
  <select name="besttocall" id="besttocall">
    <option>Morning</option>
    <option>Afternoon</option>
    <option>Evening</option>
  </select>
  </label>
</p>
<p>
              <label>
              <input type="submit" name="submit" id="submit" value="Submit" />
              </label>
      </p>
    </form>
goblinaire is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-01-2008, 04:12 PM Re: Contact Form PHP & MySql
Novice Talker

Posts: 10
Name: Matthew Hartshorn
Trades: 0
Oh if it helps


www.spicyfud.com/evwslg2.com/contact

The link should provide anyone that can help with a look at how my code is functioning.
goblinaire is offline
Reply With Quote
View Public Profile
 
Old 03-01-2008, 08:57 PM Re: Contact Form PHP & MySql
choskins102's Avatar
Super Talker

Posts: 137
Name: Casey
Trades: 3
I think you should check your link and put one that works in.
choskins102 is offline
Reply With Quote
View Public Profile
 
Old 03-01-2008, 09:21 PM Re: Contact Form PHP & MySql
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
You were trying to pass a non existant query to the mysql server. You also might need to use "localhost" as the db host. Also set a layer of protection to prevent nasty mysql injection.

PHP Code:
<?php
  
  
// Host probably is localhost or if hosted on another server
  // it might be a url with a port number
  // For example:  http://www.domain.com:3306
  
$db_host 'localhost';
  
$db_user 'user';
  
$db_pwd  'password';
  
$db_name 'database';
  
  
$conn mysql_connect($db_host$db_user$db_pwd) or die('Unable to connect DB');
  
mysql_select_db($db_name$conn) or die('Unable to select database');
  
  
$sql "
    INSERT INTO evwslg (fname, lname, email, typeofservice, address, city, state, zip, mphone, hphone, besttocall)
    VALUE (
      '" 
mysql_real_escape_string($_POST['fname']) . "',
      '" 
mysql_real_escape_string($_POST['lname']) . "',
      '" 
mysql_real_escape_string($_POST['email']) . "',
      '" 
mysql_real_escape_string($_POST['typeofservice']) . "',
      '" 
mysql_real_escape_string($_POST['address']) . "',
      '" 
mysql_real_escape_string($_POST['city']) . "',
      '" 
mysql_real_escape_string($_POST['state']) . "',
      '" 
mysql_real_escape_string($_POST['zip']) . "',
      '" 
mysql_real_escape_string($_POST['mphone']) . "',
      '" 
mysql_real_escape_string($_POST['hphone']) . "',
      '" 
mysql_real_escape_string($_POST['besttocall']) . "'
    )
  "
;
  
  
mysql_query($sql$conn);
  
mysql_close($conn);
  
  
header('Location: http://www.spicyfud.com/evwslg/contact/thankyou.html');
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 03-01-2008, 10:41 PM Re: Contact Form PHP & MySql
Novice Talker

Posts: 10
Name: Matthew Hartshorn
Trades: 0
thanks mgraphic

Think this might be a login issue or our server. It's a DB on a sepearte server and we're developing on GoDaddy server with Windows before going live. I don't think localhost will work once we transfer it anyway. I will try and squeeze it out of him if there's a port or if they have their server secured. I know my IP was rejected with MySQL admin, but I could ping the server.

kinda rough going we've received partial information from the client through out the development. We built a site and had to raze it after we finally received some input a month later. Scary thing is we have to do it all over again for a larger site for the same client. Think it might be time to set up a server at home to do the development and testing.
goblinaire is offline
Reply With Quote
View Public Profile
 
Old 03-01-2008, 10:54 PM Re: Contact Form PHP & MySql
Novice Talker

Posts: 10
Name: Matthew Hartshorn
Trades: 0
Mgraphic any chance you want to look at the database info I have via e-mail? I don't want to post it here.
goblinaire is offline
Reply With Quote
View Public Profile
 
Old 03-01-2008, 11:08 PM Re: Contact Form PHP & MySql
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
The thing about using an external database server is that it requires special configuration for it to work. Things like permissions, port blocking/firewall, etc all get in the way. You should talk with the hosting company and/or owner of the other server to have them set it up for you.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 03-02-2008, 02:55 AM Re: Contact Form PHP & MySql
Novice Talker

Posts: 10
Name: Matthew Hartshorn
Trades: 0
heh thanks. I kind of figured it was on their side but don't want to talk shop until I know more. I think we'll just send the client the php page and see if he knows why it won't connect.

The name of the server alone makes me think they have extra security on it.

This is a great place helped me more than the tutorials I've been through. thanks again.
goblinaire is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Contact Form PHP & MySql
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.60630 seconds with 12 queries