Help connecting Database with Script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
goneinsane
Forum Newbie
Posts: 6
Joined: Fri Oct 09, 2009 2:59 pm

Help connecting Database with Script

Post by goneinsane »

Hello,

Added field to form where the user will enter the template name. Seems to be working very well, adds the name to the table in database. Here is the code:

Code: Select all

 
 
<?
 
require_once("../co.php");
require_once("ac.php");
 
if(isset($_POST[s1]))
{
    $NewPassword1 = strip_tags($_POST[NewPass1]);
    $NewPassword2 = strip_tags($_POST[NewPass2]);
    $NewMerchantName = strip_tags($_POST[MerchantName]);
    $NewMerchantEmail = strip_tags($_POST[MerchantEmail]);
    $NewTemplateName = strip_tags($_POST[TemplateName]);
    $NewMerchantPayPal = strip_tags($_POST[MerchantPayPal]);
    $NewSalesTax1 = strip_tags($_POST[SalesTax1]);
    $NewName = strip_tags($_POST[MerchantSiteName]);
    $NewSlogan = strip_tags($_POST[MerchantSiteSlogan]);
    $NewTitle = strip_tags($_POST[MerchantSiteTitle]);
    $NewKeywords = strip_tags($_POST[MerchantSiteKeywords]);
    $NewDesc = strip_tags($_POST[MerchantSiteDesc]);
    $NewHelp = strip_tags($_POST[Help]);
 
    if($_POST[NewAdmin] != $_SESSION[mun])
    {
        $NewMerchantID = $_POST[NewAdmin];
 
        $_SESSION[mun] = $NewMerchantID;
    }
    else
    {
        $NewMerchantID = $_SESSION[mun];
    }
 
 
    $NewLogoFile = $_FILES[logo][name];
 
    if(!empty($NewLogoFile))
    {
        $NewLogoName = $NewLogoFile;
 
        //delete the old logo
        if(!empty($_POST[MerchantLogo]))
        {
            unlink("../MyImages/".$_POST[MerchantLogo]);
        }
 
        //upload the new logo file
        copy($_FILES[logo][tmp_name], "../MyImages/".$NewLogoName);
    }
    else
    {
        $NewLogoName = $_POST[MerchantLogo];
    }
 
    if(!empty($NewPassword1))
    {
        if(empty($NewPassword2) || ($NewPassword1 != $NewPassword2))
        {
            $up_error = "<center><font color=red size=2 face=verdana><b>Retype and confirm your new password again, please!</b></font></center>";
        }
        elseif($NewPassword1 == $NewPassword2)
        {
            $NewPassword = md5($NewPassword1);
        }
    }
    elseif(empty($NewMerchantName))
    {
        $up_error = "<center><font color=red size=2 face=verdana><b>Enter your name, please!</b></font></center>";
    }
        elseif(empty($NewTemplateName))
    {
        $up_error = "<center><font color=red size=2 face=verdana><b>Enter the template you wish to use.</b></font></center>";
    }
    elseif(empty($NewMerchantEmail) || !ereg("@", $NewMerchantEmail))
    {
        $up_error = "<center><font color=red size=2 face=verdana><b>Enter your email, please!</b></font></center>";
    }
    elseif(empty($NewMerchantPayPal))
    {
        $up_error = "<center><font color=red size=2 face=verdana><b>Enter your PayPal.com email, please!</b></font></center>";
    }
    elseif(!empty($NewSalesTax1))
    {
        if($_POST[SalesTax2] == "no sales tax")
        {
            $up_error = "<center><font color=red size=2 face=verdana><b>You should define the Sales Tax clause!</b></font></center>";           
        }
        else
        {
            $MySalesTax = "$NewSalesTax1|$_POST[SalesTax2]";
        }
    }
 
    if(!isset($up_error))
    {
        if(isset($NewPassword))
        {
            $q1 = "update devbg_merchants set 
                            MerchantID = '$NewMerchantID',
                            MerchantPass = '$NewPassword',
                            MerchantName = '$NewMerchantName',
                            MerchantEmail = '$NewMerchantEmail',
                            TemplateName = '$NewTemplateName',
                            MerchantPayPal = '$NewMerchantPayPal',
                            MerchantSiteName = '$NewName',
                            MerchantSiteSlogan = '$NewSlogan',
                            MerchantSiteTitle = '$NewTitle',
                            MerchantSiteKeywords = '$NewKeywords',
                            MerchantSiteDesc = '$NewDesc',
                            SalesTax = '$MySalesTax',
                            Help = '$NewHelp',
                            sp_payee_email = '$_POST[sp_payee_email]',
                            sp_vendor_email = '$_POST[sp_vendor_email]',
                            sp_secret_code = '$_POST[sp_secret_code]'    ";
        }
        else
        {
            $q1 = "update devbg_merchants set 
                            MerchantID = '$NewMerchantID',
                            MerchantName = '$NewMerchantName',
                            MerchantEmail = '$NewMerchantEmail',
                            TemplateName = '$NewTemplateName',
                            MerchantPayPal = '$NewMerchantPayPal',
                            MerchantSiteName = '$NewName',
                            MerchantSiteSlogan = '$NewSlogan',
                            MerchantSiteTitle = '$NewTitle',
                            MerchantSiteKeywords = '$NewKeywords',
                            MerchantSiteDesc = '$NewDesc',
                            SalesTax = '$MySalesTax',
                            Help = '$NewHelp',
                            sp_payee_email = '$_POST[sp_payee_email]',
                            sp_vendor_email = '$_POST[sp_vendor_email]',
                            sp_secret_code = '$_POST[sp_secret_code]'    ";
        }
 
        mysql_query($q1) or die(mysql_error());
 
    }
 
 
 
}
 
//get the merchant information
$q1 = "select * from devbg_merchants where MerchantID = '$_SESSION[mun]' ";
$r1 = mysql_query($q1) or die(mysql_error());
$a1 = mysql_fetch_array($r1);
 
?>
 
<form method=post  enctype="multipart/form-data">
  <table align=center width=450>
    <caption align=center>
    <font size=2><b>Edit Account Information</b></font><br>
    <?=$up_error?>
    </caption>
    <tr style="background-color:#B0B0B0; font-family:verdana; font-size:11; font-weight:bold; color:white"> 
      <td colspan=2>Change your Admin ID:</td>
    </tr>
    <tr> 
      <td>New Admin ID:</td>
      <td><input type=text name=NewAdmin value="<?=$a1[MerchantID]?>"></td>
    </tr>
    <tr style="background-color:#B0B0B0; font-family:verdana; font-size:11; font-weight:bold; color:white"> 
      <td colspan=2>Change your password:</td>
    </tr>
    <tr> 
      <td>New password:</td>
      <td><input type=password name=NewPass1></td>
    </tr>
    <tr> 
      <td>Confirm password:</td>
      <td><input type=password name=NewPass2></td>
    </tr>
    <tr style="background-color:#B0B0B0; font-family:verdana; font-size:11; font-weight:bold; color:white"> 
      <td colspan=2>Personal Information:</td>
    </tr>
    <tr> 
      <td>Your name:</td>
      <td><input type=text name=MerchantName value="<?=$a1[MerchantName]?>"></td>
    </tr>
    <tr> 
      <td>Contact Email:</td>
      <td><input type=text name=MerchantEmail value="<?=$a1[MerchantEmail]?>"></td>
    </tr>
    <tr> 
      <td>Theme:</td>
      <td><input type=text name=TemplateName value="<?=$a1[TemplateName]?>"></td>
    </tr>
    <tr style="background-color:#B0B0B0; font-family:verdana; font-size:11; font-weight:bold; color:white"> 
      <td colspan=2>Payment settings:</td>
    </tr>
    <tr> 
      <td>PayPal Email:</td>
      <td><input type=text name=MerchantPayPal value="<?=$a1[MerchantPayPal]?>"></td>
    </tr>
Now on most of my pages I have the header code that looks like this:

Code: Select all

require_once("themes/Default/header.php");
I wanted to change the word Default to add in whatever word the user has entered in the form.
I have tried:

Code: Select all

require_once("themes/$a1[TemplateName]/header.php");
and

Code: Select all

require_once("themes/" . $a1[TemplateName] . "/header.php");
but neither of them are working.

Does anyone know what I am doing wrong???
goneinsane
Forum Newbie
Posts: 6
Joined: Fri Oct 09, 2009 2:59 pm

Re: Help connecting Database with Script

Post by goneinsane »

Oh yes and I forgot to mention...the Default folder is there and is typed into the form and saved in the database.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Help connecting Database with Script

Post by requinix »

Code: Select all

require_once("themes/$a1[TemplateName]/header.php");
That will work if $a1 has the right values.

What does a print_r($a1) give?
Post Reply