Author Topic: unusual behavior, and that's just me...  (Read 79 times)

lostnvegas

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
unusual behavior, and that's just me...
« on: January 26, 2012, 08:52:37 PM »
Ok I got a question. I realize it's probably not even worthy of the lower echelon in scripting but then again i'm no master. So I make a simple script that posts information into my online database from an html form. It worked beautifully. I made another script using the exact same formatting (although it has more entries than the first) and it acts like it runs perfectly but when i check the database nothing is posted, just blanks. I welcome suggestions and appreciate your consideration. I iwll post the code below. first the smaller one that worked:
PHP Code: [Select]

<?php


define
('DB_NAME''blackmail');
define('DB_USER''blackmail');
//I left out the password below
define('DB_PASSWORD''*****');
define('DB_HOST''blackmail.db.8631036.hostedresource.com');


$link mysql_connect(DB_HOSTDB_USERDB_PASSWORD);

if (!
$link)
	
{
	
die(
'could not connect: ' mysql_error());
}
$db_selected mysql_select_db(DB_NAME$link);

if (!
$db_selected) {
	
die(
'Can\'t use ' DB_NAME ' : ' mysql_error());
}


$value1 $_POST['first_name'];
$value2 $_POST['last_name'];
$value3 $_POST['email'];
$value4 $_POST['comments'];

$sql "INSERT INTO memberlist (first_name, last_name, email, comments) VALUES ('$value1', '$value2', '$value3', '$value4')";


if (!
mysql_query($sql)) {
	
die(
'Error: ' mysql_error());

}

mysql_close();

?>


and the one that doesn't work:
PHP Code: [Select]
<?php

define
('DB_NAME''black44users');
define('DB_USER''black44users');
define('DB_PASSWORD''*****');
define('DB_HOST''black44users.db.8631036.hostedresource.com');

$link mysql_connect(DB_HOSTDB_USER,DB_PASSWORD);

if (!
$link)
	
{
	
die(
'could not connect: ' mysql_error());

}
$db_selected mysql_select_db(DB_NAME$link);

if (!
$db_selected) {
	
die(
'Can\'t use ' DB_NAME ' : ' mysql_error());
}

$value1 $_POST['first_name'];
$value2 $_POST['last_name'];
$value3 $_POST['address1'];
$value4 $_POST['address2'];
$value5 $_POST['city'];
$value6 $_POST['state'];
$value7 $_POST['zip'];
$value8 $_POST['phone'];
$value9 $_POST['email'];
$value10 $_POST['email2'];
$value11 $_POST['shippingfirst'];
$value12 $_POST['shippinglast'];
$value13 $_POST['shippingaddress1'];
$value14 $_POST['shippingaddress2'];
$value15 $_POST['shippingcity'];
$value16 $_POST['shippingstate'];
$value17 $_POST['shippingzip'];
$value18 $_POST['cctype'];
$value19 $_POST['ccnumber'];
$value20 $_POST['ccexpiration'];
$value21 $_POST['cccvv'];


$sql "INSERT INTO customers (first_name, last_name, address1, address2, city, state, zip, phone, email, email2, shippingfirst, shippinglast, shippingaddress1, shippingaddress2, shippingcity, shippingstate, shippingzip, cctype, ccnumber, ccexpiration, cccvv) VALUES ('$VALUE1', '$VALUE2', '$VALUE3', '$VALUE4', '$VALUE5','$VALUE6', '$VALUE7', '$VALUE8', '$VALUE9', '$VALUE10', '$VALUE11', '$VALUE12', '$VALUE13', '$VALUE14', '$VALUE15', '$VALUE16', '$VALUE17', '$VALUE18', '$VALUE19', '$VALUE20', '$VALUE20')";

if (!
mysql_query($sql)) {
	
die(
'Error: ' mysql_error());
}
mysql_close();

?>

Sarthak Patel

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 215
  • Karma: +4/-0
    • View Profile
Re: unusual behavior, and that's just me...
« Reply #1 on: January 27, 2012, 12:24:56 AM »
Quote
hi i have checked your code your doing following mistake
you are using $VALUE1, $VALUE2, $VALUE3 ... etc in your sql which is not define by you.
you have to use $value1,$value2, $value3 ... etc in your sql.

use below code
PHP Code: [Select]

$sql 
"INSERT INTO customers (first_name, last_name, address1, address2, city, state, zip, phone, email, email2, shippingfirst, shippinglast, shippingaddress1, shippingaddress2, shippingcity, shippingstate, shippingzip, cctype, ccnumber, ccexpiration, cccvv) valueS ('$value1', '$value2', '$value3', '$value4', '$value5','$value6', '$value7', '$value8', '$value9', '$value10', '$value11', '$value12', '$value13', '$value14', '$value15', '$value16', '$value17', '$value18', '$value19', '$value20', '$value20')";


Instead of below code
PHP Code: [Select]

$sql 
"INSERT INTO customers (first_name, last_name, address1, address2, city, state, zip, phone, email, email2, shippingfirst, shippinglast, shippingaddress1, shippingaddress2, shippingcity, shippingstate, shippingzip, cctype, ccnumber, ccexpiration, cccvv) VALUES ('$VALUE1', '$VALUE2', '$VALUE3', '$VALUE4', '$VALUE5','$VALUE6', '$VALUE7', '$VALUE8', '$VALUE9', '$VALUE10', '$VALUE11', '$VALUE12', '$VALUE13', '$VALUE14', '$VALUE15', '$VALUE16', '$VALUE17', '$VALUE18', '$VALUE19', '$VALUE20', '$VALUE20')";


I hope this will helpful for you..
Reply your feedback.
~~SR~~~

lostnvegas

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: unusual behavior, and that's just me...
« Reply #2 on: January 27, 2012, 10:17:34 AM »
lol wow, what sophomoric error. That was it, works like a charm. I really appreciate your time. I think i'm going to enroll in a web development course at the community college. PhP is an incredible language and i want to learn more. Again thanks for looking it over. you da man