Jump to content

bloody form....


herghost

Recommended Posts

Hi guys,

 

anyone help me with this?

 

here is my form input:

$checkBoxes = array('name', 'changemx', 'traceaddy', 'addoncgi', 'addondomains', 'zoneedit', 'advguest', 'agora', 'analog', 'handlers', 'autoresponders', 'awstats', 'backup', 'backupwizard', 'bandwidth', 'boxtrapper', 'cgi', 'csvimport', 'setlang', 'style', 'chat', 'statselect', 'counter', 'cron', 'errpgs', 'defaultaddress', 'dirselector', 'diskusageviewer', 'popaccts', 'emailauth', 'emaildomainfwd', 'blockers', 'emailscripts', 'entropybanner', 'entropysearch', 'errlog', 'fantastico', 'Fantastico_De_Luxe', 'filemanager', 'forwarders', 'frontpage', 'ftpaccts', 'ftpsetup', 'getstart', 'hotlink', 'ipdeny', 'ipdeny', 'cpanelpro_images', 'indexmanager', 'modules_php_pear', 'modules_perl', 'modules_ruby', 'interchange', 'clock', 'lastvisits', 'cpanelpro_leechprotect', 'lists', 'mime', 'mysql', 'nettools', 'pgp', 'bbs', 'parkeddomains', 'password', 'phpmyadmin', 'phppgadmin', 'postgres', 'randhtml', 'rawlog', 'redirects', 'ror', 'ssh', 'sslinstall', 'sslmanager', 'searchsubmit', 'php_config', 'serverstatus', 'scgiwrap', 'simplezoneedit', 'guest', 'spamassassin', 'spambox', 'statmanager', 'subdomains', 'subdomainstats', 'cpanelpro_support', 'updatecontact', 'updatenotificationprefs', 'videotut', 'clamavconnector_scan', 'webdisk', 'webalizer', 'webmail', 'webprotect'); 
foreach ($checkBoxes as $key) {
     $data[$key] = isset($_POST[$key])?trim($_POST[$key]) : '';
}


$query = "INSERT INTO product_features (" . implode(", ", $checkBoxes) . ") VALUES (" . implode("', '", $data) . ")";

 

and here is the result:

Error: 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 '', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1' at line 1

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/195717-bloody-form/
Share on other sites

Try:

 

$query = "INSERT INTO product_features (" . implode(', ', $checkBoxes) . ") VALUES (" . implode(', ', $data) . ")";

 

Or, even better, something like:

 

$formBoxes = implode(', ', $checkboxes);
$formData = implode(', ', $data);

$query = "INSERT INTO product_features ($formBoxes) VALUES ($formData)";

Link to comment
https://forums.phpfreaks.com/topic/195717-bloody-form/#findComment-1028229
Share on other sites

INSERT INTO product_features (name, changemx, traceaddy, addoncgi, addondomains, zoneedit, advguest, agora, analog, handlers, autoresponders, awstats, backup, backupwizard, bandwidth, boxtrapper, cgi, csvimport, setlang, style, chat, statselect, counter, cron, errpgs, defaultaddress, dirselector, diskusageviewer, popaccts, emailauth, emaildomainfwd, blockers, emailscripts, entropybanner, entropysearch, errlog, fantastico, Fantastico_De_Luxe, filemanager, forwarders, frontpage, ftpaccts, ftpsetup, getstart, hotlink, ipdeny, ipdeny, cpanelpro_images, indexmanager, modules_php_pear, modules_perl, modules_ruby, interchange, clock, lastvisits, cpanelproleechprotect, lists, mime, mysql, nettools, pgp, bbs, parkeddomains, password, phpmyadmin, phppgadmin, postgres, randhtml, rawlog, redirects, ror, ssh, sslinstall, sslmanager, searchsubmit, php_config, serverstatus, scgiwrap, simplezoneedit, guest, spamassassin, spambox, statmanager, subdomains, subdomainstats, cpanelpro_support, updatecontact, updatenotificationprefs, videotut, clamavconnector_scan, webdisk, webalizer, webmail, webprotect) VALUES (go', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1)Error: 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 '', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1' at line 1

 

To many 1's for me!

 

Can you see the error?

Link to comment
https://forums.phpfreaks.com/topic/195717-bloody-form/#findComment-1028235
Share on other sites

I now have the below:

<?php
session_start();
include('../../config/connect.php');

$name = (isset($_POST['name'])) ? trim($_POST['name']) : '';

$query0="INSERT INTO product_features (name) VALUES ('$name')";
if (!mysql_query($query0))
  {
  die('Error: ' . mysql_error());
  }
else
{
echo $query0;
$query1 =" SELECT id FROM product_features WHERE name = '$name'";
$result = mysql_query($query1);
echo $result;
while($row = mysql_fetch_array($result));{
$id = $row['id'];
$_SESSION['id'] = $id;  
}

$checkBoxes = array( 'changemx', 'traceaddy', 'addoncgi', 'addondomains', 'zoneedit', 'advguest', 'agora', 'analog', 'handlers', 'autoresponders', 'awstats', 'backup', 'backupwizard', 'bandwidth', 'boxtrapper', 'cgi', 'csvimport', 'setlang', 'style', 'chat', 'statselect', 'counter', 'cron', 'errpgs', 'defaultaddress', 'dirselector', 'diskusageviewer', 'popaccts', 'emailauth', 'emaildomainfwd', 'blockers', 'emailscripts', 'entropybanner', 'entropysearch', 'errlog', 'fantastico', 'Fantastico_De_Luxe', 'filemanager', 'forwarders', 'frontpage', 'ftpaccts', 'ftpsetup', 'getstart', 'hotlink', 'ipdeny', 'cpanelpro_images', 'indexmanager', 'modules_php_pear', 'modules_perl', 'modules_ruby', 'interchange', 'clock', 'lastvisits', 'cpanelproleechprotect', 'lists', 'mime', 'mysql', 'nettools', 'pgp', 'bbs', 'parkeddomains', 'password', 'phpmyadmin', 'phppgadmin', 'postgres', 'randhtml', 'rawlog', 'redirects', 'ror', 'ssh', 'sslinstall', 'sslmanager', 'searchsubmit', 'php_config', 'serverstatus', 'scgiwrap', 'simplezoneedit', 'guest', 'spamassassin', 'spambox', 'statmanager', 'subdomains', 'subdomainstats', 'cpanelpro_support', 'updatecontact', 'updatenotificationprefs', 'videotut', 'clamavconnector_scan', 'webdisk', 'webalizer', 'webmail', 'webprotect'); 
foreach ($checkBoxes as $key) {
     $data[$key] = isset($_POST[$key])?trim($_POST[$key]) : '';
}

$formBoxes = implode(', ', $checkBoxes);
$formData = implode(', ', $data);
$id = $_SESSION['id'];


$query = "INSERT INTO product_features WHERE id = '$id'($formBoxes) VALUES ($formData)";
echo $query;


if (!mysql_query($query))
  {
  die('Error: ' . mysql_error());
  }
else
{
$_SESSION['featureadd'] = 'featureadd';
header("Location: $adminbase/viewfeaturelist.php");
}
}
?>

 

But am still running into this error:

INSERT INTO product_features (name) VALUES ('try')Resource id #5INSERT INTO product_features WHERE id = ''(changemx, traceaddy, addoncgi, addondomains, zoneedit, advguest, agora, analog, handlers, autoresponders, awstats, backup, backupwizard, bandwidth, boxtrapper, cgi, csvimport, setlang, style, chat, statselect, counter, cron, errpgs, defaultaddress, dirselector, diskusageviewer, popaccts, emailauth, emaildomainfwd, blockers, emailscripts, entropybanner, entropysearch, errlog, fantastico, Fantastico_De_Luxe, filemanager, forwarders, frontpage, ftpaccts, ftpsetup, getstart, hotlink, ipdeny, cpanelpro_images, indexmanager, modules_php_pear, modules_perl, modules_ruby, interchange, clock, lastvisits, cpanelproleechprotect, lists, mime, mysql, nettools, pgp, bbs, parkeddomains, password, phpmyadmin, phppgadmin, postgres, randhtml, rawlog, redirects, ror, ssh, sslinstall, sslmanager, searchsubmit, php_config, serverstatus, scgiwrap, simplezoneedit, guest, spamassassin, spambox, statmanager, subdomains, subdomainstats, cpanelpro_support, updatecontact, updatenotificationprefs, videotut, clamavconnector_scan, webdisk, webalizer, webmail, webprotect) VALUES (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)Error: 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 'WHERE id = ''(changemx, traceaddy, addoncgi, addondomains, zoneedit, advguest, a' at line 1

 

 

Link to comment
https://forums.phpfreaks.com/topic/195717-bloody-form/#findComment-1028252
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.