Jump to content

Genesis5150

New Members
  • Posts

    8
  • Joined

  • Last visited

Genesis5150's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for the advice I went on and tried this but no luck: if (obj.office && obj.office.length < 3) { if (valid) document.listingform.office.focus(); document.listingform.office.style.border="solid 1px red"; msg+="\"Office\" field cannot contain less than three characters\n"; valid = false; }
  2. Sorry for the misunderstanding. What I'm trying to look for is a code that only works if there a value to that field. If a value has been posted then make sure it is not less than 3 characters. No error messages are displayed if it is empty and only display an error message if the value of that field is less than 3 characters if posted.
  3. Now that I'm thinking about it I'm trying to use !empty() to first check if it is empty and then do a check if there is a value to make sure the value is not less than 3 characters. This is what I have: if (empty($_POST['office'])) { $doNotSubmit = true; } // IF THE FORM FIELD IS TOO SHORT elseif (strlen($_POST['office']) < 3 ) { $fielderror .="\"Office\" field cannot contain less than three characters<br>"; $doNotSubmit = true; } But the code above didn't work. Thanks
  4. I'm looking for a solution for the javascript version of if isset in php. This is what I have: if (typeof obj.office !='') {( document.listingform.office.value.length < 3 ); { if (valid) document.listingform.office.focus(); document.listingform.office.style.border="solid 1px red"; msg+="\"Office\" field cannot contain less than three characters\n"; valid = false; } } What I want to to do is if the field "office" holds a value and is less than three characters then alert but only if it has a value. How can I do that.
  5. I want a php verification only if a value is submitted in a field and if so to make sure it has less than 3 characters. This what I have which checks if it has less than 3 characters but not sure how to only trigger if a value has been submitted. Thanks if (( strlen($_POST['office']) < 3 ) ){ $fielderror .="\"Office\" field cannot contain less than three characters<br>"; $doNotSubmit = true; }
  6. Thanks everyone for the help also the syantax error was fixed by changing it to this: $insert_row = $conn->query("INSERT INTO bookings (username, title, percent, spots, mini, cancel, start, finish, date_created) VALUES ('".$username."','".$title."','".$percent."','".$spots."','".$mini."','".$cancel."','".$start."','".$finish."', NOW())"); Alo thanks jcbones!
  7. Ok so I changed my code to fit MySQLi to this: error_reporting(E_ALL); if(isset($_POST['submit'])) { $fielderror = ""; if( $_POST["percent"] == "" || $_POST["spots"] == "" || $_POST["cancel"] == "" || $_POST["mini"] == "" || $_POST["start"] == "" || $_POST["finish"] == ""){ $fielderror="Please fill the fields annotated with an asterisk<br>"; $doNotSubmit = true; } if( !is_numeric($_POST["percent"]) /*!(preg_match('#^\d+(\.(\d{2}))?$#',($_POST["amount"])))*/ ){ $fielderror="Only Numbers In The Deposit Field"; $doNotSubmit = true; } if( $_POST['spots'] != "" ){ if (!is_numeric($_POST['spots'])) { $fielderror .="Only Numbers In The Spots Field"; $doNotSubmit = true; } } if( $_POST['cancel'] != "" ){ if (!is_numeric($_POST['cancel'])) { $fielderror .="Only Numbers In The Cancelation Field"; $doNotSubmit = true; } } if( $_POST['mini'] != "" ){ if (!is_numeric($_POST['mini'])) { $fielderror .="Only Numbers In The Minimum Stay Field"; $doNotSubmit = true; } } if( $doNotSubmit == false ) { $dbhost = 'localhost'; $dbuser = '####'; $dbpass = '####'; $dbname = '####'; // Database name $tbl_name = 'bookings'; // Table name $conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname); $username = $_SESSION["class"]["username"]; // check connection if ($conn->connect_error) { trigger_error('Database connection failed: ' . $conn->connect_error, E_USER_ERROR); } $title = mysqli_real_escape_string($conn, $_POST['title']); $percent = mysqli_real_escape_string($conn, $_POST['percent']); $spots = mysqli_real_escape_string($conn, $_POST['spots']); $mini = mysqli_real_escape_string($conn, $_POST['mini']); $cancel = mysqli_real_escape_string($conn, $_POST['cancel']); $start = mysqli_real_escape_string($conn, $_POST['start']); $finish = mysqli_real_escape_string($conn, $_POST['finish']); $insert_row = $conn->query("INSERT INTO bookings (username, title, percent, spots, mini, cancel, start, finish, date_created) VALUES ('".$username."','".$title."','".$percent."','".$spots."','".$mini."','".$cancel."','".$start."','".$finish."', NOW(), ')"); if($insert_row){ print 'Success! <br />'; }else{ die('Error This happen : ('. $conn->errno .') '. $conn->error); } } } ?> But now I'm getting this error: Notice: Undefined variable: doNotSubmit in C:\xampp\htdocs\user\booki ng\index.php on line 38 Error This happen : (1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '')' at line 1
  8. Could someone please help me. I can't figure out why this code is not inserting into the database. All the values are filled in. Thanks <?php error_reporting(E_ALL); if(isset($_POST['submit'])) { $fielderror = ""; if( $_POST["percent"] == "" || $_POST["spots"] == "" || $_POST["cancel"] == "" || $_POST["start"] == "" || $_POST["finish"] == ""){ //$errorTrace .= "after <br>"; $fielderror="Please fill the fields annotated with an asterisk<br>"; $doNotSubmit = true; } if( !is_numeric($_POST["percent"]) /*!(preg_match('#^\d+(\.(\d{2}))?$#',($_POST["amount"])))*/ ){ $fielderror="Only Numbers In The Deposit Field"; $doNotSubmit = true; } if( $_POST['spots'] != "" ){ if (!is_numeric($_POST['spots'])) { $fielderror .="Only Numbers In The Spots Field"; $doNotSubmit = true; } } if( $_POST['cancel'] != "" ){ if (!is_numeric($_POST['cancel'])) { $fielderror .="Only Numbers In The Cancelation Field"; $doNotSubmit = true; } } if( $doNotSubmit == false ) { $bd = mysql_connect("localhost","####_####","####"); if (!$bd){die('Could not connect: ' . mysql_error());} mysql_select_db("####",$bd); $username = $_SESSION["class"]["username"]; $sql = "INSERT INTO bookings (username, title, percent, spots, mini, cancel, start, finish, date_created) VALUES ('".$username."', '".mysql_real_escape_string($_POST['title'])."', '".mysql_real_escape_string($_POST['percent'])."', '".mysql_real_escape_string($_POST['spots'])."', '".mysql_real_escape_string($_POST['mini'])."', '".mysql_real_escape_string($_POST['cancel'])."', '".mysql_real_escape_string($_POST['start'])."', '".mysql_real_escape_string($_POST['finish'])."', NOW(), ')"; if(mysqli_query($bd, $sql)){ echo "Records added successfully."; } else{ echo "ERROR: Could not able to execute $sql. " . mysqli_error($bd); } // Close connection mysqli_close($link); } } ?> The Form: <form action="index.php" id="dates" method="post" name="dates" class="sky-form" onSubmit="return Blank_TextField_Validator()" enctype='multipart/form-data' /> <div class="row"> <fieldset> <section class="col col-6"> <span style="background-color:#0000cd; font-size:16px; color:white; padding:5px;">Select Unit</span> <label class="select"> <?php $sql = "SELECT * FROM units WHERE `username` = '".$_SESSION['class']['username']."'ORDER BY date_created DESC"; $result = mysql_query($sql); echo "<select name='title'>"; while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['title'] . "'>" . $row['title'] . "</option>"; } echo "</select>"; ?> <i></i> </label> </section> </div> <div class="row"> <section class="col col-3"> <span style="background-color:#0000cd; font-size:16px; color:white; padding:5px;">*Percentage of Deposit</span> <label class="input"> <i class="icon-prepend fa fa-bar-chart-o"></i> <input type="text" name="percent" id="percent" placeholder="100%" value="<?php print isset($_POST['percent']) ? strip_tags($_POST['percent']) : ""; ?>"> </label> </section> </div> <div class="row"> <section class="col col-2"> <span style="background-color:#0000cd; font-size:16px; color:white; padding:5px;">*How Many Spots?</span> <label class="input"> <i class="icon-prepend fa fa-bed"></i> <input type="text" name="spots" id="spots" placeholder="Available Spots" value="<?php print isset($_POST['spots']) ? strip_tags($_POST['spots']) : ""; ?>"> </label> </section> <section class="col col-2"> <span style="background-color:#0000cd; font-size:16px; color:white; padding:5px;">*Minimum Days?</span> <label class="input"> <i class="icon-prepend fa fa-calendar-o"></i> <input type="mini" name="mini" id="mini" placeholder="Minimum" value="<?php print isset($_POST['mini']) ? strip_tags($_POST['mini']) : ""; ?>"> </label> </section> <section class="col col-4"> <span style="background-color:#0000cd; font-size:16px; color:white; padding:5px;">*How Many Days Before Cancellation?</span> <label class="input"> <i class="icon-prepend fa fa-times"></i> <input type="text" name="cancel" id="cancel" placeholder="Days Before Cancellation" value="<?php print isset($_POST['cancel']) ? strip_tags($_POST['cancel']) : ""; ?>"> </label> </section> </div> <div class="row"> <section class="col col-2"> <span style="background-color:#0000cd; font-size:16px; color:white; padding:5px;">*Select Start Date</span> <label class="input"> <i class="icon-prepend fa fa-calendar"></i> <input type="text" name="start" id="start" placeholder="Start date" value="<?php print isset($_POST['start']) ? strip_tags($_POST['start']) : ""; ?>"> </label> </section> <section class="col col-2"> <span style="background-color:#0000cd; font-size:16px; color:white; padding:5px;">*Select Finish Date</span> <label class="input"> <i class="icon-prepend fa fa-calendar"></i> <input type="text" name="finish" id="finish" placeholder="Finish date" value="<?php print isset($_POST['finish']) ? strip_tags($_POST['finish']) : ""; ?>"> </label> </section> </div> </fieldset> <footer> <button input name='submit' type='submit' value='submit' class="button">Submit</button> </footer> </form>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.