Crustyfur Posted May 23, 2007 Share Posted May 23, 2007 As per subject. I have a form that allows users to edit entries in the db. Thats all cool. My problem is that if any fields are left blank the form is inserting a '0' value when I need it to remain 'null'. How do I stop it inserting '0' values? Thanks in advance. <?php <input type=\"text\" name=\"ffor\" id=\"ffor\" size=\"5\"/ value=\"". $row["ffor"] ."\"> ?> Link to comment https://forums.phpfreaks.com/topic/52677-stopping-form-inserting-when-value-null/ Share on other sites More sharing options...
trq Posted May 23, 2007 Share Posted May 23, 2007 Can we see your actual query? Also, what db field types and defaults are you using? Link to comment https://forums.phpfreaks.com/topic/52677-stopping-form-inserting-when-value-null/#findComment-260035 Share on other sites More sharing options...
Crustyfur Posted May 23, 2007 Author Share Posted May 23, 2007 Here's the full job. <?php $result = $db->sql_query("UPDATE ".$prefix."_fixtures SET teamid='".forSql($_POST["teamid"])."',fdate='".forSql($_POST["fdate"])."', ftimeid='".forSql($_POST["ftimeid"])."', fopp='".forSql($_POST["fopp"])."', ftid='".forSql($_POST["ftid"])."', ffor='".forSql($_POST["ffor"])."', fagg='".forSql($_POST["fagg"])."' WHERE fid ='$fid'"); if($result) { echo "This fixture has been succesfully updated. I hope you won! "; } else { echo "<b>There has been an error adding the fixture!</b>"; print_r($db->sql_error($result)); } } list($fid,$teamid,$fdate,$ftimeid,$fopp,$ffor,$fagg,$ftid) = $db->sql_fetchinto("SELECT fid, teamid, fdate, ftimeid, fopp, ffor, fagg, ftid FROM ".$prefix."_fixtures WHERE fid= '$fid'"); echo "<br /><fieldset><legend>Edit Fixtures & Results</legend>"; $teams="<option> -- Select a Team --</option>"; $result = $db->sql_query("SELECT * FROM hh_teams ORDER BY teamid ASC"); while($row = $db->sql_fetchrow($result)) { $selected=""; if($row["teamid"]==$teamid) $selected = " selected=\"selected\""; $teams.="<option$selected value=\"".$row["teamid"]."\">".$row["team"]."</option>"; } $fixturetime="<option> -- Select a Time --</option>"; $result = $db->sql_query("SELECT * FROM hh_fixtures_time ORDER BY ftime ASC"); while($row = $db->sql_fetchrow($result)) { $selected=""; if($row["ftimeid"]==$ftimeid) $selected = " selected=\"selected\""; $fixturetime.="<option$selected value=\"".$row["ftimeid"]."\">".$row["ftime"]."</option>"; } $fixturetype="<option> -- Select a Fixture Type --</option>"; $result = $db->sql_query("SELECT * FROM hh_fixtures_type ORDER BY ftid ASC"); while($row = $db->sql_fetchrow($result)) { $selected=""; if($row["ftid"]==$ftid) $selected = " selected=\"selected\""; $fixturetype.="<option$selected value=\"".$row["ftid"]."\">".$row["ftype"]."</option>"; } $result = $db->sql_query("SELECT * FROM ".$prefix."_fixtures WHERE fid ='$fid'"); if($row = $db->sql_fetchrow($result)) { echo "$status<form action=\"$nukeurl/admin/?op=editfixture&fid=". $row[0] ."\" method=\"post\"> <br /> <center><b>This page allows you to edit fixtures & results.</b></center><br /><br /> <table width=\"100%\"> <tr><td align=\"right\"><b>Team: </b></td><td> <select id=\"teamid\" name=\"teamid\">$teams</select> <a href=\"http://www.heathhoops.com/admin/?op=addteam\">Add a New Team</a> </td></tr> <tr><td width=\"50%\" align=\"right\"><b>Date (YYYY-MM-DD): </b></td><td width=\"50%\" ><input type=\"text\" name=\"fdate\" id=\"fdate\" size=\"30\"/ value=\"". $row["fdate"] ."\"></td></tr> <tr><td align=\"right\"><b>Time: </b></td><td> <select id=\"ftimeid\" name=\"ftimeid\">$fixturetime</select> <a href=\"http://www.heathhoops.com/admin/?op=addtime\">Add a Time</a> </td></tr> <tr><td width=\"50%\" align=\"right\"><b>Opposition: </b></td><td width=\"50%\" ><input type=\"text\" name=\"fopp\" id=\"fopp\" size=\"30\"/ value=\"". $row[4] ."\"></td></tr> <tr><td align=\"right\"><b>Fixture Type: </b></td><td> <select id=\"ftid\" name=\"ftid\">$fixturetype</select> </td></tr> <tr><td align=\"right\"><b>Heath Hoops Score: </b></td><td><input type=\"text\" name=\"ffor\" id=\"ffor\" size=\"5\"/ value=\"". $row[5] ."\"></td><tr> <tr><td align=\"right\"><b>Opposition Score: </b></td><td><input type=\"text\" name=\"fagg\" id=\"fagg\" size=\"5\"/ value=\"". $row[6] ."\"></td><tr> <tr><td height=\"10\" colspan=\"2\"></td></tr> <tr><td align=\"center\" colspan=\"2\"><input type=\"submit\" name=\"savebutton\" value=\"Save Fixture\" /></td></tr> </table> </form></fieldset>"; ?> Link to comment https://forums.phpfreaks.com/topic/52677-stopping-form-inserting-when-value-null/#findComment-260038 Share on other sites More sharing options...
trq Posted May 23, 2007 Share Posted May 23, 2007 And your field types / defaults are? Link to comment https://forums.phpfreaks.com/topic/52677-stopping-form-inserting-when-value-null/#findComment-260043 Share on other sites More sharing options...
marcus Posted May 23, 2007 Share Posted May 23, 2007 Just so something as so: <?php if(!$_POST[ffor]){ echo "ffor has no value"; }else { //query } ?> Link to comment https://forums.phpfreaks.com/topic/52677-stopping-form-inserting-when-value-null/#findComment-260047 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.