Jump to content

Recommended Posts

I've had some help with a form script, however, the way it is written points toward "localhost" once the form is submitted to a database.  My host does not allow "localhost", but I actually have to point the data to the host with all of the db info.  This is what I have to start with:

if (isset($_POST['subedit'])) {
  $opMode='gather';
}
if (isset($_POST['subapprove'])) {
if (isset($_POST['subedit'])) {
  $opMode='gather';
}
if (isset($_POST['subapprove'])) {
  if (mysql_query("INSERT INTO table SET ...")) {
      $opMode='added';
  } else {
      $opMode='fail';
  }
}

 

Would I change it to something like this?

 

if (isset($_POST['subedit'])) {
  $opMode='gather';
}
if (isset($_POST['subapprove'])) {
if (isset($_POST['subedit'])) {
  $opMode='gather';
}
if (isset($_POST['subapprove'])) {
  if $con = mysql_connect("mydb.db.1234567.hostedresource.com","mydb","mypassword");
       if (!$con) {
        die('Could not connect: ' . mysql_error()); }
        mysql_select_db("mydb", $con);

INSERT INTO contact_info (name, email)

VALUES

('$_POST[name]','$_POST[email]')");

mysql_close($con);

{
      $opMode='added';
  } else {
      $opMode='fail';
  }
}

 

Thanks all for your help!

Link to comment
https://forums.phpfreaks.com/topic/155560-another-form-question/
Share on other sites

Well the first piece of code you have doesn't connect to your database at all.  Where is that happening? That's what you would want to change, instead of adding what you did (the 2nd piece of code you posted).  If your code was working before with the 'localhost' wherever you were testing it, and now you have to point to somewhere else for this host you are using, all you should have to do is change 'localhost' to the database server specified by your host (according to your 2nd script, it looks like 'mydb.db.1234567.hostedresource.com').

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.