ambo Posted September 25, 2008 Share Posted September 25, 2008 ok guys so i have the events table up and it posts events just fine its getting late and im tired of looking at code ill do more tommorow but the events script will actually post empty fields if you just hit submit so i was wondering <form method="post" action="eventprocess.php"> <table width="100%" cellspacing="0" cellpadding="0"> <tr> <td width="59%">Convention ID Must Be Unique:</td> <td width="41%"><div align="center"> <input type="text" name="id" size="20" value'This Must Be Changed'> </div></td> </tr> <tr> <td><font color="#008000">Start</font> Date/Time:YYYY-MM-DD 00:00:00</td> <td><div align="center"> <input type="text" name="start" size="20"> </div></td> </tr> <tr> <td><font color="#FF0000">End</font> Date/Time:YYYY-MM-DD 00:00:00</td> <td><div align="center"> <input type="text" name="end" size="20"> </div></td> </tr> <tr> <td>Event Type:</td> <td><div align="center"> <input type="text" name="type" size="20"> </div></td> </tr> <tr> <td>Event Location:</td> <td><div align="center"> <input type="text" name="location" size="20"> </div></td> </tr> <tr> <td>Event Details:</td> <td><div align="center"> <input type="text" name="details" size="20"> </div></td> </tr> <tr> <td>Event Notes:</td> <td><div align="center"> <input type="text" name="notes" size="20"> </div></td> </tr> <tr> <td colspan="2"><div align="center"> <input type="submit" value="Submit New Event"> <input type="hidden" name="action" value="submit_new_event"> </div></td> </tr> </table> </form> How Do you make it so you cant submit a empty field could you do a function like " if all fields contain data then post else{you must fill out all fields} This is the handler for posting data to database $CONVENTION_ID = mysql_real_escape_string($_POST['id']); $event_start = mysql_real_escape_string($_POST['start']); $event_end = mysql_real_escape_string($_POST['end']); $event_type = mysql_real_escape_string($_POST['type']); $event_location = mysql_real_escape_string($_POST['location']); $event_details = mysql_real_escape_string($_POST['details']); $event_notes= mysql_real_escape_string($_POST['notes']); mysql_query("INSERT INTO events (CONVENTION_ID,event_start,event_end,event_type,event_location,event_details,event_notes) VALUES('$CONVENTION_ID','$event_start','$event_end','$event_type','$event_location','$event_details','$event_notes') ") or die(mysql_error()); echo "Data Inserted!"; Quote Link to comment https://forums.phpfreaks.com/topic/125741-technical-question/ Share on other sites More sharing options...
F1Fan Posted September 25, 2008 Share Posted September 25, 2008 Using only PHP, just do a check after it's posted and return an error if something's empty. The better way would be to use form validation with JavaScript. http://www.w3schools.com/js/tryit.asp?filename=tryjs_formvalidate Quote Link to comment https://forums.phpfreaks.com/topic/125741-technical-question/#findComment-650209 Share on other sites More sharing options...
Maq Posted September 25, 2008 Share Posted September 25, 2008 You can check these field with javascript. Have a function like: function IsEmpty(aTextField) { if ((aTextField.value.length==0) || (aTextField.value==null)) { return true; } else { return false; } } This help? Quote Link to comment https://forums.phpfreaks.com/topic/125741-technical-question/#findComment-650210 Share on other sites More sharing options...
Maq Posted September 25, 2008 Share Posted September 25, 2008 F1Fan is right, you should check this with PHP and javascript in case the user has javascript disabled. Quote Link to comment https://forums.phpfreaks.com/topic/125741-technical-question/#findComment-650212 Share on other sites More sharing options...
ambo Posted September 25, 2008 Author Share Posted September 25, 2008 well i might not have to do this if i can figure out a way to delete a variable i can do it with this mysql_query("DELETE FROM events WHERE CONVENTION_ID= 'value' "); But can you get it to work with this $del_id = mysql_real_escape_string($_POST['delid']); mysql_query("DELETE FROM events WHERE CONVENTION_ID=$del_id"); Where the red is input from the form with a input with name delid Quote Link to comment https://forums.phpfreaks.com/topic/125741-technical-question/#findComment-650224 Share on other sites More sharing options...
ambo Posted September 25, 2008 Author Share Posted September 25, 2008 By the way this goes to all that have helped me thank you so much I know im a noob im new to php but i am learning when this site is done and the hard work pays off you guys will be repayed for your troubles i wont forget the help esspecially from f1fan who was helping me rather extensively on another problem Quote Link to comment https://forums.phpfreaks.com/topic/125741-technical-question/#findComment-650227 Share on other sites More sharing options...
Maq Posted September 25, 2008 Share Posted September 25, 2008 Try debugging, like this: mysql_query("DELETE FROM events WHERE CONVENTION_ID='$del_id'") or die (mysql_error()); You should also try echoing out your query to make sure your vars have the correct values: Quote Link to comment https://forums.phpfreaks.com/topic/125741-technical-question/#findComment-650231 Share on other sites More sharing options...
ambo Posted September 25, 2008 Author Share Posted September 25, 2008 Still no wont delete it Quote Link to comment https://forums.phpfreaks.com/topic/125741-technical-question/#findComment-650247 Share on other sites More sharing options...
Sulman Posted September 25, 2008 Share Posted September 25, 2008 I always seperate the query. It makes it easier to debug: <?php $del_id = mysql_real_escape_string($_POST['delid']); $query="DELETE FROM events WHERE CONVENTION_ID=$del_id"; mysql_query($query); // you can now see what the query is doing by echoing it out: echo $query ?> Copy the query then try running it through phpMyAdmin to see what is going on. You may find the error quicker. Quote Link to comment https://forums.phpfreaks.com/topic/125741-technical-question/#findComment-650270 Share on other sites More sharing options...
ambo Posted September 25, 2008 Author Share Posted September 25, 2008 ok it works somewhat when i type 0 it deletes all events when i type event id it doesnt dissapear is there a way that it will delete whole row? Quote Link to comment https://forums.phpfreaks.com/topic/125741-technical-question/#findComment-650604 Share on other sites More sharing options...
Maq Posted September 25, 2008 Share Posted September 25, 2008 It should delete any row (the whole row) where the id matches. Look at this tutorial: W3 Delete Quote Link to comment https://forums.phpfreaks.com/topic/125741-technical-question/#findComment-650612 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.