pixeltrace Posted March 21, 2007 Share Posted March 21, 2007 guys, i need help i have a form that adds new job in my database my problem is if i left a field empty let say i have fields called title contact person phone contact if i left phone empty the value that is being save in my database is javascript:; how do i fix this? this is the code for my form <form action="job/addjob.php" method="post"> <table width="515" border="0" cellspacing="2" cellpadding="3"> <tr> <td colspan="3" valign="top"><img src="images/spacer.gif" width="10" height="1" /></td> </tr> <tr> <td colspan="3" bgcolor="#999999" class="text2">JOB INFORMATION</td> </tr> <tr> <td colspan="3" valign="top"><img src="images/spacer.gif" width="10" height="10" /></td> </tr> <tr> <td width="137" align="right" valign="top" class="text6">Title of the Post : </td> <td> </td> <td class="text7"><input name="jposition" type="text" size="40"></td> </tr> <tr> <td align="right" valign="top" class="text6">Client : </td> <td width="7"> </td> <td width="363"> <select name="cname"> <option value="javascript:;" selected>-- select client here --</option> <? $uSql = "SELECT client_name FROM clients"; $uResult = mysql_query($uSql, $connection); if(!$uResult){ echo 'no data found'; }else{ while($uRow = mysql_fetch_array($uResult)){ ?> <option value="<?= $uRow[client_name]?>"><?= $uRow[client_name]?></option> <? } } ?> </select></td> </tr> <tr> <td align="right" valign="top" class="text6">Contact Person: </td> <td width="7"> </td> <td><span class="text7"> <input name="cperson" type="text" size="40" /> </span></td> </tr> <tr> <td align="right" valign="top" class="text6">Specialization : </td> <td width="7"> </td> <td width="363"> <select name="specialization"> <option value="javascript:;" selected>-- select specialization here --</option> <? $uSql = "SELECT specialization FROM specialization"; $uResult = mysql_query($uSql, $connection); if(!$uResult){ echo 'no data found'; }else{ while($uRow = mysql_fetch_array($uResult)){ ?> <option value="<?= $uRow[specialization]?>"><?= $uRow[specialization]?></option> <? } } ?> </select> </td> </tr> <tr> <td align="right" valign="top" class="text6">Level : </td> <td> </td> <td> <select name="level"> <option value="javascript:;" selected>----</option> <? $uSql = "SELECT level FROM level"; $uResult = mysql_query($uSql, $connection); if(!$uResult){ echo 'no data found'; }else{ while($uRow = mysql_fetch_array($uResult)){ ?> <option value="<?= $uRow[level]?>"><?= $uRow[level]?></option> <? } } ?> </select></td> </tr> <tr> <td align="right" valign="top" class="text6">Industry : </td> <td> </td> <td> <select name="industry"> <option value="javascript:;" selected>-- select industry here--</option> <? $uSql = "SELECT industry FROM industry"; $uResult = mysql_query($uSql, $connection); if(!$uResult){ echo 'no data found'; }else{ while($uRow = mysql_fetch_array($uResult)){ ?> <option value="<?= $uRow[industry]?>"><?= $uRow[industry]?></option> <? } } ?> </select></td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align="right" valign="top" class="text6">Our Client : </td> <td> </td> <td><textarea name="cdescription" cols="50" rows="5"></textarea></td> </tr> <tr> <td align="right" class="text6"> </td> <td> </td> <td> </td> </tr> <tr> <td align="right" valign="top" class="text6">Requirements : </td> <td> </td> <td><textarea name="jrequirements" cols="50" rows="8"></textarea></td> </tr> <tr> <td align="right" class="text6"> </td> <td> </td> <td> </td> </tr> <tr> <td align="right" valign="top" class="text6">Responsibilities : </td> <td> </td> <td><textarea name="jresponsibilities" cols="50" rows="8"></textarea></td> </tr> <tr> <td align="right" class="text6"> </td> <td> </td> <td> </td> </tr> <tr> <td align="right" valign="top" class="text6">Job Type :</td> <td> </td> <td class="text3"><input type="checkbox" name="jtype1" value="Permanent" > Permanent <input type="checkbox" name="jtype2" value="Contract" /> Contract <input type="checkbox" name="jtype3" value="Part-Time" /> Part-Time </td> </tr> <tr> <td align="right" valign="top" class="text6"> </td> <td> </td> <td> </td> </tr> <tr> <td align="right" valign="top" class="text6">Salary :</td> <td> </td> <td><span class="text7"> <input type="text" name="salary" /> </span></td> </tr> <tr> <td align="right" valign="top" class="text6">Location :</td> <td> </td> <td><span class="text7"> <input name="location" type="text" size="50" /> </span></td> </tr> <tr> <td align="right" valign="top" class="text6">Country :</td> <td> </td> <td><select name="country"> <option value="">Select Location</option> <option value="Singapore">Singapore</option> <option value="Malaysia">Malaysia</option> <option value="Philippines">Philippines</option> <option value="India">India</option> <option value="Hong Kong">Hong Kong</option> <option value="">---------------------</option> <option value="North America">North America</option> <option value="Middle East">Middle East</option> <option value="Europe">Europe</option> </select></td> </tr> <tr> <td align="right" valign="top" class="text6">Opening Date :</td> <td> </td> <td> <select name="dayposted"> <option value='1'>1</option> <option value='2'>2</option> <option value='3'>3</option> <option value='4'>4</option> <option value='5'>5</option> <option value='6'>6</option> <option value='7'>7</option> <option value='8'>8</option> <option value='9'>9</option> <option value='10'>10</option> <option value='11'>11</option> <option value='12'>12</option> <option value='13'>13</option> <option value='14'>14</option> <option value='15'>15</option> <option value='16'>16</option> <option value='17'>17</option> <option value='18'>18</option> <option value='19'>19</option> <option value='20'>20</option> <option value='21'>21</option> <option value='22'>22</option> <option value='23'>23</option> <option value='24'>24</option> <option value='25'>25</option> <option value='26'>26</option> <option value='27'>27</option> <option value='28'>28</option> <option value='29'>29</option> <option value='30'>30</option> <option value='31'>31</option> </select> <select name="monthposted"> <option value='1'>Jan</option> <option value='2'>Feb</option> <option value='3'>Mar</option> <option value='4'>Apr</option> <option value='5'>May</option> <option value='6'>Jun</option> <option value='7'>Jul</option> <option value='8'>Aug</option> <option value='9'>Sep</option> <option value='10'>Oct</option> <option value='11'>Nov</option> <option value='12'>Dec</option> </select> <select name="yearposted"> <?php for($i=2001; $i<=date("Y"); $i++){ print '<option value="'.$i.'"'; if($yearText == $i){ print ' selected'; } print '>'.$i.'</option>'; } ?> </select> </td> </tr> <tr> <td align="right" valign="top" class="text6">Closing Date :</td> <td> </td> <td><select name="dayclosed"> <option value='1'>1</option> <option value='2'>2</option> <option value='3'>3</option> <option value='4'>4</option> <option value='5'>5</option> <option value='6'>6</option> <option value='7'>7</option> <option value='8'>8</option> <option value='9'>9</option> <option value='10'>10</option> <option value='11'>11</option> <option value='12'>12</option> <option value='13'>13</option> <option value='14'>14</option> <option value='15'>15</option> <option value='16'>16</option> <option value='17'>17</option> <option value='18'>18</option> <option value='19'>19</option> <option value='20'>20</option> <option value='21'>21</option> <option value='22'>22</option> <option value='23'>23</option> <option value='24'>24</option> <option value='25'>25</option> <option value='26'>26</option> <option value='27'>27</option> <option value='28'>28</option> <option value='29'>29</option> <option value='30'>30</option> <option value='31'>31</option> </select> <select name="monthclosed"> <option value='1'>Jan</option> <option value='2'>Feb</option> <option value='3'>Mar</option> <option value='4'>Apr</option> <option value='5'>May</option> <option value='6'>Jun</option> <option value='7'>Jul</option> <option value='8'>Aug</option> <option value='9'>Sep</option> <option value='10'>Oct</option> <option value='11'>Nov</option> <option value='12'>Dec</option> </select> <select name="yearclosed"> <?php for($i=2001; $i<=date("Y"); $i++){ print '<option value="'.$i.'"'; if($yearText == $i){ print ' selected'; } print '>'.$i.'</option>'; } ?> </select> </td> </tr> <tr> <td align="right" valign="top" class="text6">Status :</td> <td> </td> <td><select name="jstatus"> <option value="open" selected="selected">open</option> <option value="closed">closed</option> </select></td> </tr> <tr> <td align="right" valign="top" class="text6">Remark :</td> <td> </td> <td><textarea name="remarks" cols="50" rows="5"></textarea></td> </tr> <tr> <td rowspan="2"> </td> <td rowspan="2"> </td> <td><input type="submit" name="Submit" value="save" /> <input type="hidden" name="username" value="<? echo "$username"; ?>"> <input type=hidden value=http://www. name=redirect> </td> </tr> <tr> <td> </td> </tr> </table> </form> and this is the code for my addjob.php page <? session_start(); if (session_is_registered("username")){ }else{ echo "<font face=\"Arial\">You are not authorized to access this page ... Please <a href='../index.php'>Login</a></font>"; } include '../db_connect.php'; $jposition = $_POST['jposition']; $cname = $_POST['cname']; $cperson = $_POST['cperson']; $specialization = $_POST['specialization']; $level = $_POST['level']; $industry = $_POST['industry']; $cdescription = $_POST['cdescription']; $jrequirements = $_POST['jrequirements']; $jresponsibilities = $_POST['jresponsibilities']; $jtype1 = $_POST['jtype1']; $jtype2 = $_POST['jtype2']; $jtype3 = $_POST['jtype3']; $salary = $_POST['salary']; $location = $_POST['location']; $country = $_POST['country']; $dayposted = $_POST['dayposted']; $monthposted = $_POST['monthposted']; $yearposted = $_POST['yearposted']; $dayclosed = $_POST['dayclosed']; $monthclosed = $_POST['monthclosed']; $yearclosed = $_POST['yearclosed']; $jstatus = $_POST['jstatus']; $remarks = $_POST['remarks']; $username = $_POST['username']; //0000-00-00 $dateposted = $yearposted.'-'.$monthposted.'-'.$dayposted; $dateclosed = $yearclosed.'-'.$monthclosed.'-'.$dayclosed; $jposition = stripslashes($jposition); $cname = stripslashes($cname); $cperson = stripslashes($cperson); $specialization = stripslashes($specialization); $level = stripslashes($level); $industry = stripslashes($industry); $cdescription = stripslashes($cdescription); $jrequirements = stripslashes($jrequirements); $jtype1 = stripslashes($jtype1); $jtype2 = stripslashes($jtype2); $jtype3 = stripslashes($jtype3); $salary = stripslashes($salary); $location = stripslashes($location); $country = stripslashes($country); $dayposted = stripslashes($dayposted); $monthposted = stripslashes($monthposted); $yearposted = stripslashes($yearposted); $dayclosed = stripslashes($dayclosed); $monthclosed = stripslashes($monthclosed); $yearclosed = stripslashes($yearclosed); $jstatus = stripslashes($jstatus); $remarks = stripslashes($remarks); $username = stripslashes($username); // --- for the company logo //if ($clientImage == '$EventImage') {$clientImageLink = '2';} // else {$clientImageLink = '1';} $sql = mysql_query("INSERT INTO job_ads (c_name, cperson, c_description, j_position, j_responsibilities, j_requirements, industry, specialization, level, j_type1, j_type2, j_type3, location ,country, salary, j_status, remarks, date_posted, date_closed, staff_created ) VALUES('$cname', '$cperson', '$jdescription', '$jposition', '$jresponsibilities', '$jrequirements', '$industry', '$specialization', '$level', '$jtype1', '$jtype2', '$jtype3', '$location', '$country', '$salary', '$jstatus', '$remarks', '$dateposted', '$dateclosed', '$username')") or die (mysql_error()); if(!$sql){ echo '<script language=javascript> alert("Error adding client");top.location = "../jobmngr.php?id=1";</script>'; exit(); } else { $jobid = mysql_insert_id(); echo '<script language=javascript> alert("New Job has been added by '.$username.'!");top.location = "../jobmngr.php?id=2&type=1";</script>'; } ?> hope you could help me with this. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/43609-problem-in-my-add-form/ Share on other sites More sharing options...
skali Posted March 21, 2007 Share Posted March 21, 2007 That is the value that you are sending when some select box is sent empty. Why are you setting javsscript: as the value in your select lists? Just leave the value empty. [b]instead of[/b] <select name="cname"> <option value="javascript:;" selected>-- select client here --</option> [b]TO[/b] <select name="cname"> <option value="" selected>-- select client here --</option> Quote Link to comment https://forums.phpfreaks.com/topic/43609-problem-in-my-add-form/#findComment-211878 Share on other sites More sharing options...
Iceman512 Posted March 21, 2007 Share Posted March 21, 2007 Hi there, As Scali said, if you don't enter data in the field, it is taking the 'value' attribute and entering the data it contains into the database. In your case, the value field is set to 'javascript:'. Just leave the value="" attribute empty and it won't submit any data if the field is left empty. Regards, Iceman Quote Link to comment https://forums.phpfreaks.com/topic/43609-problem-in-my-add-form/#findComment-211894 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.