drakecai Posted October 7, 2010 Share Posted October 7, 2010 I have deleted mysql info for safety reasons. Here are the two webpage's codes i'm using right now menu.php <? session_start(); if(!session_is_registered(myusername)){ header("location:login.php"); } ?> <html><title>ChronoServe - Saving Time</title> <link href="style.css" rel="stylesheet" type="text/css"> <body> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="container"> <tr> <td> <table width="335px" height="50%" border="1" align="center" cellpadding="0" cellspacing="0" class="centered"> <tr> <td> <form method="post" action="insertvalues.php"> <table width="100%" border="0" align="center" cellpadding="3" cellspacing="10"> <tr> <td colspan="2"><div align="center" class="font2">Activation Information</div></td> </tr> <tr> <td colspan="2"></td> </tr> <tr> <td width="40%" class="font3">First Name :</td> <td width="60%"> <div align="center"> <input name="firstname" type="text" class="font3" id="firstname" maxlength="25" /> </div></td> </tr> <tr> <td class="font3">Last Name :</td> <td> <div align="center"> <input name="lastname" type="text" class="font3" id="lastname" maxlength="25" /> </div></td> </tr> <tr> <td height="28" class="font3">Phone Number :</td> <td> <div align="center"> <input name="pnumber" type="text" class="font3" id="pnumber" maxlength="10" /> </div></td> </tr> <tr> <td class="font3">Personnel Activated :</td> <td> <div align="center"> <input name="numberactivated" type="text" class="font3" id="numberactivated" maxlength="3" /> </div></td> </tr> <tr> <td height="37" colspan="2"></td> </tr> <tr> <td colspan="2"><div align="center"> <input name="submit" type="Submit" class="font3" value="Submit" /> </div> </td> </tr> </table> </form></td> </tr> </table> </td> </tr> </table> </body> </html> insertvalues.php <?php if(isset($_POST['Submit'])) { $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $pnumber = $_POST['pnumber']; $numberactivated = $_POST['numberactivated']; mysql_connect ("deleted", "deleted", "deleted") or die ('Error: ' . mysql_error()); mysql_select_db ("deleted"); $query = "INSERT INTO disney_database (id, firstname, lastname, pnumber, numberactivated, date) VALUES ('NULL', '".$firstname."', '".$lastname."', '".$pnumber."', '".$numberactivated."', 'NULL')"; mysql_query($query) or die('Error updating database'); header("location:menu.php"); echo "Database Updated With: ".$firstname."" - "".$lastname."" - "".$pnumber."" - "".$numberactivated.""; } else { echo "Database Error" { ?> Here is my problem. I set a one <form> on every form field I have including the submit button. Now whenever I press the submit button it redirects to insertvalues.php which it should be doing. In insertvalues i told it to query the form data and post it into my database's table. Its not doing that and tells me that it has a database error which i set it to tell me if something goes wrong. Anyone can help me? BTW I can manually query in the information using sql with phpmyadmin. so can someone please review my code for me? thanks big help! You can see what is happening. Visit www.chronoserve.com The username and password are "admin" Quote Link to comment https://forums.phpfreaks.com/topic/215381-form-data-not-being-entered-into-mysql-database/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 7, 2010 Share Posted October 7, 2010 The name of your submit form field is - name="submit" You would need to test if that same name is set in your php code. $_POST['Submit'] is not the same as $_POST['submit] Quote Link to comment https://forums.phpfreaks.com/topic/215381-form-data-not-being-entered-into-mysql-database/#findComment-1120029 Share on other sites More sharing options...
drakecai Posted October 8, 2010 Author Share Posted October 8, 2010 I have tried it works the same Quote Link to comment https://forums.phpfreaks.com/topic/215381-form-data-not-being-entered-into-mysql-database/#findComment-1120040 Share on other sites More sharing options...
Pawn Posted October 8, 2010 Share Posted October 8, 2010 Are you sure? PFMaBiSmAd's post solved the only problem I can see. Replace echo "Database Error"; with print_r($_POST); and give us the output. Quote Link to comment https://forums.phpfreaks.com/topic/215381-form-data-not-being-entered-into-mysql-database/#findComment-1120047 Share on other sites More sharing options...
PFMaBiSmAd Posted October 8, 2010 Share Posted October 8, 2010 Since the code you posted for insertvalues.php contains two fatal parse errors, I seriously doubt that is the actual code you are using. Quote Link to comment https://forums.phpfreaks.com/topic/215381-form-data-not-being-entered-into-mysql-database/#findComment-1120056 Share on other sites More sharing options...
drakecai Posted October 8, 2010 Author Share Posted October 8, 2010 I got, Array ( [firstname] => drake [lastname] => cai [pnumber] => 6263846321 [numberactivated] => 1 [submit] => Submit ) and it is what i entered in Quote Link to comment https://forums.phpfreaks.com/topic/215381-form-data-not-being-entered-into-mysql-database/#findComment-1120057 Share on other sites More sharing options...
Pawn Posted October 8, 2010 Share Posted October 8, 2010 Assuming you did actually change if(isset($_POST['Submit'])) to if(isset($_POST['submit'])), there is no way your page can be echoing "Database Error" based on that input. Quote Link to comment https://forums.phpfreaks.com/topic/215381-form-data-not-being-entered-into-mysql-database/#findComment-1120059 Share on other sites More sharing options...
drakecai Posted October 8, 2010 Author Share Posted October 8, 2010 Thank you pawn, I am guess my stubbornness caused this failure. Thank you so much guys I have one more questions, is there anyway I can make mysql delete the information i just inserted everyday? or every few hours? I want it to be automated. Quote Link to comment https://forums.phpfreaks.com/topic/215381-form-data-not-being-entered-into-mysql-database/#findComment-1120061 Share on other sites More sharing options...
Pawn Posted October 8, 2010 Share Posted October 8, 2010 Write a simple script to delete what you want, e.g. <?php $sql = "DELETE * FROM table"; if(!$query = mysql_query($sql)) { error_log("Cronjob failed on line ".__LINE__."! ".mysql_error()); } ?> Because you won't be executing the script directly, but running it automatically, it's important to log errors. To run the script every few days or hours, you will need to use crontab. Google is your friend. Quote Link to comment https://forums.phpfreaks.com/topic/215381-form-data-not-being-entered-into-mysql-database/#findComment-1120147 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.