Jump to content

mkalinow

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

mkalinow's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. So after a solid day of trying to figure this out, I stuck my headquarters variable at the top of the list and at the end of the $sql query and it worked and posted textarea as well You're right, though. Just saw that if it remains unchecked, it errors out. I'm sure you've saved me from dealing with another pain in the ass so I appreciate it. Code below if you're curious <?php $host="localhost"; // Host name $username="root"; // Mysql usernamer $password="pw"; // Mysql password $db_name="movedb"; // Database name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Get values from form $Headquarters=$_POST['headquarters']; $Company=$_POST['company']; $City=$_POST['city']; $State=$_POST['state']; $Country=$_POST['country']; $Address1=$_POST['address1']; $Address2=$_POST['address2']; $Zip=$_POST['zip']; $Division=$_POST['division']; $YearEstablished=$_POST['yearestablished']; $Homepage=$_POST['homepage']; $Qaemployees=$_POST['qaemployees']; $Numberofemployees=$_POST['numberofemployees']; $Mainnumber=$_POST['mainnumber']; $Contactname=$_POST['contactname']; $Telephone=$_POST['telephone']; $Mobile=$_POST['mobile']; $Contactposition=$_POST['contactposition']; $Emailaddy=$_POST['emailaddy']; $Faxnumber=$_POST['faxnumber']; $Comments=$_POST['comments']; // Insert data into mysql $sql="INSERT INTO supplier_data(company, city, state, country, address1, address2, zip, division, yearestablished, homepage, qaemployees, numberofemployees, mainnumber, contactname, telephone, mobile, contactposition, emailaddy, faxnumber, comments, headquarters)VALUES('$Company', '$City', '$State', '$Country', '$Address1', '$Address2', '$Zip', '$Division', '$YearEstablished', '$Homepage', '$Qaemployees', '$Numberofemployees', '$Mainnumber', '$Contactname', '$Telephone', '$Mobile', '$Contactposition', '$Emailaddy', '$Faxnumber', '$Comments', '$Headquarters')"; echo $sql; $result=mysql_query($sql); // if successfully insert data into database, displays message "Successful". if($result){ echo "Successful"; echo "<BR>"; echo "<a href='add.php'>Back to main page</a>"; } else { echo "ERROR"; } // close connection mysql_close();?> Edit: Hit enter too quickly. The Headquarters checkbox is the first field in the table and if I had to guess, I have to enter all of these variables in the order that they're coded on the form. In other words, headquarters is the first identifier, company name is the second but in the post PHP, company name came before headquarters. Am I off-base with this understanding?
  2. Well, it's a single checkbox but I was trying to rig it so it'd work. What would you recommend if I get rid of the array? Form.php <tr><td><form name="form2" method="post" action="http://localhost/scm/new-design/insert_com.php"></td><td> </td></tr> <tr><td><input type="checkbox" name="headquarters" value="1">Headquarters</td> It just enters a 1 into the DB if the record entry serves as headquarters (ticked) to a company and 0 if it doesn't (unticked). When this was all started, I wasn't using an array and sort of sifted around online and this is where I'm sitting at currently. As I said earlier, either the textareas will write to the DB or the checkboxes will, but not both. Is it still necessary to convert the data?
  3. It's an internal site so I'm not too concerned but for best practices, I'll be reading up on it soon. Well, to make this simple, I'll try to document it in full. $Faxnumber=$_POST['faxnumber']; $Comments=$_POST['comments']; [b]$Headquarters=$_POST['headquarters'];[/b] // Insert data into mysql $sql="INSERT INTO supplier_data(company, city, state, country, address1, address2, zip, division, yearestablished, homepage, qaemployees, numberofemployees, mainnumber, contactname, telephone, mobile, contactposition, emailaddy, faxnumber, comments, [b]headquarters[/b])VALUES('$Company', '$City', '$State', '$Country', '$Address1', '$Address2', '$Zip', '$Division', '$YearEstablished', '$Homepage', '$Qaemployees', '$Numberofemployees', '$Mainnumber', '$Contactname', '$Telephone', '$Mobile', '$Contactposition', '$Emailaddy', '$Faxnumber', '$Comments', [b]'$Headquarters'[/b])"; When I add $headquarters back into my first insert statement, I get the following error: INSERT INTO supplier_data(company, city, state, country, address1, address2, zip, division, yearestablished, homepage, qaemployees, numberofemployees, mainnumber, contactname, telephone, mobile, contactposition, emailaddy, faxnumber, comments, headquarters)VALUES('Test', '', '', '', '', '', '', '', '', 'http://', 'unk', 'unk', '', '', '', '', '', '', '', '', 'Array')ERROR On the form page, headquarters has a value of "headquarters[]." If I change the value to just simply "headquarters," I get: INSERT INTO supplier_data(company, city, state, country, address1, address2, zip, division, yearestablished, homepage, qaemployees, numberofemployees, mainnumber, contactname, telephone, mobile, contactposition, emailaddy, faxnumber, comments, headquarters)VALUES('w', '', '', '', '', '', '', '', '', 'http://', 'unk', 'unk', '', '', '', '', '', '', '', '', '')ERROR
  4. So, I've been having an issue setting up checkboxes on a supplier database insert form. A user has the ability to add a new entity into the database (Company name, address, etc.) via textboxes which work just fine. However, when I try to get the checkboxes to write to the mySQL database along with the textboxes, I begin getting errors. I've gotten to the point in the code where either one or the other works, but not both at the same time. I was searching around and saw that someone mentioned isset as a solution to their checkbox problem but thus far, it hasn't helped too much I'm new to this language so if you guys need any more additional information, please let me know. <?php $host="localhost"; // Host name $username="root"; // Mysql usernamer $password="pw"; // Mysql password $db_name="movedb"; // Database name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Get values from form $Company=$_POST['company']; $City=$_POST['city']; $State=$_POST['state']; $Country=$_POST['country']; $Address1=$_POST['address1']; $Address2=$_POST['address2']; $Zip=$_POST['zip']; $Division=$_POST['division']; $YearEstablished=$_POST['yearestablished']; $Homepage=$_POST['homepage']; $Qaemployees=$_POST['qaemployees']; $Numberofemployees=$_POST['numberofemployees']; $Mainnumber=$_POST['mainnumber']; $Contactname=$_POST['contactname']; $Telephone=$_POST['telephone']; $Mobile=$_POST['mobile']; $Contactposition=$_POST['contactposition']; $Emailaddy=$_POST['emailaddy']; $Faxnumber=$_POST['faxnumber']; $Comments=$_POST['comments']; // Insert data into mysql [b]$sql="INSERT INTO supplier_data(company, city, state, country, address1, address2, zip, division, yearestablished, homepage, qaemployees, numberofemployees, mainnumber, contactname, telephone, mobile, contactposition, emailaddy, faxnumber, comments)VALUES('$Company', '$City', '$State', '$Country', '$Address1', '$Address2', '$Zip', '$Division', '$YearEstablished', '$Homepage', '$Qaemployees', '$Numberofemployees', '$Mainnumber', '$Contactname', '$Telephone', '$Mobile', '$Contactposition', '$Emailaddy', '$Faxnumber', '$Comments')";[/b] if(isset($_POST['headquarters'])) { $Headquarters = implode(",",$_POST['headquarters']); echo $Headquarters; [b]$sql="INSERT INTO supplier_data(headquarters)VALUES('$Headquarters')";[/b] } echo $sql; $result=mysql_query($sql); // if successfully insert data into database, displays message "Successful". if($result){ echo "Successful"; echo "<BR>"; echo "<a href='add.php'>Back to main page</a>"; } else { echo "ERROR"; } // close connection mysql_close();?> I've bolded the two $sql statements I'm having trouble with and headquarters, by the way, is the aforementioned checkbox. I couldn't simply place it in the first INSERT statement along with all of the other variables so there I am. With the code above, it simply writes a 1 or 0 to the db depending on whether or not the box was ticked. If I comment it out, all of the textboxes now work. I figure it's because the second $sql for headquarters is just overwriting the first $sql variable, which I understand. However, I don't understand these PHP conventions because when I rename one of the $sql variables to $sql1 or anything else, I begin receiving errors. Hopefully this wasn't too drawn out but let me say that I appreciate you guys taking a look at this either way :]
×
×
  • 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.