contra10 Posted December 21, 2008 Share Posted December 21, 2008 for some reason it processes but the information isn't submitted to mysql here is my code <?php // Connects to your Database mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("inform") or die(mysql_error()); //This code runs if the form has been submitted if (isset($_POST['submit'])) { //This makes sure they did not leave any fields blank if (!$_POST['name'] | !$_POST['group'] | !$_POST['description']) { die('You did not complete all of the required fields'); } // checks if the username is in use if (!get_magic_quotes_gpc()) { $_POST['name'] = ($_POST['name']); } $groupcheck = $_POST['name']; $check = mysql_query("SELECT name FROM groups WHERE name = '$groupcheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { die('Sorry, the group '.$_POST['name'].' is already in use.'); } // this makes sure both passwords entered match if ($_POST['name'] == $_POST['group']) { die('Input a different name please. '); } // now we insert it into the database $insert = "INSERT INTO groups (name, group, description, city, email) VALUES ('".$_POST['name']."', '".$_POST['group']."', '".$_POST['description']."', '".$_POST['city']."', '".$_POST['email']."', '".$_POST['image']."')"; $add_group = mysql_query($insert); ?> <h1>Good Job</h1> <p>Thank you<a href= "http://localhost/main"</a>Main</p> <?php } else { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0" align="center" width="100"> <td align="left" width="20"><b>Name:</td><td><input type="text" name="name" maxlength="30" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"></td><br> <tr><td align="left"><b>Category:</td><td><select name="group" type="group" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"> <option value="Alumni" selected>Alumni</option> <option value="Automotive">Automotive</option> <option value="Business">Business</option> <option value="City">City</option> <option value="Environmental">Environmental</option> <option value="Fashion">Fashion</option> <option value="Angola">Angola</option> </select></td></tr> <td><b>Description:</b></td> <td><textarea name="description" type="description" cols="50" rows="7" maxlength="10" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;">PLEASE GIVE A DESCRIPTION OF THE GROUP</textarea></td></tr> <td><b>City:</b></td> <td><input type="city" name="city" maxlength="50" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"></td> <tr><td><b>Email:</td> <td><input type="email" name="email" maxlength="50" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"></td> <tr><td><b>Image:</td> <td><input type="file" name="image" name="groupimage" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"></td> <tr><td></td> <td>Uploaded Image</td> <td> <input type="submit" name="submit"> </td> </tr> </table> </form> <?php } ?> please help Link to comment https://forums.phpfreaks.com/topic/137949-solved-i-cant-upload-information-from-form-to-mysql-database/ Share on other sites More sharing options...
chronister Posted December 22, 2008 Share Posted December 22, 2008 Try this.... using or die(mysql_error()) will save MUCH time when troubleshooting queries. $add_group = mysql_query($insert) or die(mysql_error()); See if it gives ya an error. Link to comment https://forums.phpfreaks.com/topic/137949-solved-i-cant-upload-information-from-form-to-mysql-database/#findComment-721025 Share on other sites More sharing options...
contra10 Posted December 22, 2008 Author Share Posted December 22, 2008 not getting any errors...and information is not in the database Link to comment https://forums.phpfreaks.com/topic/137949-solved-i-cant-upload-information-from-form-to-mysql-database/#findComment-721029 Share on other sites More sharing options...
contra10 Posted December 22, 2008 Author Share Posted December 22, 2008 nvm error is Create A Group qwe 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, description, city, email) VALUES ('qwe', 'Alumni', 'PLEASE GIVE A DESCRI' at line 1 Link to comment https://forums.phpfreaks.com/topic/137949-solved-i-cant-upload-information-from-form-to-mysql-database/#findComment-721030 Share on other sites More sharing options...
chronister Posted December 22, 2008 Share Posted December 22, 2008 You really should not use post data directly in a query. Take those out of the query and set them as vars, run the post data through mysql_real_escape_string() (preferred), or through addslashes(). Nate Link to comment https://forums.phpfreaks.com/topic/137949-solved-i-cant-upload-information-from-form-to-mysql-database/#findComment-721031 Share on other sites More sharing options...
contra10 Posted December 22, 2008 Author Share Posted December 22, 2008 i don't think i did it right <?php // Connects to your Database mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("inform") or die(mysql_error()); //This code runs if the form has been submitted if (isset($_POST['submit'])) { //This makes sure they did not leave any fields blank if (!$_POST['name'] | !$_POST['group'] | !$_POST['description']) { die('You did not complete all of the required fields'); } // checks if the username is in use if (!get_magic_quotes_gpc()) { $_POST['name'] = ($_POST['name']); } $groupcheck = $_POST['name']; $check = mysql_query("SELECT name FROM groups WHERE name = '$groupcheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { die('Sorry, the group '.$_POST['name'].' is already in use.'); } // this makes sure both passwords entered match if ($_POST['name'] == $_POST['group']) { die('Input a different name please. '); } $name = mysql_real_escape_string($_POST['name']); $group = mysql_real_escape_string($_POST['group']); $description = mysql_real_escape_string($_POST['description']); $city = mysql_real_escape_string($_POST['city']); $email = mysql_real_escape_string($_POST['email']); // now we insert it into the database $insert = "INSERT INTO groups {name,group,description,city, email} VALUES ('".$name."', '".$group."', '".$description."', '".$city."', '".$email."')"; $add_group = mysql_query($insert) or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/137949-solved-i-cant-upload-information-from-form-to-mysql-database/#findComment-721037 Share on other sites More sharing options...
chronister Posted December 22, 2008 Share Posted December 22, 2008 $insert = "INSERT INTO groups {name,group,description,city, email} VALUES ('$name', '$group', '$description', '$city', '$email')"; $add_group = mysql_query($insert) or die(mysql_error()); If you wrap the statement in " " (quotation marks) then you can use apostrophe's ' ' to wrap the value items. They will still be parsed as variables. Do you get any errors after doing this?? Nate Link to comment https://forums.phpfreaks.com/topic/137949-solved-i-cant-upload-information-from-form-to-mysql-database/#findComment-721038 Share on other sites More sharing options...
contra10 Posted December 22, 2008 Author Share Posted December 22, 2008 the error i get is Create A Group qwe 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 '{name,group,description,city, email} VALUES ('qwe', 'Alumni', 'PLEASE GIVE A DE' at line 1 heres the code again <?php // Connects to your Database mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("inform") or die(mysql_error()); //This code runs if the form has been submitted if (isset($_POST['submit'])) { //This makes sure they did not leave any fields blank if (!$_POST['name'] | !$_POST['group'] | !$_POST['description']) { die('You did not complete all of the required fields'); } // checks if the username is in use if (!get_magic_quotes_gpc()) { $_POST['name'] = ($_POST['name']); } $groupcheck = $_POST['name']; $check = mysql_query("SELECT name FROM groups WHERE name = '$groupcheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { die('Sorry, the group '.$_POST['name'].' is already in use.'); } // this makes sure both passwords entered match if ($_POST['name'] == $_POST['group']) { die('Input a different name please. '); } $name = mysql_real_escape_string($_POST['name']); $group = mysql_real_escape_string($_POST['group']); $description = mysql_real_escape_string($_POST['description']); $city = mysql_real_escape_string($_POST['city']); $email = mysql_real_escape_string($_POST['email']); // now we insert it into the database $insert = "INSERT INTO groups {name,group,description,city, email} VALUES ('$name', '$group', '$description', '$city', '$email')"; $add_group = mysql_query($insert) or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/137949-solved-i-cant-upload-information-from-form-to-mysql-database/#findComment-721041 Share on other sites More sharing options...
contra10 Posted December 22, 2008 Author Share Posted December 22, 2008 hmm...still doesn't work Link to comment https://forums.phpfreaks.com/topic/137949-solved-i-cant-upload-information-from-form-to-mysql-database/#findComment-721054 Share on other sites More sharing options...
chronister Posted December 22, 2008 Share Posted December 22, 2008 Well, the query appears to by correct syntax.... Do this and post what you get. I am wondering if your database structure is not accepting the data.... Post the results and we'll go from there. $insert = "INSERT INTO groups {name,group,description,city, email} VALUES ('$name', '$group', '$description', '$city', '$email')"; echo $insert; //$add_group = mysql_query($insert) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/137949-solved-i-cant-upload-information-from-form-to-mysql-database/#findComment-721058 Share on other sites More sharing options...
contra10 Posted December 22, 2008 Author Share Posted December 22, 2008 I get INSERT INTO groups {name,group,description,city, email} VALUES ('yhu', 'Alumni', 'PLEASE GIVE A DESCRIPTION OF THE GROUP', 'uyh', 'yhu') Link to comment https://forums.phpfreaks.com/topic/137949-solved-i-cant-upload-information-from-form-to-mysql-database/#findComment-721059 Share on other sites More sharing options...
chronister Posted December 22, 2008 Share Posted December 22, 2008 Ok, that looks right to me as far as the syntax..... I would start looking at the database and make sure that your field names are correct and that the data types for those fields are correct. I am not sure if you will get this particular error on say a varchar(5) field when the data is longer. Take that same query into PHPmyAdmin and see if you can get it to insert there. If you get the same error (probably will) then look at the field names and the data type/length for those fields. Nate Link to comment https://forums.phpfreaks.com/topic/137949-solved-i-cant-upload-information-from-form-to-mysql-database/#findComment-721064 Share on other sites More sharing options...
contra10 Posted December 22, 2008 Author Share Posted December 22, 2008 k, i did that before and before the only data that would enter is the name, after i did it just for the city, diescription ... and on its own none of them would enter. my names were id, name, group, description... all with text except for id which was an integer....i changes it to varchar now and added lengths to them and for some reason still shows that same problem...I also checked the fields and the names in the post all match , i honestly don't know what the problem could be. Link to comment https://forums.phpfreaks.com/topic/137949-solved-i-cant-upload-information-from-form-to-mysql-database/#findComment-721071 Share on other sites More sharing options...
chronister Posted December 22, 2008 Share Posted December 22, 2008 Go to phpmyadmin and do an export of that table... I only need the structure... not the data too. I will create it on my server here at home and see whats up. Nate Link to comment https://forums.phpfreaks.com/topic/137949-solved-i-cant-upload-information-from-form-to-mysql-database/#findComment-721080 Share on other sites More sharing options...
contra10 Posted December 22, 2008 Author Share Posted December 22, 2008 -- phpMyAdmin SQL Dump -- version 2.11.6 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: Dec 21, 2008 at 09:54 PM -- Server version: 5.0.51 -- PHP Version: 5.2.6 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; -- -- Database: `inform` -- -- -------------------------------------------------------- -- -- Table structure for table `groups` -- CREATE TABLE `groups` ( `name` varchar(20) NOT NULL, `group` varchar(20) NOT NULL, `description` varchar(150) NOT NULL, `city` varchar(20) NOT NULL, `email` varchar(20) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data for table `groups` -- Link to comment https://forums.phpfreaks.com/topic/137949-solved-i-cant-upload-information-from-form-to-mysql-database/#findComment-721082 Share on other sites More sharing options...
chronister Posted December 22, 2008 Share Posted December 22, 2008 I AM AN IDIOT!!!!!!!.... Can't believe I missed this. Your using a mysql reserved word in your table. the word group is reserved. In order for it to work you will have to use backticks around it. Also, your using curly brackets in the column name part.. you have to use ( ) not { }. The error you were getting was because of the curly brackets ... but once those got fixed you would have gotten an error about using group without backticks. This works for me without errors. INSERT INTO groups (name,`group`,description,city, email) VALUES ('yhu', 'Alumni', 'PLEASE GIVE A DESCRIPTION OF THE GROUP', 'uyh', 'yhu') Nate Link to comment https://forums.phpfreaks.com/topic/137949-solved-i-cant-upload-information-from-form-to-mysql-database/#findComment-721106 Share on other sites More sharing options...
contra10 Posted December 22, 2008 Author Share Posted December 22, 2008 OH MY GOD.....THANK YOU i didn;t realize i was using the other brackets, and thanks for telling me about the ` ` around the reserved words i honestly did not know that....on last question may be stupid but i need to make sure can i still add and id section thats auto incrementerd.... I know i prolly can but im so messed up right now... i love this site...need to donate soon...LOL thank u very very much Link to comment https://forums.phpfreaks.com/topic/137949-solved-i-cant-upload-information-from-form-to-mysql-database/#findComment-721112 Share on other sites More sharing options...
chronister Posted December 22, 2008 Share Posted December 22, 2008 Yeah you can add an auto-increment id field. It should not mess things up... you may need to add it manually to some of the data that is already there, but it can be done. Nate Link to comment https://forums.phpfreaks.com/topic/137949-solved-i-cant-upload-information-from-form-to-mysql-database/#findComment-721118 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.