Jump to content

Another form question


jamichelli

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').

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.