Chubichan Posted January 11, 2009 Share Posted January 11, 2009 Hello mates it is I again. Seems my n00bness is at work again. I have the following code written and it simply is not working. Seeing if you lads could be of some help to myself. My php file for the content management: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Dr. Michael D. Doyle | Payment Information</title> <LINK REL=StyleSheet HREF="content_management.css" TYPE="text/css" /> <script defer type="text/javascript" src="pngfix.js"></script> <script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script> </head> <body> <div id="container"> <h3>Michael D. Doyle Content Management System</h3> <div id="form_wrapper"> <form action="put.php" method="post"> <div><label for="index">Homepage</label><textarea name="index" rows="15" cols="70"> </textarea></div> <div><label for="mot">Meet Our Team</label><textarea name="mot" rows="15" cols="70"> </textarea></div> <div><label for="pf">Patient Forms</label><textarea name="pf" rows="15" cols="70"> </textarea></div> <div><label for="fi">Financial Information</label><textarea name="fi" rows="15" cols="70"> </textarea></div> <div><label for="loc">Locations</label><textarea name="loc" rows="15" cols="70"> </textarea></div> <div><label for="con">Contact</label><textarea name="con" rows="15" cols="70"> </textarea></div> <div><label for="ms">Mission Statement</label><textarea name="ms" rows="15" cols="70"> </textarea></div> <div><label for="dis">Disclaimer</label><textarea name="dis" rows="15" cols="70"> </textarea></div> <div class="actions"><input type="submit" input name="submit" value="Submit Content" id="add" class="submit"/></div> </form> </div> </div> </body> </html> Now my put.php that will process these inputs and place them in the mySQL database: <?php if(isset($_POST['add'])) { include 'config.php'; include 'opendb.php'; $index = $_POST['index']; $mot = $_POST['mot']; $pf = $_POST['pf']; $fi = $_POST['fi']; $loc = $_POST['loc']; $con = $_POST['con']; $ms = $_POST['ms']; $dis = $_POST['dis']; $query = "INSERT INTO cms (index, team, form, financial, locations, contact, mission, disclaimer) VALUES ('$index', '$mot', '$pf', '$fi', '$loc', '$con', '$ms', '$dis')"; mysql_query($query) or die('Error, insert query failed'); include 'closedb.php'; echo "Update complete."; } ?> Here are my included php files that I use to connect to the database. opendb: <?php $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); ?> config: <?php $dbhost = 'localhost'; $dbuser = 'drmdoyle_user'; $dbpass = 'password is hidden'; $dbname = 'drmdoyle_content'; ?> closedb: <?php mysql_close($conn); ?> I am sure it is something small but my eyes are tired and I need another pair of eyes to look at it for me. Any help would be delightful. Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/140409-solved-why-isnt-this-working-am-i-missing-something/ Share on other sites More sharing options...
peranha Posted January 11, 2009 Share Posted January 11, 2009 What exactly isnt working, any errors you are getting will help also. Quote Link to comment https://forums.phpfreaks.com/topic/140409-solved-why-isnt-this-working-am-i-missing-something/#findComment-734854 Share on other sites More sharing options...
Lamez Posted January 11, 2009 Share Posted January 11, 2009 change this mysql_query($query) or die('Error, insert query failed'); to mysql_query($query) or die(mysql_error()); post the error. Quote Link to comment https://forums.phpfreaks.com/topic/140409-solved-why-isnt-this-working-am-i-missing-something/#findComment-734855 Share on other sites More sharing options...
Chubichan Posted January 11, 2009 Author Share Posted January 11, 2009 It was reporting this: $query = "INSERT INTO cms (index, team, form, financial, locations, contact, mission, disclaimer) VALUES ('$index', '$mot', '$pf', '$fi', '$loc', '$con', '$ms', '$dis')"; mysql_query($query) or die('Error, insert query failed'); Error, insert query failed Now it does nothing. www.drmdoyle.com/content_management.php for testing Quote Link to comment https://forums.phpfreaks.com/topic/140409-solved-why-isnt-this-working-am-i-missing-something/#findComment-734856 Share on other sites More sharing options...
trq Posted January 11, 2009 Share Posted January 11, 2009 index is a reserved word within mysql. Either change your field name to something else (recommended) or wrap it within `backticks`. Quote Link to comment https://forums.phpfreaks.com/topic/140409-solved-why-isnt-this-working-am-i-missing-something/#findComment-734873 Share on other sites More sharing options...
Chubichan Posted January 11, 2009 Author Share Posted January 11, 2009 changed name to home and in all corresponding locations. Any other advice? Quote Link to comment https://forums.phpfreaks.com/topic/140409-solved-why-isnt-this-working-am-i-missing-something/#findComment-734927 Share on other sites More sharing options...
RestlessThoughts Posted January 11, 2009 Share Posted January 11, 2009 I've never seen ' id="add" ' in a form before. Try changing the 'name' of the submit button to 'add', or the 'if(isset)' to 'submit'. Maybe that'll help. Quote Link to comment https://forums.phpfreaks.com/topic/140409-solved-why-isnt-this-working-am-i-missing-something/#findComment-734938 Share on other sites More sharing options...
DarkSuperHero Posted January 11, 2009 Share Posted January 11, 2009 RestlessThoughts is right... your checking to see if $_POST['add'] is set, but it is never set because there is no field with name add, its id is add, but not its name... so change your code to say $_POST['submit'] or change your form from name="submit" to name="add".... try it...let us know what happens... Quote Link to comment https://forums.phpfreaks.com/topic/140409-solved-why-isnt-this-working-am-i-missing-something/#findComment-734948 Share on other sites More sharing options...
Chubichan Posted January 12, 2009 Author Share Posted January 12, 2009 changed the name to name="add" and got this Error, insert query failed from line 17: mysql_query($query) or die('Error, insert query failed'); AHHHH Quote Link to comment https://forums.phpfreaks.com/topic/140409-solved-why-isnt-this-working-am-i-missing-something/#findComment-734983 Share on other sites More sharing options...
Chubichan Posted January 12, 2009 Author Share Posted January 12, 2009 New code. Still doesn't work <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Dr. Michael D. Doyle | Payment Information</title> <LINK REL=StyleSheet HREF="content_management.css" TYPE="text/css" /> </head> <body> <div id="container"> <h3>Michael D. Doyle Content Management System</h3> <div id="form_wrapper"> <form method="post" action="put.php"> <div><label for="index">Homepage</label><textarea name="home" rows="15" cols="70"> </textarea></div> <div><label for="mot">Meet Our Team</label><textarea name="mot" rows="15" cols="70"> </textarea></div> <div><label for="pf">Patient Forms</label><textarea name="pf" rows="15" cols="70"> </textarea></div> <div><label for="fi">Financial Information</label><textarea name="fi" rows="15" cols="70"> </textarea></div> <div><label for="loc">Locations</label><textarea name="loc" rows="15" cols="70"> </textarea></div> <div><label for="con">Contact</label><textarea name="con" rows="15" cols="70"> </textarea></div> <div><label for="ms">Mission Statement</label><textarea name="ms" rows="15" cols="70"> </textarea></div> <div><label for="dis">Disclaimer</label><textarea name="dis" rows="15" cols="70"> </textarea></div> <div class="actions"><input type="submit" input name="submit" value="Submit Content" class="submit"/></div> </form> </div> </div> </body> </html> put.php: <?php if(isset($_POST['submit'])) { include 'config.php'; include 'opendb.php'; $home = $_POST['home']; $mot = $_POST['mot']; $pf = $_POST['pf']; $fi = $_POST['fi']; $loc = $_POST['loc']; $con = $_POST['con']; $ms = $_POST['ms']; $dis = $_POST['dis']; $query = "INSERT INTO cms (home, team, form, financial, location, contact, mission, disclaimer) VALUES ('$home', '$mot', '$pf', '$fi', '$loc', '$con', '$ms', '$dis')"; mysql_query($query) or die('No worky'); include 'closedb.php'; echo "Worky!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/140409-solved-why-isnt-this-working-am-i-missing-something/#findComment-734995 Share on other sites More sharing options...
DarkSuperHero Posted January 12, 2009 Share Posted January 12, 2009 <div class="actions"><input type="submit" input name="submit" value="Submit Content" class="submit"/></div> into <div class="actions"><input type="submit" name="submit" value="Submit Content" class="submit"/></div> Quote Link to comment https://forums.phpfreaks.com/topic/140409-solved-why-isnt-this-working-am-i-missing-something/#findComment-735004 Share on other sites More sharing options...
Chubichan Posted January 12, 2009 Author Share Posted January 12, 2009 <div class="actions"><input type="submit" input name="submit" value="Submit Content" class="submit"/></div> into <div class="actions"><input type="submit" name="submit" value="Submit Content" class="submit"/></div> Changed it. Close, but no cigar. Still giving me the error that it can't insert into the table. Any other advice anyone has? I absolutely cannot think of what it is that I am doing wrong. I have ran over this code a million times. Quote Link to comment https://forums.phpfreaks.com/topic/140409-solved-why-isnt-this-working-am-i-missing-something/#findComment-735013 Share on other sites More sharing options...
premiso Posted January 12, 2009 Share Posted January 12, 2009 You know pritnig out the actual error message may help. <?php if(isset($_POST['submit'])) { include 'config.php'; include 'opendb.php'; $home = $_POST['home']; $mot = $_POST['mot']; $pf = $_POST['pf']; $fi = $_POST['fi']; $loc = $_POST['loc']; $con = $_POST['con']; $ms = $_POST['ms']; $dis = $_POST['dis']; $query = "INSERT INTO cms (home, team, form, financial, location, contact, mission, disclaimer) VALUES ('$home', '$mot', '$pf', '$fi', '$loc', '$con', '$ms', '$dis')"; mysql_query($query) or die('No worky: ' . mysql_error()); include 'closedb.php'; echo "Worky!"; } ?> mysql_error would help you. My bet is you have a ' single quote in your data coming in and mysql_real_escape_string that data will probably fix it. Quote Link to comment https://forums.phpfreaks.com/topic/140409-solved-why-isnt-this-working-am-i-missing-something/#findComment-735014 Share on other sites More sharing options...
Chubichan Posted January 12, 2009 Author Share Posted January 12, 2009 It printed this: No worky: No database selected Sorry that I am such a noobster, but what exactly would fix this? I am connecting to my database just fine I thought.... ????, Adam Quote Link to comment https://forums.phpfreaks.com/topic/140409-solved-why-isnt-this-working-am-i-missing-something/#findComment-735027 Share on other sites More sharing options...
premiso Posted January 12, 2009 Share Posted January 12, 2009 use mysql_select_db after mysql_connect Quote Link to comment https://forums.phpfreaks.com/topic/140409-solved-why-isnt-this-working-am-i-missing-something/#findComment-735030 Share on other sites More sharing options...
Chubichan Posted January 12, 2009 Author Share Posted January 12, 2009 use mysql_select_db after mysql_connect Like this: <?php $conn = mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname) or die ('Error connecting to mysql'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/140409-solved-why-isnt-this-working-am-i-missing-something/#findComment-735036 Share on other sites More sharing options...
premiso Posted January 12, 2009 Share Posted January 12, 2009 use mysql_select_db after mysql_connect Like this: <?php $conn = mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname) or die ('Error connecting to mysql'); ?> Did you try it? Yes, like that. Quote Link to comment https://forums.phpfreaks.com/topic/140409-solved-why-isnt-this-working-am-i-missing-something/#findComment-735038 Share on other sites More sharing options...
Chubichan Posted January 12, 2009 Author Share Posted January 12, 2009 Prints an error: Error connecting to mysql from: or die ('Error connecting to mysql') Quote Link to comment https://forums.phpfreaks.com/topic/140409-solved-why-isnt-this-working-am-i-missing-something/#findComment-735042 Share on other sites More sharing options...
Chubichan Posted January 12, 2009 Author Share Posted January 12, 2009 No idea what I have done to fix it, but it is fixed. I think I may have just had a small typo in my opendb.php file....But I am not sure. FIXED!! Thanks to all who helped! Quote Link to comment https://forums.phpfreaks.com/topic/140409-solved-why-isnt-this-working-am-i-missing-something/#findComment-735048 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.