custy913
02-06-2008, 04:10 PM
I have this form on my site. The information supposed to be stored in database (Mysql) but nothing happened.
Can anyone please help me how to add new info in a database?
<?php
require_once('DB.php');
$db = DB::connect("mysql://xxxxxx:xxxxx@localhost/xxxxx");
if(!empty($_POST['store_name'])) {
$store_name = addslashes($_POST['store_name']);
$addr1 = addslashes($_POST['addr1']);
$addr2 = addslashes($_POST['addr2']);
$manager = addslashes($_POST['manager']);
$phone = addslashes($_POST['phone']);
$city = addslashes($_POST['city']);
$state = addslashes($_POST['state']);
$zip = addslashes($_POST['zip']);
$notes = addslashes($_POST['notes']);
$localq = $db->query("select ziplat, ziplong from zipcodes where zipcode = $zip");
$localr = $localq->fetchRow(DB_FETCHMODE_ASSOC);
$ziplat = $localr['ziplat'];
$ziplong = $localr['ziplong'];
// query the DB
$sql = "INSERT INTO stores (store_name, addr1, addr2, city, state, zip, phone, manager, notes, ziplat, ziplong) values('$store_name', '$addr1', '$addr2', '$city', '$state', '$zip', '$phone', '$manager', '$notes', $ziplat, $ziplong);";
$q = $db->query($sql);
$db->commit();
?> <font color=red size=3><b>Store<u><?= $store_name ?></u> Added.</b></font>
<?php
$disabled = 'disabled=1';
#exit;
}
?>
Can anyone please help me how to add new info in a database?
<?php
require_once('DB.php');
$db = DB::connect("mysql://xxxxxx:xxxxx@localhost/xxxxx");
if(!empty($_POST['store_name'])) {
$store_name = addslashes($_POST['store_name']);
$addr1 = addslashes($_POST['addr1']);
$addr2 = addslashes($_POST['addr2']);
$manager = addslashes($_POST['manager']);
$phone = addslashes($_POST['phone']);
$city = addslashes($_POST['city']);
$state = addslashes($_POST['state']);
$zip = addslashes($_POST['zip']);
$notes = addslashes($_POST['notes']);
$localq = $db->query("select ziplat, ziplong from zipcodes where zipcode = $zip");
$localr = $localq->fetchRow(DB_FETCHMODE_ASSOC);
$ziplat = $localr['ziplat'];
$ziplong = $localr['ziplong'];
// query the DB
$sql = "INSERT INTO stores (store_name, addr1, addr2, city, state, zip, phone, manager, notes, ziplat, ziplong) values('$store_name', '$addr1', '$addr2', '$city', '$state', '$zip', '$phone', '$manager', '$notes', $ziplat, $ziplong);";
$q = $db->query($sql);
$db->commit();
?> <font color=red size=3><b>Store<u><?= $store_name ?></u> Added.</b></font>
<?php
$disabled = 'disabled=1';
#exit;
}
?>