PHP - Running A Database Insert On Image Click
Hi,
I need to run a database insert when somebody clicks on an image. Should I use a php function ? or javascript ? or something else ? Many thanks in advance, Scott. Similar TutorialsI have a php script that I've been running that seems to have been working but now I'm wondering if some of my logic is potentially off. I select records from a db table within a date range which I put into an array called ```$validCount``` If that array is not empty, that means I have valid records to update with my values, and if it's empty I just insert. The trick with the insert is that if the ```STORES``` is less than the ```Quantity``` then it only inserts as many as the ```STORES``` otherwise it inserts as many as ```Quantity```. So if a record being inserted with had Stores: 14 Quantity:12
Then it would only insert 12 records but if it had It would only insert 1 record. In short, for each customer I should only ever have as many valid records (within a valid date range) as they have stores. If they have 20 stores, I can have 1 or 2 records but should never have 30. It seems like updating works fine but I'm not sure if it's updating the proper records, though it seems like in some instances it's just inserting too many and not accounting for past updated records. This is the logic I have been working with:
if(!empty($validCount)){ for($i=0; $i<$row2['QUANTITY']; $i++){ try{ $updateRslt = $update->execute($updateParams); }catch(PDOException $ex){ $out[] = $failedUpdate; } } }else{ if($row2["QUANTITY"] >= $row2["STORES"]){ for($i=0; $i<$row2["STORES"]; $i++){ try{ $insertRslt = $insert->execute($insertParams); }catch(PDOException $ex){ $out[] = $failedInsertStore; } } }elseif($row2["QUANTITY"] < $row2["STORES"]){ for($i=0; $i<$row2["QUANTITY"]; $i++){ try{ $insertRslt = $insert->execute($insertParams); }catch(PDOException $ex){ $out[] = $failedInsertQuantity; } } } }
Let's say customer 123 bought 4 of product A and they have 10 locations
customerNumber | product | category | startDate | expireDate | stores Because they purchased less than their store count, I insert 4 records. Now if my ```$validCheck``` query selects all 4 of those records (since they fall in a valid date range) and my loop sees that the array isn't empty, it knows it needs to update those or insert. Let's say they bought 15 this time. Then I would need to insert 6 records, and then update the expiration date of the other 9 records.
customerNumber | product | category | startDate | expireDate | stores There can only ever be a maximum of 10 (store count) records for that customer and product within the valid date range. As soon as the row count for that customer/product reaches the equivalent of stores, it needs to now go through and update equal to the quantity so now I'm running this but it's not running and no errors, but it just returns back to the command line $total = $row2['QUANTITY'] + $validCheck; if ($total < $row2['STORES']) { $insert_count = $row2['QUANTITY']; $update_count = 0; } else { $insert_count = $row2['STORES'] - $validCheck; // insert enough to fill all stores $update_count = ($total - $insert_count); // update remainder } for($i=0; $i<$row2['QUANTITY']; $i++){ try{ $updateRslt = $update->execute($updateParams); }catch(PDOException $ex){ $failedUpdate = "UPDATE_FAILED"; print_r($failedUpdate); $out[] = $failedUpdate; } } for($i=0; $i<$insert_count; $i++){ try{ $insertRslt = $insert->execute($insertParams); }catch(PDOException $ex){ $failedInsertStore = "INSERT_STORE_FAILED!!!: " . $ex->getMessage(); print_r($failedInsertStore); $out[] = $failedInsertStore; } }```
I am trying to create a calendar of Events for my company's website. When I search for this type of calendar, I can find code that runs the calendar from one Events table. However, we could have an Event that has multiple performances. (For example, Lily Tomlin could be performing at the Atwood Concert Hall in Anchorage on 09/09/11 and at the Vagabond Blues in Palmer on 09/10/11.) So we have two tables to draw the information from: Events and Performance I can successfully create a MySQL query (see below) with PHP coding that will make a listing (as demostrated on our website http://www.centertix.net/). Code: [Select] "SELECT Events.PublishDate, Events.EventOnSaleDate, Events.BldgContractDate, Events.SetUpComplete, Events.EventTitle, Performance.PerfID, Performance.startDateTime, Performance.endDateTime, Performance.PerfType, venues.VenueName, venues.VenueCode FROM (Performance RIGHT JOIN Events ON Performance.EventID = Events.EventID) LEFT JOIN venues ON Performance.VenueCode = venues.VenueCode WHERE Events.BldgContractDate Is Not Null AND Events.SetUpComplete Is Not Null AND Performance.PerfType='Public Event'"However, I'm not advanced enough to create the if-clause or while-loop to check to see if the Performance.startDate = the calendar's date and then place the info into the appropriate calendar grid box. I think have determined where it should be place in my PHP code, but need help getting the calendar to work. Here's the code where I think it should go: Code: [Select] for($list_day = 1; $list_day <= $days_in_month; $list_day++): if(($list_day == date("j",mktime(0,0,0,$this->month))) && (date("F") == date("F",mktime(0,0,0,$this->month))) && (date("Y") == date("Y",mktime(0,0,0,$this->month,$list_day,$this->year)))) { $this->calendar.= '<td class="'. $this->style .'-current-day">'; } else { if(($running_day == "0") || ($running_day == "6")) { $this->calendar.= '<td class="'. $this->style .'-weekend-day">'; } else { $this->calendar.= '<td class="'. $this->style .'-day">'; } } /* add in the day number */ $this->calendar.= '<div class="'. $this->style .'-day-number">'.$list_day.'</div>'; /** QUERY THE DATABASE FOR AN ENTRY FOR THIS DAY !! IF MATCHES FOUND, PRINT THEM !! **/ $this->calendar.= '<div class="'. $this->style .'-text"><a href="">PERFORMANCE INFO</a></div>'. "\n"; /** QUERY THE DATABASE FOR AN ENTRY FOR THIS DAY !! IF NO MATCHES FOUND, PRINT NOTHING !! **/ $this->calendar.= str_repeat('<p> </p>',2); $this->calendar.= '</td>'; if($running_day == 6): $this->calendar.= '</tr>'; if(($day_counter+1) != $days_in_month): $this->calendar.= '<tr class="'. $this->style .'-row">'; endif; $running_day = -1; $days_in_this_week = 0; endif; $days_in_this_week++; $running_day++; $day_counter++; endfor; Please help me plug the calendar in with the appropriate events! If you would like to see how far I have gotten, you can check out this link: http://www.myalaskacenter.com/calendars/calendarSample2.php I have this code <?php session_start(); $error = 0; $valError = ""; // Form Page Submit Security $domain_list = explode(',',""); $ip_limit = 0; $active = 1; $active_message = <<<EOT Sorry, this form is currently disabled. EOT; include_once 'security/secure_submit.php'; include_once 'lib/utility.php'; $_SESSION["entry_key"] = isset($_SESSION["entry_key"]) ? $_SESSION["entry_key"] : md5(time() + rand(10000, 1000000)); // cname - text if(isset($_POST['cname']) && $_POST['cname'] != '') { $cname = isset($_POST['cname']) ? $_POST['cname'] : ''; $_SESSION['cname'] = $cname; } else { $error = '1'; $valError .= 'Company Name : is required.<br/>'; } if(isset($_SESSION['cname_is'])) { $_SESSION['cname_is'] = 0; } $cname = isset($_SESSION['cname']) ? $_SESSION['cname'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['cname'] = $cname; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['Company Name :'] = $cname; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['cname'] = "Company Name :"; // dname - text if(isset($_POST['dname']) && $_POST['dname'] != '') { $dname = isset($_POST['dname']) ? $_POST['dname'] : ''; $_SESSION['dname'] = $dname; } else { $error = '1'; $valError .= 'Domain Name : is required.<br/>'; } if(isset($_SESSION['dname_is'])) { $_SESSION['dname_is'] = 0; } $dname = isset($_SESSION['dname']) ? $_SESSION['dname'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['dname'] = $dname; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['Domain Name :'] = $dname; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['dname'] = "Domain Name :"; // ipaddress - text if(isset($_POST['ipaddress']) && $_POST['ipaddress'] != '') { $ipaddress = isset($_POST['ipaddress']) ? $_POST['ipaddress'] : ''; $_SESSION['ipaddress'] = $ipaddress; } else { $error = '1'; $valError .= 'IP Address : is required.<br/>'; } if(isset($_SESSION['ipaddress_is'])) { $_SESSION['ipaddress_is'] = 0; } $ipaddress = isset($_SESSION['ipaddress']) ? $_SESSION['ipaddress'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['ipaddress'] = $ipaddress; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['IP Address :'] = $ipaddress; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['ipaddress'] = "IP Address :"; // ns1 - text if(isset($_POST['ns1']) && $_POST['ns1'] != '') { $ns1 = isset($_POST['ns1']) ? $_POST['ns1'] : ''; $_SESSION['ns1'] = $ns1; } else { $error = '1'; $valError .= 'Name Server 1 : is required.<br/>'; } if(isset($_SESSION['ns1_is'])) { $_SESSION['ns1_is'] = 0; } $ns1 = isset($_SESSION['ns1']) ? $_SESSION['ns1'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['ns1'] = $ns1; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['Name Server 1 :'] = $ns1; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['ns1'] = "Name Server 1 :"; // ns2 - text if(isset($_POST['ns2']) && $_POST['ns2'] != '') { $ns2 = isset($_POST['ns2']) ? $_POST['ns2'] : ''; $_SESSION['ns2'] = $ns2; } else { $error = '1'; $valError .= 'Name Server 2 : is required.<br/>'; } if(isset($_SESSION['ns2_is'])) { $_SESSION['ns2_is'] = 0; } $ns2 = isset($_SESSION['ns2']) ? $_SESSION['ns2'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['ns2'] = $ns2; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['Name Server 2 :'] = $ns2; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['ns2'] = "Name Server 2 :"; // ftpserver - text if(isset($_POST['ftpserver']) && $_POST['ftpserver'] != '') { $ftpserver = isset($_POST['ftpserver']) ? $_POST['ftpserver'] : ''; $_SESSION['ftpserver'] = $ftpserver; } else { $error = '1'; $valError .= 'FTP Server Address : is required.<br/>'; } if(isset($_SESSION['ftpserver_is'])) { $_SESSION['ftpserver_is'] = 0; } $ftpserver = isset($_SESSION['ftpserver']) ? $_SESSION['ftpserver'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['ftpserver'] = $ftpserver; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['FTP Server Address :'] = $ftpserver; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['ftpserver'] = "FTP Server Address :"; // ftpuname - text if(isset($_POST['ftpuname']) && $_POST['ftpuname'] != '') { $ftpuname = isset($_POST['ftpuname']) ? $_POST['ftpuname'] : ''; $_SESSION['ftpuname'] = $ftpuname; } else { $error = '1'; $valError .= 'FTP Username : is required.<br/>'; } if(isset($_SESSION['ftpuname_is'])) { $_SESSION['ftpuname_is'] = 0; } $ftpuname = isset($_SESSION['ftpuname']) ? $_SESSION['ftpuname'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['ftpuname'] = $ftpuname; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['FTP Username :'] = $ftpuname; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['ftpuname'] = "FTP Username :"; // ftppword - text if(isset($_POST['ftppword']) && $_POST['ftppword'] != '') { $ftppword = isset($_POST['ftppword']) ? $_POST['ftppword'] : ''; $_SESSION['ftppword'] = $ftppword; } else { $error = '1'; $valError .= 'FTP Password : is required.<br/>'; } if(isset($_SESSION['ftppword_is'])) { $_SESSION['ftppword_is'] = 0; } $ftppword = isset($_SESSION['ftppword']) ? $_SESSION['ftppword'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['ftppword'] = $ftppword; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['FTP Password :'] = $ftppword; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['ftppword'] = "FTP Password :"; // pop - text if(isset($_POST['pop']) && $_POST['pop'] != '') { $pop = isset($_POST['pop']) ? $_POST['pop'] : ''; $_SESSION['pop'] = $pop; } else { $error = '1'; $valError .= 'POP : is required.<br/>'; } if(isset($_SESSION['pop_is'])) { $_SESSION['pop_is'] = 0; } $pop = isset($_SESSION['pop']) ? $_SESSION['pop'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['pop'] = $pop; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['POP :'] = $pop; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['pop'] = "POP :"; // smtp - text if(isset($_POST['smtp']) && $_POST['smtp'] != '') { $smtp = isset($_POST['smtp']) ? $_POST['smtp'] : ''; $_SESSION['smtp'] = $smtp; } else { $error = '1'; $valError .= 'SMTP : is required.<br/>'; } if(isset($_SESSION['smtp_is'])) { $_SESSION['smtp_is'] = 0; } $smtp = isset($_SESSION['smtp']) ? $_SESSION['smtp'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['smtp'] = $smtp; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['SMTP :'] = $smtp; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['smtp'] = "SMTP :"; // webmailaddy - text if(isset($_POST['webmailaddy']) && $_POST['webmailaddy'] != '') { $webmailaddy = isset($_POST['webmailaddy']) ? $_POST['webmailaddy'] : ''; $_SESSION['webmailaddy'] = $webmailaddy; } else { $error = '1'; $valError .= 'Webmail Address : is required.<br/>'; } if(isset($_SESSION['webmailaddy_is'])) { $_SESSION['webmailaddy_is'] = 0; } $webmailaddy = isset($_SESSION['webmailaddy']) ? $_SESSION['webmailaddy'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['webmailaddy'] = $webmailaddy; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['Webmail Address :'] = $webmailaddy; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['webmailaddy'] = "Webmail Address :"; // adiskspace - text if(isset($_POST['adiskspace']) && $_POST['adiskspace'] != '') { $adiskspace = isset($_POST['adiskspace']) ? $_POST['adiskspace'] : ''; $_SESSION['adiskspace'] = $adiskspace; } else { $error = '1'; $valError .= 'Allocated Disk Space : is required.<br/>'; } if(isset($_SESSION['adiskspace_is'])) { $_SESSION['adiskspace_is'] = 0; } $adiskspace = isset($_SESSION['adiskspace']) ? $_SESSION['adiskspace'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['adiskspace'] = $adiskspace; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['Allocated Disk Space :'] = $adiskspace; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['adiskspace'] = "Allocated Disk Space :"; // ambw - text if(isset($_POST['ambw']) && $_POST['ambw'] != '') { $ambw = isset($_POST['ambw']) ? $_POST['ambw'] : ''; $_SESSION['ambw'] = $ambw; } else { $error = '1'; $valError .= 'Allocated Monthly Bandwidth : is required.<br/>'; } if(isset($_SESSION['ambw_is'])) { $_SESSION['ambw_is'] = 0; } $ambw = isset($_SESSION['ambw']) ? $_SESSION['ambw'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['ambw'] = $ambw; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['Allocated Monthly Bandwidth :'] = $ambw; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['ambw'] = "Allocated Monthly Bandwidth :"; // amboxes - text if(isset($_POST['amboxes']) && $_POST['amboxes'] != '') { $amboxes = isset($_POST['amboxes']) ? $_POST['amboxes'] : ''; $_SESSION['amboxes'] = $amboxes; } else { $error = '1'; $valError .= 'Allocated MailBoxes : is required.<br/>'; } if(isset($_SESSION['amboxes_is'])) { $_SESSION['amboxes_is'] = 0; } $amboxes = isset($_SESSION['amboxes']) ? $_SESSION['amboxes'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['amboxes'] = $amboxes; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['Allocated MailBoxes :'] = $amboxes; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['amboxes'] = "Allocated MailBoxes :"; // amboxquota - text if(isset($_POST['amboxquota']) && $_POST['amboxquota'] != '') { $amboxquota = isset($_POST['amboxquota']) ? $_POST['amboxquota'] : ''; $_SESSION['amboxquota'] = $amboxquota; } else { $error = '1'; $valError .= 'Allocated MailBox Quoted : is required.<br/>'; } if(isset($_SESSION['amboxquota_is'])) { $_SESSION['amboxquota_is'] = 0; } $amboxquota = isset($_SESSION['amboxquota']) ? $_SESSION['amboxquota'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['amboxquota'] = $amboxquota; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['Allocated MailBox Quoted :'] = $amboxquota; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['amboxquota'] = "Allocated MailBox Quoted :"; // adbase - text if(isset($_POST['adbase']) && $_POST['adbase'] != '') { $adbase = isset($_POST['adbase']) ? $_POST['adbase'] : ''; $_SESSION['adbase'] = $adbase; } else { $error = '1'; $valError .= 'Allocated Databases : is required.<br/>'; } if(isset($_SESSION['adbase_is'])) { $_SESSION['adbase_is'] = 0; } $adbase = isset($_SESSION['adbase']) ? $_SESSION['adbase'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['adbase'] = $adbase; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['Allocated Databases :'] = $adbase; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['adbase'] = "Allocated Databases :"; // exp - text if(isset($_POST['exp']) && $_POST['exp'] != '') { $exp = isset($_POST['exp']) ? $_POST['exp'] : ''; $_SESSION['exp'] = $exp; } else { $error = '1'; $valError .= 'Expires On : is required.<br/>'; } if(isset($_SESSION['exp_is'])) { $_SESSION['exp_is'] = 0; } $exp = isset($_SESSION['exp']) ? $_SESSION['exp'] : ''; $_SESSION['qs']["{$_SESSION['entry_key']}"]['exp'] = $exp; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['Expires On :'] = $exp; $_SESSION['qs-label']["{$_SESSION['entry_key']}"]['exp'] = "Expires On :"; if($error){ if(isset($_SESSION['pages']['page5.php'])) { unset($_SESSION['pages']['page5.php']); } $_SESSION["e_message"] = $valError; header("Location: index.php?section-hostingedit"); } else { $_SESSION['pages']['page5.php'] = 'pass'; // custom route code //DATABASE INTERACTION //Setup database connection $dbserver = "localhost"; $dbuname = "vri_dev"; $dbpword = "emit098nice054" //Connect to DB Server $con = mysql_connect($dbserver, $dbuname, $dbpword); if(!$con){ die('Could not connect to the database server :' . mysql_error()); echo"1"; }else{ echo"1.2"; //Select Database mysql_select_db("vri_inkcontrol", $con); //Get idcname $q = "SELECT idcname FROM `tbl_hosting_cname` WHERE cname='$_POST['cname']' AND dname='$_POST['dname']'"; $r = mysql_query($q); //Put idcname query into an array $r_array = mysql_fetch_assoc($r); //Store idcname result from previouse query $idcname = $r_array['idcname']; //trap duplicate records //If the number of rows returned by above query is not greater then we if(mysql_num_rows($r) == 0){ echo"2"; //Insert idcname in `tbl_hosting_cname` since id doesn't exist $q = "INSERT INTO `tbl_hosting_cname` SET cname='$_POST['cname']"; mysql_query($q); //grab the cname id in `tbl_hosting_cname` $q = "SELECT idcname FROM `tbl_hosting_cname WHERE cname='$_POST['cname']'"; $r = mysql_query($q); //now we must grab the id cname from array $q = "SELECT idcname FROM `tbl_hosting_cname` WHERE cname='$_POST['cname']'"; $r = mysql_query($q); $row = mysql_fetch_assoc($r); $idcname = $row['idcname']; $r = mysql_query("SELECT * FROM `tbl_hosting_domain` WHERE cname='$idcname' AND dname='$_POST['dname']'"); if(mysql_num_rows($r) !== 1){ echo"3"; $q = "INSERT INTO `tbl_hosting_domain` (idcname, dname, ip, ns1, ns2, ftpaddress, ftpuname, ftppword, pop, smtp, webmailaddress, diskspace, bandwidth, nummailboxes, mailboxquota, numdatabases, exp) VALUES ('$idcname', '$_POST['dname']', '$_POST['ip']', '$_POST['ns1']', '$_POST['ns2']', '$_POST['ftpserver']', '$_POST['ftpuname']', '$_POST['ftppword']', '$_POST['pop']', '$_POST['smtp']', '$_POST['webmailaddy']', '$_POST['adiskspace']', '$_POST['ambw']', '$_POST['amboxes']', '$_POST['amboxesquota']', '$_POST['adbases']', '$_POST['exp']')"; mysql_query($q); $route = "Location: index.php?section=newaddyes"; }elseif(mysql_num_rows($r) == 1){ echo"3.2"; $q = "SELECT idcname FROM `tbl_hosting_cname` WHERE cname='$_POST['cname']'"; $r = mysql_query($q); $row = mysql_fetch_assoc($r); $idcname = $row['idcname']; $q = "UPDATE `tbl_hosting_domain` SET ( ip = '$_POST['ip']', ns1 = '$_POST['ns1']', ns2 = '$_POST['ns2']', ftpaddress = '$_POST['ftpserver']', ftpuname = '$_POST['ftpuname']', ftppword = '$_POST['ftppword']', pop = '$_POST['pop']', smtp = '$_POST['smtp']', webmailaddress = '$_POST['webmailaddy']', diskspace = '$_POST['adiskspace']', bandwidth = '$_POST['ambw']', nummailboxes = '$_POST['amboxes']', mailboxquota = '$_POST['amboxesquota']', numdatabases = '$_POST['adbases']', exp = '$_POST['exp']' WHERE cname='$idcname'"; $route = "Location: index.php?section=newaddyes"; }else{ echo"lsr1" $route = "Location: index.php?section=newaddno"; } // conditional route code // default action header($route); } ?> the code that will not run is // custom route code //DATABASE INTERACTION //Setup database connection $dbserver = "localhost"; $dbuname = "vri_dev"; $dbpword = "emit098nice054" //Connect to DB Server $con = mysql_connect($dbserver, $dbuname, $dbpword); if(!$con){ die('Could not connect to the database server :' . mysql_error()); echo"1"; }else{ echo"1.2"; //Select Database mysql_select_db("vri_inkcontrol", $con); //Get idcname $q = "SELECT idcname FROM `tbl_hosting_cname` WHERE cname='$_POST['cname']' AND dname='$_POST['dname']'"; $r = mysql_query($q); //Put idcname query into an array $r_array = mysql_fetch_assoc($r); //Store idcname result from previouse query $idcname = $r_array['idcname']; //trap duplicate records //If the number of rows returned by above query is not greater then we if(mysql_num_rows($r) == 0){ echo"2"; //Insert idcname in `tbl_hosting_cname` since id doesn't exist $q = "INSERT INTO `tbl_hosting_cname` SET cname='$_POST['cname']"; mysql_query($q); //grab the cname id in `tbl_hosting_cname` $q = "SELECT idcname FROM `tbl_hosting_cname WHERE cname='$_POST['cname']'"; $r = mysql_query($q); //now we must grab the id cname from array $q = "SELECT idcname FROM `tbl_hosting_cname` WHERE cname='$_POST['cname']'"; $r = mysql_query($q); $row = mysql_fetch_assoc($r); $idcname = $row['idcname']; $r = mysql_query("SELECT * FROM `tbl_hosting_domain` WHERE cname='$idcname' AND dname='$_POST['dname']'"); if(mysql_num_rows($r) !== 1){ echo"3"; $q = "INSERT INTO `tbl_hosting_domain` (idcname, dname, ip, ns1, ns2, ftpaddress, ftpuname, ftppword, pop, smtp, webmailaddress, diskspace, bandwidth, nummailboxes, mailboxquota, numdatabases, exp) VALUES ('$idcname', '$_POST['dname']', '$_POST['ip']', '$_POST['ns1']', '$_POST['ns2']', '$_POST['ftpserver']', '$_POST['ftpuname']', '$_POST['ftppword']', '$_POST['pop']', '$_POST['smtp']', '$_POST['webmailaddy']', '$_POST['adiskspace']', '$_POST['ambw']', '$_POST['amboxes']', '$_POST['amboxesquota']', '$_POST['adbases']', '$_POST['exp']')"; mysql_query($q); $route = "Location: index.php?section=newaddyes"; }elseif(mysql_num_rows($r) == 1){ echo"3.2"; $q = "SELECT idcname FROM `tbl_hosting_cname` WHERE cname='$_POST['cname']'"; $r = mysql_query($q); $row = mysql_fetch_assoc($r); $idcname = $row['idcname']; $q = "UPDATE `tbl_hosting_domain` SET ( ip = '$_POST['ip']', ns1 = '$_POST['ns1']', ns2 = '$_POST['ns2']', ftpaddress = '$_POST['ftpserver']', ftpuname = '$_POST['ftpuname']', ftppword = '$_POST['ftppword']', pop = '$_POST['pop']', smtp = '$_POST['smtp']', webmailaddress = '$_POST['webmailaddy']', diskspace = '$_POST['adiskspace']', bandwidth = '$_POST['ambw']', nummailboxes = '$_POST['amboxes']', mailboxquota = '$_POST['amboxesquota']', numdatabases = '$_POST['adbases']', exp = '$_POST['exp']' WHERE cname='$idcname'"; $route = "Location: index.php?section=newaddyes"; }else{ echo"lsr1" $route = "Location: index.php?section=newaddno"; } If everything on the form passes it should process the data into the database. However it is not. I placed echo statements to see where it was getting to in the database interaction portion of the code but no dice. Any help is apreciated, thanks in advance. hello I want query from one table and insert in another table on another domain . each database on one domain name. for example http://www.site.com $con1 and http://www.site1.com $con. can anyone help me? my code is : <?php $dbuser1 = "insert in this database"; $dbpass1 = "insert in this database"; $dbhost1 = "localhost"; $dbname1 = "insert in this database"; // Connecting, selecting database $con1 = mysql_connect($dbhost1, $dbuser1, $dbpass1) or die('Could not connect: ' . mysql_error()); mysql_select_db($dbname1) or die('Could not select database'); $dbuser = "query from this database"; $dbpass = "query from this database"; $dbhost = "localhost"; $dbname = "query from this database"; // Connecting, selecting database $con = mysql_connect($dbhost, $dbuser, $dbpass) or die('Could not connect: ' . mysql_error()); mysql_select_db($dbname) or die('Could not select database'); //query from database $query = mysql_query("SELECT * FROM `second_content` WHERE CHANGED =0 limit 0,1"); while($row=mysql_fetch_array($query)){ $result=$row[0]; $text=$row[1]."</br>Size:(".$row[4].")"; $alias=$row[2]; $link = '<a target="_blank" href='.$row[3].'>Download</a>'; echo $result; } //insert into database mysql_query("SET NAMES 'utf8'", $con1); $query3= " INSERT INTO `jos_content` (`id`, `title`, `alias`, `) VALUES (NULL, '".$result."', '".$alias."', '')"; if (!mysql_query($query3,$con1)) { die('Error: text add' . mysql_error()); } mysql_close($con); mysql_close($con1); ?> Ok, I have a graphing class that I built to build simple bar/line graphs for work. I have a side project I'm working on that is a little bigger in terms of data. Usually I do months or weeks. But I have some arrays with about 1000 data sets.
And when I create the image it stops at a certain point and doesn't even draw the X-Axis (One of the last procedures in my code).
And I know there is an issue, because if I Limit the query to 100 results, the graph will come out fine. If I limit it to 200 results the plotted line will show but the X-Axis will be cut of. If I put it to 300 results the plotted line will stop towards 2/3rds the way through the graph.
So I know the code is working when I reduce the results. I check the image info and it's only 3.25kb in size. Not sure what's going on here. I tried googling it but really didn't come up with any solid answers like most google searches.
If anyone has a clue why this is happening, please let me know.
Thanks a lot in advance.
And what's weird is if I add Zebra gridlines to it, on the colored zebra background, I can see a white line that represents the data. It's almost like the ink runs out, lol.
Edited by akphidelt2007, 26 June 2014 - 07:31 PM.
Hi guys, Thanks
if(isset($_POST['send'])){ $category = $_POST['category']; $item_type = $_POST['item_type']; $item_size = $_POST['item_size']; $product_name = $_POST['product_name']; $item_qty = $_POST['item_qty']; $price = $_POST['price']; $total_price = $_POST['total_price']; $item_price = $_POST['item_price']; $sql = " INSERT INTO shopping( trans_ref, category, product_name, item_type, item_size, item_qty, item_price, price, date ) VALUES( :trans_ref, :category, :product_name, :item_type, :item_size, :item_qty, :item_price, :price, NOW() ) "; $stmt = $pdo->prepare($sql); $stmt->execute(array( ':trans_ref' => $_SESSION['trans_ref'], ':category' => $category, ':product_name' => $product_name, ':item_type' => $item_type, ':item_size' => $item_size, ':item_qty' => $item_qty, ':item_price' => $item_price, ':price' => $price )); if ( $stmt->rowCount()){ echo '<div class="alert bg-success text-center">SHOPPING COMPLETED</div>'; }else{ echo '<div class="alert bg-danger text-center">SHOPPING NOT COMPLETED. A PROBLE OCCURED</div>'; } }
I've begun to play around with object oriented php and I was wondering how I would go about writing a method that inserts values into a table.
I have a class, called queries, and I made this very simple function:
class queries { public function insert($table, $field, $value){ global $dbh; $stmt = $dbh->prepare("INSERT INTO $table ($field) VALUES (:value)"); $stmt->bindParam(":value", $value); $stmt->execute(); } } $queries = new queries(); how do I make the $image piece so that it inserts "images/$image.php" into the database? VALUES('$name', '$id', '$image','$event')"; Hi... Got a slight problem with my code, it keeps telling me that there is an error in my syntax, yet I have used the same code before perfectly, and for the life of me cannot see the problem? ....any ideas? <?php if (!isset($_SESSION)) { session_start(); } // Connects to your Database mysql_connect("localhost", "justair1_mick", "guru1969") or die(mysql_error()) ; mysql_select_db("justair1_justair") or die(mysql_error()) ; $filename = ($_FILES['image']['name']); $group = $_POST['group']; $make_model = $_POST['make_model']; $seats = $_POST['seats']; $transmission = $_POST['transmission']; $doors = $_POST['doors']; $lg_bags = $_POST['lg_bags']; $sm_bags = $_POST['sm_bags']; $aircon = $_POST['aircon']; $day1 = $_POST['1_day']; $days2 = $_POST['2_days']; $days3_6 = $_POST['3_6days']; $week = $_POST['week']; $days8_13 = $_POST['8_13days']; $days14 = $_POST['14_days']; if(isset($filename)){ //This is the directory where images will be saved $target = "images/"; $target2 = $target . basename( $_FILES['image']['name']); //This gets all the other information from the form $fileA=($_FILES['image']['name']); } $updateSQL = "INSERT INTO car_groups (group, make_model, transmission, seats, doors, lg_bags, sm_bags, aircon, image) VALUES ('$group', '$make_model', '$transmission', '$seats', '$doors', '$lg_bags', '$sm_bags', '$aircon', '$filename')"; mysql_query($updateSQL) or die(mysql_error()); //Writes the photo to the server move_uploaded_file($_FILES['image']['tmp_name'], $target2); header ("Location: carhireInsert.php"); ?> It keeps telling me... "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group, make_model, transmission, seats, doors, lg_bags, sm_bags, aircon, image) ' at line 1" ..? Really stuck on this one... Any help would be apreciated.. thanks.. Mick. Hi I have started my error checking for my form. I am understand that the date must be inserted in the format yyyy/mm/dd but on my form i need it to be inserted in the format dd/mm/yyyy. I have wrote some code but have only been doing php about a week properly so I can't see what my error is. Whenever I try to insert the date, the form its self does not error but if i check the database the date is simply 0000/00/00. Can anyone help? if(isset($_POST['submit'])) { $first_name = mysql_real_escape_string($_POST['first_name']); $last_name = mysql_real_escape_string($_POST['last_name']); $DOB = mysql_real_escape_string($_POST['DOB']); $sex = mysql_real_escape_string($_POST['sex']); $email = mysql_real_escape_string($_POST['email']); $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $agree = mysql_real_escape_string($_POST['agreed']); $creation_date = mysql_real_escape_string($_POST['creation_date']); $user_type = mysql_real_escape_string($_POST['member_type']); $access_level = mysql_real_escape_string($_POST['access_level']); $validation = mysql_real_escape_string($_POST['validation_id']); $club_user = mysql_real_escape_string($_POST['user_type']); $date_check = "/^([0-9]{2})/([0-9]{2})/([0-9]{4})$/"; if($first_name == "") { $message = "Please enter a first name"; $success = 0; } else if($last_name == "") { $message = "Please enter a surname"; $success = 0; } else if($DOB =="") { $message = "Please enter your date of birth."; $success = 0; } else if(!(preg_match("/^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/", $DOB))) { $message = "Please enter your birthday in the format dd/mm/yyyy"; $success = 0; } else if($email =="") { $message = "Please enter a correct email."; $success = 0; } else if($username =="") { $message = "Please enter a username."; $success = 0; } else if($password =="") { $message = "Please enter a password greater than 6 characters long."; $success = 0; } else { $DOB = $explode[2]."-".$explode[1]."-".$explode[0]; $password_md5 = md5($password); $insert_member= "INSERT INTO Members (`first_name`,`last_name`,`DOB`,`sex`,`email`,`username`,`password`,`agree`,`creation_date`,`usertype`,`access_level`,`validationID`) VALUES ('".$first_name."','".$last_name."','".$DOB."','".$sex."','".$email."','".$username."','".$password_md5."','".$agree."','".$creation_date."','".$user_type."','".$access_level."', '".$validation."')"; $insert_member_now= mysql_query($insert_member) or die(mysql_error()); $url = "thankyou.php?name=".$_POST['username']; header('Location: '.$url); Hi guys, Is it possible to insert into two tables in a database? Thanks I created this database Code: [Select] <?php $mysqli = mysqli_connect('localhost', 'admin', 'jce123', 'php_class'); if(mysqli_connect_errno()) { printf("connection failed: %s\n", mysqli_connect_error()); exit(); }else{ $q = mysqli_query($mysqli, "DROP TABLE IF EXISTS airline_survey"); if($q){echo "deleted the table airline_survey....<br>";} else{echo "damm... ".mysqli_error($mysqli);} $sql = "CREATE TABLE airline_survey ( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, staff CHAR(10) NOT NULL, luggage CHAR(10) NOT NULL, seating CHAR(10) NOT NULL, clean CHAR(10) NOT NULL, noise CHAR(10) NOT NULL )"; $res = mysqli_query($mysqli, $sql); if($res === TRUE) { echo "table created"; } else { printf("Could not create table: %s\n", mysqli_error($mysqli)); } mysqli_close($mysqli); } ?> When I look at it it looks fine. I have a form that sends data to this script: Code: [Select] <?php $con = mysql_connect('localhost', 'admin', 'abc123'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("php_class", $con); foreach ($_POST as $key => $value) { $staff = ""; $luggage = ""; $seating = ""; $clean = ""; $noise = ""; switch($key){ case "staff": $staff = $value; break; case "luggage": $luggage = $value; break; case "seating": $seating = $value; break; case "clean": $clean = $value; break; case "noise": $noise = $value; break; default: echo "we must be in the twilight zone"; } echo $staff."<br>"; [color=red] mysql_query("INSERT INTO airline_survey (staff, luggage, seating, clean, noise) VALUES ($staff, $luggage, $seating, $clean, $noise)");[/color] } ?> as you can see right before the insert query I test one of the variables to see if it has the string I'm expecting and it does. The problem is the script runs without giving me an error message but the data never gets inserted into the table. I am having an issue trying to get products that I am entering through my admin panel to go into my database. I am thinking that the programmer of the script might have forgot some code possibly, but everything else does get inserted into the database regarding categories, manufactures etc. Here is the insert product php script. My db and functions are set to go to my database with website name/password etc.
<?php if(!isset($_SESSION['customer_email'])){ echo "<script> window.open('../checkout.php','_self'); </script>"; } $customer_email = $_SESSION['customer_email']; $get_customer = "select * from customers where customer_email='$customer_email'"; $run_customer = mysqli_query($con,$get_customer); $row_customer = mysqli_fetch_array($run_customer); $customer_id = $row_customer['customer_id']; $select_general_settings = "select * from general_settings"; $run_general_settings = mysqli_query($con,$select_general_settings); $row_general_settings = mysqli_fetch_array($run_general_settings); $product_vendor_status = $row_general_settings["new_product_status"]; ?> <script src="//cdn.tinymce.com/4/tinymce.min.js"></script> <script>tinymce.init({ selector:'#product_desc,#product_features' });</script> <div class="row"><!-- 2 row Starts --> <div class="col-lg-12"><!-- col-lg-12 Starts --> <div class="panel panel-default"><!-- panel panel-default Starts --> <div class="panel-heading"><!-- panel-heading Starts --> <h3 class="panel-title"> <i class="fa fa-money fa-fw"></i> Insert Product </h3> </div><!-- panel-heading Ends --> <div class="panel-body"><!-- panel-body Starts --> <form id="insert_product_form" method="post" enctype="multipart/form-data"><!-- form-horizontal Starts --> <div class="row"><!-- 2 row Starts --> <div class="col-md-9"><!-- col-md-9 Starts --> <div class="form-group" ><!-- form-group Starts --> <label> Product Title </label> <input type="text" name="product_title" class="form-control" required > </div><!-- form-group Ends --> <div class="form-group" ><!-- form-group Starts --> <label> Product Seo Description </label> <textarea name="product_seo_desc" class="form-control" maxlength="230" placeholder="Most search engines use a maximum of 230 chars for the description."></textarea> </div><!-- form-group Ends --> <div class="form-group" ><!-- form-group Starts --> <label> Product Url </label> <input type="text" name="product_url" class="form-control" required > <br> <p style="font-size:15px; font-weight:bold;"> Product Url Example : navy-blue-t-shirt </p> </div><!-- form-group Ends --> <div class="form-group"><!-- form-group Starts --> <label> Product Tabs </label> <ul class="nav nav-tabs"><!-- nav nav-tabs Starts --> <li class="active"> <a data-toggle="tab" href="#description"> Product Description </a> </li> <li> <a data-toggle="tab" href="#features"> Product Features </a> </li> <li> <a data-toggle="tab" href="#video"> Sounds And Videos </a> </li> </ul><!-- nav nav-tabs Ends --> <div class="tab-content"><!-- tab-content Starts --> <div id="description" class="tab-pane fade in active"><!-- description tab-pane fade in active Starts --> <br> <textarea name="product_desc" class="form-control" rows="15" id="product_desc"></textarea> </div><!-- description tab-pane fade in active Ends --> <div id="features" class="tab-pane fade in"><!-- features tab-pane fade in Starts --> <br> <textarea name="product_features" class="form-control" rows="15" id="product_features"></textarea> </div><!-- features tab-pane fade in Ends --> <div id="video" class="tab-pane fade in"><!-- video tab-pane fade in Starts --> <br> <textarea name="product_video" class="form-control" rows="15"></textarea> </div><!-- video tab-pane fade in Ends --> </div><!-- tab-content Ends --> </div><!-- form-group Ends --> <div class="form-group" id="product_weight"><!-- form-group Starts --> <label> Product Weight <small> (kg)</small> </label> <input type="text" name="product_weight" class="form-control"> </div><!-- form-group Ends --> <div class="form-group" id="product_price"><!-- form-group Starts --> <label> Product Price </label> <input type="text" name="product_price" class="form-control" required> </div><!-- form-group Ends --> <div class="form-group" id="product_psp_price"><!-- form-group Starts --> <label> Product Sale Price </label> <input type="text" name="psp_price" class="form-control"> </div><!-- form-group Ends --> </div><!-- col-md-9 Ends --> <div class="col-md-3"><!-- col-md-3 Starts --> <div class="form-group"><!-- form-group Starts --> <label> Select A Product Type </label> <select class="form-control" name="product_type"><!-- select manufacturer Starts --> <option value="physical_product"> (Physical Product) Simple Product </option> <option value="digital_product"> (Digital Product) Downloadable Product </option> <option value="variable_product"> (Variable Product) Advanced Product </option> </select><!-- select manufacturer Ends --> </div><!-- form-group Ends --> <div class="form-group"><!-- form-group Starts --> <label> Select A Manufacturer </label> <select class="form-control" name="manufacturer"><!-- select manufacturer Starts --> <option> Select A Manufacturer </option> <?php $get_manufacturer = "select * from manufacturers"; $run_manufacturer = mysqli_query($con,$get_manufacturer); while($row_manufacturer= mysqli_fetch_array($run_manufacturer)){ $manufacturer_id = $row_manufacturer['manufacturer_id']; $manufacturer_title = $row_manufacturer['manufacturer_title']; echo "<option value='$manufacturer_id'> $manufacturer_title </option>"; } ?> </select><!-- select manufacturer Ends --> </div><!-- form-group Ends --> <div class="form-group"><!-- form-group Starts --> <label> Product Category </label> <select name="product_cat" class="form-control" > <option> Select a Product Category </option> <?php $get_p_cats = "select * from product_categories"; $run_p_cats = mysqli_query($con,$get_p_cats); while ($row_p_cats=mysqli_fetch_array($run_p_cats)) { $p_cat_id = $row_p_cats['p_cat_id']; $p_cat_title = $row_p_cats['p_cat_title']; echo "<option value='$p_cat_id' >$p_cat_title</option>"; } ?> </select> </div><!-- form-group Ends --> <div class="form-group" ><!-- form-group Starts --> <label> Category </label> <select name="cat" class="form-control" > <option> Select a Category </option> <?php $get_cat = "select * from categories"; $run_cat = mysqli_query($con,$get_cat); while ($row_cat=mysqli_fetch_array($run_cat)) { $cat_id = $row_cat['cat_id']; $cat_title = $row_cat['cat_title']; echo "<option value='$cat_id'>$cat_title</option>"; } ?> </select> </div><!-- form-group Ends --> <div class="form-group" ><!-- form-group Starts --> <label> Product Image 1 </label> <input type="file" name="product_img1" class="form-control" required > </div><!-- form-group Ends --> <div class="form-group" ><!-- form-group Starts --> <label> Product Image 2 </label> <input type="file" name="product_img2" class="form-control"> </div><!-- form-group Ends --> <div class="form-group" ><!-- form-group Starts --> <label> Product Image 3 </label> <input type="file" name="product_img3" class="form-control"> </div><!-- form-group Ends --> <div class="form-group" ><!-- form-group Starts --> <label> Product Keywords </label> <input type="text" name="product_keywords" class="form-control"> </div><!-- form-group Ends --> <div class="form-group" ><!-- form-group Starts --> <label> Product Label </label> <input type="text" name="product_label" class="form-control"> </div><!-- form-group Ends --> </div><!-- col-md-3 Ends --> </div><!-- 2 row Ends --> <div class="form-group" id="product-stock-management"><!-- form-group Starts --> <label> Product Inventory Stock Management </label> <div class="panel panel-default"><!-- panel panel-default Starts --> <div class="panel-heading"><!-- panel-heading Starts --> <strong> Inventory - Stock Options </strong> </div><!-- panel-heading Ends --> <div class="panel-body"><!--panel-body Starts --> <div class="row"><!-- row Starts --> <div class="col-sm-6" id="stock-status"><!-- col-sm-6 Starts --> <div class="form-group"><!-- form-group Starts --> <label> Stock Status </label> <select class="form-control" name="stock_status" required><!-- select manufacturer Starts --> <option value="instock">In stock</option> <option value="outofstock">Out of stock</option> <option value="onbackorder">On backorder</option> </select><!-- select manufacturer Ends --> </div><!-- form-group Ends --> </div><!-- col-sm-6 Ends --> <div class="col-sm-6"><!-- col-sm-6 Starts --> <div class="form-group"><!-- form-group Starts --> <label> Enable stock management at product level? </label> <div class="radio"> <label> <input type="radio" name="enable_stock" value="yes" required> Yes </label> <label> <input type="radio" name="enable_stock" value="no" checked required> No </label> </div> </div><!-- form-group Ends --> </div><!-- col-sm-6 Ends --> </div><!-- row Ends --> <div class="row" id="stock-management-row"><!-- row Starts --> <div class="col-sm-6"><!-- col-sm-6 Starts --> <div class="form-group"><!-- form-group Starts --> <label> Stock Quantity </label> <input type="number" name="stock_quantity" value="0" class="form-control" required> </div><!-- form-group Ends --> </div><!-- col-sm-6 Ends --> <div class="col-sm-6"><!-- col-sm-6 Starts --> <div class="form-group"><!-- form-group Starts --> <label> Allow backorders? </label> <select class="form-control" name="allow_backorders" required><!-- select manufacturer Starts --> <option value="no">Do not allow</option> <option value="notify">Allow, but notify customer</option> <option value="yes">Allow</option> </select><!-- select manufacturer Ends --> </div><!-- form-group Ends --> </div><!-- col-sm-6 Ends --> </div><!-- row Ends --> </div><!--panel-body Ends --> </div><!-- panel panel-default Ends --> </div><!-- form-group Ends --> </form><!-- form-horizontal Ends --> <div class="form-group" id="variable_product_options"><!-- form-group Starts --> <label> Variable Product Options </label> <div class="panel panel-default"><!-- panel panel-default Starts --> <div class="panel-heading"><!-- panel-heading Starts --> <ul class="nav nav-tabs"><!-- nav nav-tabs Starts --> <li class="active"> <a data-toggle="tab" href="#product_attributes"> Product Attributes </a> </li> <li> <a data-toggle="tab" href="#product_variations"> Product Variations </a> </li> </ul><!-- nav nav-tabs Ends --> </div><!-- panel-heading Ends --> <div class="panel-body"><!--panel-body Starts --> <div class="tab-content"><!-- tab-content Starts --> <div id="product_attributes" class="tab-pane fade in active"><!-- product_attributes tab-pane fade in active Starts --> <form id="insert_attribute_form" method="post"><!-- form Starts --> <div class="row"><!-- row Starts --> <div class="col-sm-4"><!-- col-sm-4 Starts --> <div class="form-group"><!-- form-group Starts --> <label> Name: </label> <input type="text" name="attribute_name" class="form-control" required> </div><!-- form-group Ends --> </div><!-- col-sm-4 Ends --> <div class="col-sm-8"><!-- col-sm-8 Starts --> <div class="form-group"><!-- form-group Starts --> <label> Value(s): </label> <textarea name="attribute_values" class="form-control" placeholder="Enter some attributes by '|' separating values." required></textarea> </div><!-- form-group Ends --> </div><!-- col-sm-8 Ends --> </div><!-- row Ends --> <div class="form-group"><!-- form-group Starts --> <input type="submit" value="Insert Product Attribute" class="btn btn btn-primary"> </div><!-- form-group Ends --> </form><!-- form Ends --> <table class="table table-hover table-bordered table-striped"><!-- table table-hover table-bordered table-striped Starts --> <thead><!-- thead Starts --> <tr> <th>Attribute Name:</th> <th>Attribute Value(s):</th> <th>Actions:</th> </tr> </thead><!-- thead Ends --> <tbody><!-- tbody Starts --> <?php $random_id = 152; $select_product_attributes = "select * from product_attributes where product_id='$random_id'"; $run_product_attributes = mysqli_query($con,$select_product_attributes); while($row_product_attributes = mysqli_fetch_array($run_product_attributes)){ $attribute_id = $row_product_attributes["attribute_id"]; $attribute_name = $row_product_attributes["attribute_name"]; $attribute_values = $row_product_attributes["attribute_values"]; ?> <tr id="tr-attribute-<?php echo $attribute_id; ?>"> <td> <div class="edit" data-attribute="<?php echo $attribute_id; ?>"><?php echo $attribute_name; ?></div> <input type="text" id="attribute-name" class="input-edit form-control" data-attribute="<?php echo $attribute_id; ?>" value="<?php echo $attribute_name; ?>"> </td> <td> <div class="edit" data-attribute="<?php echo $attribute_id; ?>"><?php echo $attribute_values; ?></div> <input type="text" id="attribute-values" class="input-edit form-control" data-attribute="<?php echo $attribute_id; ?>" value="<?php echo $attribute_values; ?>"> </td> <td> <div class="btn-group"> <a href="#" class="edit-product-attribute btn btn-primary btn-sm" data-attribute="<?php echo $attribute_id; ?>"> <i class="fa fa-pencil"></i> Edit </a> <a href="#" class="save-product-attribute btn btn-success btn-sm" data-attribute="<?php echo $attribute_id; ?>"> <i class="fa fa-floppy-o"></i> Save </a> <a href="#" class="delete-product-attribute btn btn-danger btn-sm" data-attribute="<?php echo $attribute_id; ?>"> <i class="fa fa-trash-o"></i> Delete </a> </div> </td> </tr> <?php } ?> </tbody><!-- tbody Ends --> </table><!-- table table-hover table-bordered table-striped Ends --> </div><!-- product_attributes tab-pane fade in active Ends --> <div id="product_variations" class="tab-pane fade in"><!-- product_variations tab-pane fade in Starts --> <form id="product-variations-form" method="post" enctype="multipart/form-data"><!-- form Starts --> <div class="form-group row"><!-- form-group Starts --> <label class="col-sm-3 control-label"> Default Form Values: </label> <div class="col-sm-9"><!-- col-sm-10 Starts --> <div class="row" id="default_form_values"><!-- row default_form_values Starts --> </div><!-- row default_form_values Ends --> <span class="help-block"> These are the product attributes that will be pre-selected on the frontend. </span> </div><!-- col-sm-9 Ends --> </div><!-- form-group Ends --> <hr class="variation-hr"> <div class="form-group row"><!-- form-group Starts --> <label class="col-sm-1 control-label"> Actions: </label> <div class="col-sm-10"><!-- col-sm-10 Starts --> <select class="form-control" id="action_select"><!-- select manufacturer Starts --> <option value="add_variation"> Add A New Variation </option> <option value="create_variations_from_attributes"> Create New Variations From All Attributes </option> <option value="delete_all_variations"> Delete All Variations </option> </select><!-- select manufacturer Ends --> </div><!-- col-sm-10 Ends --> <div class="col-sm-1"><!-- col-sm-1 Starts --> <button type="button" id="go_button" class="btn btn-success form-control"> Go </button> </div><!-- col-sm-1 Ends --> </div><!-- form-group Ends --> <div class="product-variations-div"><!-- product-variations-div Starts --> </div><!-- product-variations-div Ends --> <hr class="variation-hr"> <div class="form-group"><!-- form-group Starts --> <input type="submit" value="Save Product Variations" class="btn btn btn-success"> </div><!-- form-group Ends --> </form><!-- form Ends --> <div class="ajax-response-div"></div> </div><!-- product_variations tab-pane fade in Ends --> </div><!-- tab-content Ends --> </div><!--panel-body Ends --> </div><!-- panel panel-default Ends --> </div><!-- form-group Ends --> <div class="form-group"><!-- form-group Starts --> <input type="submit" name="submit" value="Insert Product" form="insert_product_form" class="btn btn-primary form-control"> </div><!-- form-group Ends --> </div><!-- panel-body Ends --> </div><!-- panel panel-default Ends --> </div><!-- col-lg-12 Ends --> </div><!-- 2 row Ends --> <script> $(document).ready(function(){ //Product Stock Management Code Starts $("#stock-management-row").hide(); $("input[name='enable_stock']").click(function(){ var radio_value = $(this).val(); if(radio_value == "yes"){ $("#stock-status").hide(); $("#stock-management-row").show(); }else if(radio_value == "no"){ $("#stock-status").show(); $("#stock-management-row").hide(); } }); //Product Stock Management Code Ends //Change Product Type Function Code Starts function change_product_type(){ var product_type = $("select[name='product_type']").val(); if(product_type == "physical_product"){ $("#product_weight").show(); $("#product_price").show(); $("#product_psp_price").show(); $('#product_weight input,#product_price input,#product_psp_price input').prop("disabled", false); $("#product-stock-management").show(); $('#product-stock-management input,#product-stock-management select').prop("disabled", false); $("#variable_product_options").hide(); }else if(product_type == "digital_product"){ $("#product_weight").hide(); $("#product_price").show(); $("#product_psp_price").show(); $('#product_weight input,#product_price input,#product_psp_price input').prop("disabled", false); $("#product-stock-management").show(); $('#product-stock-management input,#product-stock-management select').prop("disabled", false); $("#variable_product_options").hide(); }else if(product_type == "variable_product"){ $("#product_weight").hide(); $("#product_price").hide(); $("#product_psp_price").hide(); $('#product_weight input,#product_price input,#product_psp_price input').prop("disabled", true); $("#product-stock-management").hide(); $('#product-stock-management input,#product-stock-management select').prop("disabled", true); $("#variable_product_options").show(); } } //Change Product Type Function Code Ends change_product_type(); $("select[name='product_type']").change(function(){ change_product_type(); }); //Load Product Attributes Function Code Starts function load_product_attributes(){ $.ajax({ method: "POST", url: "variable_product/load_product_attributes.php", data: { random_id: <?php echo $random_id; ?> }, success:function(data){ $("table tbody").html(data); $("table").removeClass("wait-loader"); } }); } //Load Product Attributes Function Code Ends //Insert New Product Attribute Code Starts $("#insert_attribute_form").submit(function(event){ event.preventDefault(); $("table").addClass("wait-loader"); $.ajax({ method: "POST", url: "variable_product/insert_product_attribute.php", data: $('#insert_attribute_form').serialize() + "&random_id=<?php echo $random_id; ?>", success: function(){ $("#insert_attribute_form").find("input[type=text],textarea").val(""); load_product_attributes(); } }); }); //Insert New Product Attribute Code Ends //Edit Product Attribute Code Starts $(".input-edit").hide(); $(".save-product-attribute").hide(); $(".edit-product-attribute").on('click', function(event){ event.preventDefault(); var attribute_id = $(this).data("attribute"); $(".edit").show(); $(".input-edit").hide(); $(".edit[data-attribute='" + attribute_id +"']").hide(); $(".input-edit[data-attribute='" + attribute_id +"']").show().focus(); $(".edit-product-attribute[data-attribute='" + attribute_id +"']").hide(); $(".save-product-attribute[data-attribute='" + attribute_id +"']").show(); }); //Edit Product Attribute Code Ends //Update Save Product Attribute Code Starts $(".save-product-attribute").on('click', function(event){ event.preventDefault(); var attribute_id = $(this).data("attribute"); $(".edit[data-attribute='" + attribute_id +"']").show(); $(".input-edit[data-attribute='" + attribute_id +"']").hide(); $(".edit-product-attribute[data-attribute='" + attribute_id +"']").show(); $(".save-product-attribute[data-attribute='" + attribute_id +"']").hide(); var attribute_name = $("#attribute-name[data-attribute='" + attribute_id +"']").val(); var attribute_values = $("#attribute-values[data-attribute='" + attribute_id +"']").val(); $("#attribute-name[data-attribute='" + attribute_id +"']").prev(".edit").text(attribute_name); $("#attribute-values[data-attribute='" + attribute_id +"']").prev(".edit").text(attribute_values); var random_id = <?php echo $random_id; ?>; $.ajax({ method: "POST", url: "variable_product/update_product_attribute.php", data: { random_id: random_id, attribute_id: attribute_id, attribute_name: attribute_name, attribute_values: attribute_values } }); }); //Update Save Product Attribute Code Ends //Delete Product Attribute Code Starts $(".delete-product-attribute").on('click', function(event){ event.preventDefault(); var attribute_id = $(this).data("attribute"); $("#tr-attribute-" + attribute_id).remove(); var random_id = <?php echo $random_id; ?>; $.ajax({ method: "POST", url: "variable_product/delete_product_attribute.php", data: { random_id: random_id, attribute_id: attribute_id } }); }); //Delete Product Attribute Code Ends //Load Product Variations Default Form Values Function Code Starts function load_variations_default_form_values(){ $.ajax({ method: "POST", url: "variable_product/load_default_form_values.php", data: { random_id: <?php echo $random_id; ?> }, success:function(data){ $("#default_form_values").html(data); } }); } //Load Product Variations Default Form Values Function Code Ends //Load Product Variations Function Code Starts function load_product_variations(){ $.ajax({ method: "POST", url: "variable_product/load_product_variations.php", data: { random_id: <?php echo $random_id; ?> }, success:function(data){ $(".product-variations-div").html(data); $(".product-variations-div").removeClass("wait-loader"); } }); } //Load Product Variations Function Code Ends //Click Product Variations Tab Code Starts $("a[href='#product_variations']").click(function(){ $(".product-variations-div").addClass("wait-loader"); load_variations_default_form_values(); load_product_variations(); }); //Click Product Variations Tab Code Ends //Save Update Product Variations Function Code Starts function save_update_product_variations(){ var form = document.getElementById("product-variations-form"); var form_data = new FormData(form); form_data.append("random_id", <?php echo $random_id; ?>); $.ajax({ method: "POST", url: "variable_product/update_all_variations.php", data:form_data, contentType: false, cache: false, processData:false, success: function(data){ $(".ajax-response-div").html(data); $(".product-variations-div").removeClass("wait-loader"); } }); } //Save Update Product Variations Function Code Ends //Product Variations Actions Go Button Code Starts $("#go_button").click(function(){ var action_select = $("#action_select").val(); if(action_select == "add_variation"){ $(".product-variations-div").addClass("wait-loader"); save_update_product_variations(); $(".product-variations-div").addClass("wait-loader"); $.ajax({ method: "POST", url: "variable_product/insert_product_variation.php", data: { random_id: <?php echo $random_id; ?> }, success: function(){ load_product_variations(); } }); }else if(action_select == "create_variations_from_attributes"){ var confirm_action = confirm("Are you sure you want to link all variations? This will create a new variation for each and every possible combination of variation attributes (max 50 per run)."); if(confirm_action == true){ $(".product-variations-div").addClass("wait-loader"); save_update_product_variations(); $(".product-variations-div").addClass("wait-loader"); $.ajax({ method: "POST", url: "variable_product/create_variations_from_attributes.php", data: { random_id: <?php echo $random_id; ?> }, success: function(data){ $(".ajax-response-div").html(data); load_product_variations(); load_variations_default_form_values(); } }); } }else if(action_select == "delete_all_variations"){ var confirm_action = confirm("Are you sure you want to delete all variations? This cannot be undone."); if(confirm_action == true){ $(".product-variations-div").addClass("wait-loader"); $.ajax({ method: "POST", url: "variable_product/delete_all_variations.php", data: { random_id: <?php echo $random_id; ?> }, success: function(){ load_product_variations(); load_variations_default_form_values(); } }); } } }); //Product Variations Actions Go Button Code Ends //Save Update Submit From Of Product Variations Code Starts $("#product-variations-form").submit(function(event){ event.preventDefault(); $(".product-variations-div").addClass("wait-loader"); save_update_product_variations(); load_variations_default_form_values(); }); //Save Update Submit From Of Product Variations Code Ends }); </script> <?php if(isset($_POST['submit'])){ $product_title = mysqli_real_escape_string($con, $_POST['product_title']); $product_seo_desc = mysqli_real_escape_string($con, $_POST['product_seo_desc']); $product_url = mysqli_real_escape_string($con, $_POST['product_url']); $product_cat = mysqli_real_escape_string($con, $_POST['product_cat']); $cat = mysqli_real_escape_string($con, $_POST['cat']); $manufacturer_id = mysqli_real_escape_string($con, $_POST['manufacturer']); $product_price = mysqli_real_escape_string($con, $_POST['product_price']); $product_desc = mysqli_real_escape_string($con, $_POST['product_desc']); $product_keywords = mysqli_real_escape_string($con, $_POST['product_keywords']); $psp_price = mysqli_real_escape_string($con, $_POST['psp_price']); $product_label = mysqli_real_escape_string($con, $_POST['product_label']); $product_type = mysqli_real_escape_string($con, $_POST['product_type']); $product_features = mysqli_real_escape_string($con, $_POST['product_features']); $product_video = mysqli_real_escape_string($con, $_POST['product_video']); $product_weight = mysqli_real_escape_string($con, $_POST['product_weight']); $stock_status = mysqli_real_escape_string($con, $_POST['stock_status']); $enable_stock = mysqli_real_escape_string($con, $_POST['enable_stock']); $stock_quantity = mysqli_real_escape_string($con, $_POST['stock_quantity']); $allow_backorders = mysqli_real_escape_string($con, $_POST['allow_backorders']); $status = "product"; $product_img1 = $_FILES['product_img1']['name']; $product_img2 = $_FILES['product_img2']['name']; $product_img3 = $_FILES['product_img3']['name']; $temp_name1 = $_FILES['product_img1']['tmp_name']; $temp_name2 = $_FILES['product_img2']['tmp_name']; $temp_name3 = $_FILES['product_img3']['tmp_name']; $allowed = array('jpeg','jpg','gif','png'); $product_img1_extension = pathinfo($product_img1, PATHINFO_EXTENSION); $product_img2_extension = pathinfo($product_img2, PATHINFO_EXTENSION); $product_img3_extension = pathinfo($product_img3, PATHINFO_EXTENSION); if(!in_array($product_img1_extension,$allowed)){ echo "<script> alert('Your Product Image 1 File Extension Is Not Supported.'); </script>"; $product_img1 = ""; }else{ move_uploaded_file($temp_name1,"../admin_area/product_images/$product_img1"); } if(!empty($product_img2)){ if(!in_array($product_img2_extension,$allowed)){ echo "<script> alert('Your Product Image 2 File Extension Is Not Supported.'); </script>"; $product_img2 = ""; }else{ move_uploaded_file($temp_name2,"../admin_area/product_images/$product_img2"); } } if(!empty($product_img3)){ if(!in_array($product_img3_extension,$allowed)){ echo "<script> alert('Your Product Image 3 File Extension Is Not Supported.'); </script>"; $product_img3 = ""; }else{ move_uploaded_file($temp_name3,"../admin_area/product_images/$product_img3"); } } $insert_product = "insert into products (vendor_id,p_cat_id,cat_id,manufacturer_id,date,product_title,product_seo_desc,product_url,product_img1,product_img2,product_img3,product_price,product_psp_price,product_desc,product_features,product_video,product_keywords,product_label,product_type,product_weight,product_vendor_status,status) values ('$customer_id','$product_cat','$cat','$manufacturer_id',NOW(),'$product_title','$product_seo_desc','$product_url','$product_img1','$product_img2','$product_img3','$product_price','$psp_price','$product_desc','$product_features','$product_video','$product_keywords','$product_label','$product_type','$product_weight','$product_vendor_status','$status')"; $run_product = mysqli_query($con,$insert_product); $product_id = mysqli_insert_id($con); if($run_product){ if($product_type != "variable_product"){ if($enable_stock == "yes" and $stock_quantity > 0){ $stock_status = "instock"; }elseif($enable_stock == "yes" and $allow_backorders == "no" and $stock_quantity < 1){ $stock_status = "outofstock"; }elseif($enable_stock == "yes" and ($allow_backorders == "yes" or $allow_backorders == "notify") and $stock_quantity < 1){ $stock_status = "onbackorder"; } $insert_product_stock = "insert into products_stock (product_id,enable_stock,stock_status,stock_quantity,allow_backorders) values ('$product_id','$enable_stock','$stock_status','$stock_quantity','$allow_backorders')"; $run_insert_product_stock = mysqli_query($con,$insert_product_stock); } $update_product_stock = "update products_stock set product_id='$product_id' where product_id='$random_id'"; $run_update_product_stock = mysqli_query($con,$update_product_stock); $update_product_attributes = "update product_attributes set product_id='$product_id' where product_id='$random_id'"; $run_product_attributes = mysqli_query($con, $update_product_attributes); $update_product_variations = "update product_variations set product_id='$product_id' where product_id='$random_id'"; $run_product_variations = mysqli_query($con, $update_product_variations); echo " <script> alert(' Your Product Has Been Inserted Successfully. '); window.open('index.php?products','_self'); </script> "; } } ?>
Everything on this page works the form loads and i can insert info into the form but when i click submit it just reloads the page(action="this page") and nothing happens. thanks in advance -Adam Code: [Select] <?php require("connection/connection.php"); include("connection/functions.php"); ?> <HTML> <head> <meta content="yes" name="apple-mobile-web-app-capable" /> <meta content="index,follow" name="robots" /> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <link href="" rel="apple-touch-icon" /> <meta content="minimum-scale=1.0, width=device-width, maximum-scale=0.6667, user-scalable=no" name="viewport" /> <meta name="format-detection" content="telephone=no"/> <link href="css/style.css" rel="stylesheet" media="screen" type="text/css" /> <script src="javascript/functions.js" type="text/javascript"></script> <title>.: Bookmarks :.</title> <link href="" rel="apple-touch-startup-image" /> <meta content="apple-mobile-web-app-status-bar-style" content="default" /> </head> <body class="musiclist"> <div id="topbar"> <div id="title">.: Bookmarks :.</div> <div id="leftbutton"> <a href="default.html"><img src="images/home.png"></a> </div> <div id="rightbutton"> <a href="">Programs</a> </div> </div> <div id="tributton"> <div class="links"> <a id="pressed" href="Bookmarks/Bookmarks.php">Bookmarks</a><a href="Music/Music.html">Music</a><a href="">Movies</a> </div> </div> <div id="content" style="top: 36px"> <form method="post" action="AddBookmark.php"> <span class="graytitle">Add Bookmark</span> <ul class="pageitem"> <li class="bigfield"><input type="text" name="BookmarkName" placeholder="Bookmark Name" /></li> <li class="bigfield"><input type="text" name="BookmarkLink" placeholder="Bookmark Link" /></li> <li class="select"><select name="d"> <?php $getbookmarksections = mysql_query("SELECT * FROM bookmarksections"); confirm_query($getbookmarksections); while($getbm = mysql_fetch_array($getbookmarksections)){ $id = $getbm["ID"]; $sn = $getbm["SectionName"]; echo "<option value=\"$id\">$sn</option>"; } ?> </select><span class="arrow"></span></li> <li class="button"> <input name="AddBookmark" type="submit" value="Add Bookmark" /> </li> </ul> </form> <?php if(isset($_POST["AddBookmark"])){ $SectionID = $id; $Bookmark = $_POST["BookmarkName"]; $BookmarkLink = $_POST["BookmarkLink"]; $add = "INSERT INTO `bookmarks` (`ID` ,`SectionID` ,`Bookmark` ,`BookmarkLink`) VALUES ('NULL', '$SectionID', '$Bookmark', '$BookmarkLink')"; if(confirm_query($add)){ echo "<span class=\"graytitle\">Bookmark '$BookmarkName' in '$sn' Added.</span>"; } } ?> </div> <div id="footer"> </div> </body> </HTML> <?php //Close Connection if(isset($connection)){ mysql_close($connection); } ?> this is the code i suspect is not working Code: [Select] <?php if(isset($_POST["AddBookmark"])){ $SectionID = $id; $Bookmark = $_POST["BookmarkName"]; $BookmarkLink = $_POST["BookmarkLink"]; $add = "INSERT INTO `bookmarks` (`ID` ,`SectionID` ,`Bookmark` ,`BookmarkLink`) VALUES ('NULL', '$SectionID', '$Bookmark', '$BookmarkLink')"; if(confirm_query($add)){ echo "<span class=\"graytitle\">Bookmark '$BookmarkName' in '$sn' Added.</span>"; } } ?> Hi all, I've made a page the variables are being recieved and echo'd ok, however they are not being inserted into the database. below is the file with the insert statement. any help really appreciated. MsKazza Code: [Select] <?php // Database connect $con = mysql_connect("mysql1.myhost.ie","admin_book","root123"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("book_test", $con); $orderid=$_GET['orderid']; //Parse Values from Coupon.php Form $orderid = mysql_real_escape_string(trim($_POST['orderid'])); $design = mysql_real_escape_string(trim($_POST['design'])); $childname = mysql_real_escape_string(trim($_POST['childname'])); $address = mysql_real_escape_string(trim($_POST['address'])); echo $orderid; echo $design; echo $childname; echo $address; $sql="INSERT INTO details (orderid, design, childname, address) VALUES ('$orderid','$design','$childname','$address')"; ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Digital Scribe Books</title> <link href="style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } function MM_swapImgRestore() { //v3.0 var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; } function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_swapImage() { //v3.0 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} } </script> </head> <body onload="MM_preloadImages('images/buttons/home_over.png','images/buttons/books_over.png','images/buttons/cards_over.png','images/buttons/letters_over.png')"> <div id="snow"> <div id="wrapper"> <div id="header"> <div id="logo"><img src="images/digital_scripe.png" width="218" height="91" /></div> <div id="menu"><a href="index.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Home','','images/buttons/home_over.png',1)"><img src="images/buttons/home_act.png" name="Home" width="131" height="132" border="0" id="Home" /></a><a href="books.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Books','','images/buttons/books_over.png',1)"><img src="images/buttons/books_act.png" name="Books" width="131" height="132" border="0" id="Books" /></a><a href="cards.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Cards','','images/buttons/cards_over.png',1)"><img src="images/buttons/cards_act.png" name="Cards" width="131" height="132" border="0" id="Cards" /></a><a href="letters.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Letters','','images/buttons/letters_over.png',1)"><img src="images/buttons/letters_act.png" name="Letters" width="131" height="132" border="0" id="Letters" /></a></div> </div> <div id="content"> <div id="info_bar"><br /><br /><br /> <p>Your personal order number is:</p><br /> <br /> <p>Please fill out the details of where you would like your order to be shipped to.</p> </div> <form action="card_paynow.php" method="POST" name="custdetails" id="custdetails"> <table width="60%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="19%">orderid</td> <td width="81%"><input name="orderid" type="hidden" value="<? echo $orderid; ?>"></td> </tr> <tr> <td>name</td> <td><input name="name" type="text" id="name"></td> </tr> <tr> <td>surname</td> <td><input name="surname" type="text" id="surname"></td> </tr> <tr> <td>address 1 </td> <td><input name="add1" type="text" id="add1"></td> </tr> <tr> <td>address 2 </td> <td><input name="add2" type="text" id="add2"></td> </tr> <tr> <td>town</td> <td><input name="town" type="text" id="town"></td> </tr> <tr> <td>county</td> <td><input name="county" type="text" id="county"></td> </tr> <tr> <td>postcode</td> <td><input name="postcode" type="text" id="postcode"></td> </tr> <tr> <td>number</td> <td><input name="phone" type="text" id="phone"></td> </tr> <tr> <td>email</td> <td><input name="email" type="text" id="email"></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Continue..."></td> </tr> <tr> <td> </td> <td> </td> </tr> </table> </form> </div> <div id="footer" class="clear"><div id="sign"><div id="sign_text">Personalised<br /> Books</div> </div></div> </div></div> </body> </html> Hello, I am trying to get a news script to work, but I can't get it to insert anything into the database. I cannot figure it out for the life of me. Code: (newsupdate.php) [Select] <form name="shout" action="post.php" method="post"> <p><b>Name:</b><br/><input type="text" name="name" size="15"/></p> <p><b>Message</b>:<br/> <textarea wrap="physical" name="message" rows="3" cols="25">News goes here! </textarea></p> <p><input type="submit" value="Shout now!"/> <input type="reset" value="Clear"/></p> </form> Code: (post.php) [Select] <? $name = $_POST["name"]; $message = $_POST["message"]; include("dbconnect.php"); $date = date("M j y"); $menu = MYSQL_QUERY("INSERT INTO adminnews (id,name,date,message)". "VALUES ('NULL', '$name', '$date', '$message')"); echo("Shout-out added! You will be redirected to the main page shortly. If you are not, click <a href='index.php'>here</a>."); ?> dbconnect.php is just the configuration for connecting to the database, and I have checked that all ready. A log-in script uses it just fine. Hello, ive got the right output from the code below, only my mysql query doesnt seem to be working as it should. Im not too great with mysql so please any help or suggestions would be great. I have tried the code but when I check my database nothing has been inserted. !?! Code: [Select] <?php include('db.php'); include('func.php'); ?><html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Chained Select Boxes using PHP, MySQL and jQuery</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#wait_1').hide(); $('#drop_1').change(function(){ $('#wait_1').show(); $('#result_1').hide(); $.get("func.php", { func: "drop_1", drop_var: $('#drop_1').val() }, function(response){ $('#result_1').fadeOut(); setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400); }); return false; }); }); function finishAjax(id, response) { $('#wait_1').hide(); $('#'+id).html(unescape(response)); $('#'+id).fadeIn(); } </script> </head> <body> <p> <form action="" method="post"> Name: <input type="text" name="Name" /><br /> Phone: <input type="text" name="Phone" /><br /> Email: <input type="text" name="Email" /><br /> Postcode: <input type="text" name="Postcode" /><br /> Web Address: <input type="text" name="Website" /><br /><br /> <select name="drop_1" id="drop_1"> <option value="" selected="selected" disabled="disabled">Select a Category</option> <?php getTierOne(); ?> </select> <span id="wait_1" style="display: none;"> <img alt="Please Wait" src="ajax-loader.gif"/> </span> <span id="result_1" style="display: none;"></span> <br /> </form> </p> <p> <?php if(isset($_POST['submit'])){ $drop = $_POST['drop_1']; $tier_two = $_POST['Subtype']; echo "You selected "; echo $drop." & ".$tier_two; } $Name = $_POST["Name"]; $Phone = $_POST["Phone"]; $Email = $_POST["Email"]; $Postcode = $_POST["Postcode"]; $Website = $_POST["Website"]; echo "<br>"; echo $Name; echo "<br>"; echo $Website; mysql_query ("INSERT INTO business (Name, Type, Subtype, Phone, Email, Postcode, Web Address) VALUES ('$Name', '$drop', '$tier_two' , '$Phone', '$Email', '$Postcode', '$Website')"); ?> Im not sure it makes a difference but, I am adding data into each column of my database with the exception of the 1st column named 'ID' which is set to auto_increment. i have this code... and i want to make it more dynamic.... Code: [Select] <?php $content = $content[1].$content[2].$content[3].$content[4].$content[5].$content[6].$content[7].$content[8].$content[9].$content[10].$content[11].$content[12] .$content[13].$content[14].$content[15].$content[16] .$content[17].$content[18].$content[19].$content[20].$content[21].$content[22].$content[23].$content[24]; $sql = mysql_query ("insert into database (content) values ('$content')") or die(mysql_error()); ?> for example... instead content[1]. content[2]. content[3] ...etc... i want something like this....... $content = $content[from 1 to 24]; or $content = $content[from 1 to 777]; any solutions? hi, i was having difficulty and i'm quite confused how to insert these values to the database before it will become as it is, based on this article: http://roshanbh.com.np/2008/01/populate-triple-drop-down-list-change-options-value-from-database-using-ajax-and-php.html what i did was putting/saving the values directly in the database (mysql). but now i want those values to be coming from the user's input:the country,state and city so the system will just get those values, store it to the database with the fields of each table having the same content like that from article above..i really need some help here.. This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=350408.0 |