Jump to content

Recommended Posts

OK, I have a new host, and thus I now have the ability to use MySQL instead of Access.

 

I have a simple script, which I need to convert the code to utilize the new database. I will worry about migrating the content aft er I get teh script working.

 

OK, here's the current code:

 

<?php

if (isset($_POST['company'])) {
$company = $_POST['company'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$country = $_POST['country'];
$outside_us = $_POST['outside_us'];
$phone = $_POST['phone'];
$website = $_POST['website'];
$fax = $_POST['fax'];
$email = $_POST['email'];
$store_type = $_POST['store_type'];
$comments = $_POST['comments'];
$referral = $_POST['referral'];

$msg = "Attention Sliquid! You have a new vendor request!
Company Name = {$company} 
First Name = {$firstname}
Last Name = {$lastname}
Address = {$address1}
Address 2 = {$address2}
City = {$city}
State = {$state}
Zip = {$zip}
Country = {$country}
Shipping Info = {$outside_us}
Phone = {$phone}
Website = {$website}
Fax = {$fax}
Email = {$email}
Store Type = {$store_type}
Comments = {$comments}
Referred By = {$referral}";

Enter_New_Entry($company,$firstname,$lastname,$address1,$address2,$city,$state,$zip,$country,$outside_us,$phone,$website,$fax,$email,$store_type,$comments,$referral);

//ini_set(SMTP, "smtp.sliquid.com");
ini_set(SMTP, "mail.sliquid.com");
ini_set(smtp_port, 25);
ini_set(sendmail_from, "sales@sliquid.com");
$headers = "From: sales@sliquid.com\r\n";
$headers .= "BCC: dean@sliquid.com\r\n";
//mail(To, subject, content, header);
$to = "sales@sliquid.com";
$result  = mail($to, "New Vendor Request", $msg, $headers);
if( $result == 0 ) {
	echo "error <br>";

}
}
function Enter_New_Entry 
($company,$firstname,$lastname,$address1,$address2,$city,$state,$zip,$country,$outside_us,$phone,$website,$fax,$email,$store_type,$comments,$referral) {

$cnx = odbc_connect( 'records_db' , '******', '********' );
    if (!$cnx) {
        Error_handler( "Error in odbc_connect" , $cnx );
    }

    $SQL_Exec_String = "Insert Into distributors (company, firstname, lastname, address1, address2, city, state, zip, country, outside_us, phone, website, fax, email, store_type, comments, referral)
            Values ('$company', '$firstname', '$lastname', '$address1', '$address2', '$city', '$state', '$zip', '$country', '$outside_us', '$phone', '$website', '$fax', '$email', '$store_type', '$comments', '$referral')";

    $cur= odbc_exec( $cnx, $SQL_Exec_String );
    if (!$cur) {
        Error_handler( "Error in odbc_exec( no cursor returned ) " , $cnx );
}

odbc_close($cnx);  
header("location: http://www.sliquid.com/verify.htm"); 

}

?>

 

I found out how to change my db connection to mysql, but im lost on teh other parts (mysql_connect, mysql_exec?)

 

any ideas, solutions, or links to something that will show me all the equivalent functions between access and mysql?

 

Thanks

\colin

Link to comment
https://forums.phpfreaks.com/topic/52044-ms-access-to-mysql-conversion-need-help/
Share on other sites

OK, i got a test db connection page to work...

 

<html>
<head>
<title>MySQL database test</title>
</head>
<body>

<?php

if (!($db = 
mysql_connect("localhost","user_name","my_password"))) {
        print ("Unable to connect to database host: $_db_host");
        errorEmail();
        exit;
}

if (!(mysql_select_db("db_name",$db)))  {
        print ("Unable to select database: $_db_name");
        errorEmail();
        exit;
}

print "<p>Database connection successful.<br /></p>";


?>

</body>
</html>

 

when I access this page, it echos "Database connection successful"

 

however, when I run my original script:

function Enter_New_Entry 
($company,$firstname,$lastname,$address1,$address2,$city,$state,$zip,$country,$outside_us,$phone,$website,$fax,$email,$store_type,$comments,$referral) {

$cnx = mysql_connect("localhost","user_name","my_password");
    if (!$cnx) {
        Error_handler( "Error in mysql_connect" , $cnx );
    }

    $SQL_Exec_String = "Insert Into distributors (company, firstname, lastname, address1, address2, city, state, zip, country, outside_us, phone, website, fax, email, store_type, comments, referral)
            Values ('$company', '$firstname', '$lastname', '$address1', '$address2', '$city', '$state', '$zip', '$country', '$outside_us', '$phone', '$website', '$fax', '$email', '$store_type', '$comments', '$referral')";

    $cur= mysql_query( $cnx, $SQL_Exec_String );
    if (!$cur) {
        Error_handler( "Error in mysql_query( no cursor returned ) " , $cnx );
}

mysql_close($cnx);  
header("location: http://www.sliquid.com/verify.htm"); 

}

?>

 

nothing is inserted into the database...

no error message is returned...

and because of my submit to and my header redirect, it takes me to my old host...

 

 

looking at it, it seems that the dbtest script has a line that references the database name, where the form does not.

 

how can i modify the script to contain the reference to the database name, or is there a better way to accomplish this?

 

i cant find a way to edit my post, so Im just going to have to add new information.

 

I changed my script to point back to itself instead of the old host, as well as my header.

 

Now I am getting an error

<b>

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/sliquidc/public_html/become.php on line 47

 

Fatal error: Call to undefined function error_handler() in /home/sliquidc/public_html/become.php on line 49</b>

 

This is where the error is reporting:

    $cur= mysql_query( $cnx, $SQL_Exec_String );
    if (!$cur) {
        Error_handler( "Error in mysql_query( no cursor returned ) " , $cnx );

 

here is the whole code:

<?php

if (isset($_POST['company'])) {
$company = $_POST['company'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$country = $_POST['country'];
$outside_us = $_POST['outside_us'];
$phone = $_POST['phone'];
$website = $_POST['website'];
$fax = $_POST['fax'];
$email = $_POST['email'];
$store_type = $_POST['store_type'];
$comments = $_POST['comments'];
$referral = $_POST['referral'];

$msg = "Attention Sliquid! You have a new vendor request!
Company Name = {$company} 
First Name = {$firstname}
Last Name = {$lastname}
Address = {$address1}
Address 2 = {$address2}
City = {$city}
State = {$state}
Zip = {$zip}
Country = {$country}
Shipping Info = {$outside_us}
Phone = {$phone}
Website = {$website}
Fax = {$fax}
Email = {$email}
Store Type = {$store_type}
Comments = {$comments}
Referred By = {$referral}";

Enter_New_Entry($company,$firstname,$lastname,$address1,$address2,$city,$state,$zip,$country,$outside_us,$phone,$website,$fax,$email,$store_type,$comments,$referral);

//ini_set(SMTP, "smtp.sliquid.com");
ini_set(SMTP, "mail.sliquid.com");
ini_set(smtp_port, 25);
ini_set(sendmail_from, "sales@sliquid.com");
$headers = "From: sales@sliquid.com\r\n";
$headers .= "BCC: dean@sliquid.com\r\n";
//mail(To, subject, content, header);
$to = "sales@sliquid.com";
$result  = mail($to, "New Vendor Request", $msg, $headers);
if( $result == 0 ) {
	echo "error <br>";

}
}
function Enter_New_Entry 
($company,$firstname,$lastname,$address1,$address2,$city,$state,$zip,$country,$outside_us,$phone,$website,$fax,$email,$store_type,$comments,$referral) {

$cnx = mysql_connect("localhost","user_name","password");
    if (!$cnx) {
        Error_handler("Error in mysql_connect",$cnx);
    }

    $SQL_Exec_String = "Insert Into distributors (company, firstname, lastname, address1, address2, city, state, zip, country, outside_us, phone, website, fax, email, store_type, comments, referral)
            Values ('$company', '$firstname', '$lastname', '$address1', '$address2', '$city', '$state', '$zip', '$country', '$outside_us', '$phone', '$website', '$fax', '$email', '$store_type', '$comments', '$referral')";

    $cur= mysql_query( $cnx, $SQL_Exec_String );
    if (!$cur) {
        Error_handler( "Error in mysql_query( no cursor returned ) " , $cnx );
}

mysql_close($cnx);  
header("location: http://69.89.31.71/~sliquidc/verify.htm"); 

}

?>

OK, Im not sure why error_handler was working on the old server, but I changed it.

 

Here's the error Im getting now when I submit the form:

 

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/sliquidc/public_html/become.php on line 47

Invalid query:

 

$cnx = mysql_connect("localhost","user_name","user_pass");
    if (!$cnx) {
        die('Could not connect: ' . mysql_error());
    }

    $SQL_Exec_String = "Insert Into distributors (company, firstname, lastname, address1, address2, city, state, zip, country, outside_us, phone, website, fax, email, store_type, comments, referral)
            Values ('$company', '$firstname', '$lastname', '$address1', '$address2', '$city', '$state', '$zip', '$country', '$outside_us', '$phone', '$website', '$fax', '$email', '$store_type', '$comments', '$referral')";

    $cur = mysql_query($cnx, $SQL_Exec_String);
    if (!$cur) {
        die('Invalid query: ' . mysql_error());
}

mysql_close($cnx);  
header("location: http://69.89.31.71/~sliquidc/verify.htm"); 

}

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.