Jump to content
Larry Ullman's Book Forums

chuflasky

Members
  • Posts

    40
  • Joined

  • Last visited

Posts posted by chuflasky

  1. Hi jeremy126, i have a question. How are you inserting the data.

    $e= mysqli_real_escape_strim($dbc,trim(POST[emailm]) ); or 

    are you using  preg_match() function

    $trimmed = array_map('trim',$_ POST);
     preg_match('/^A-Z\'.-]{2,20}$/i', $trimmed['$e]);

    just for curiosity.Because it seems that if you have a successful registration then the error is the way you are retrieving the data.  

  2. Thanks guys for you help is working fine now my problem was that i was closing the condition before the <option> for example

     $month = array(1 =>'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'Octuber', 'November', 'December');
    echo '<select name="event_month" id="a_place"   >';
    echo'<option value="0">Month</option>';
    
    foreach($month as $key =>$value){
     echo "<option value=\"$value\">$value</option>
    }
    if($_POST['event_month']) =="$value"){
    echo 'selected="selected" ';
    }
    echo"</selected>";
    

     

    and the correct way that actually works is

      $month = array(1 =>'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'Octuber', 'November', 'December');
       //make the month pulldown menu
       echo '<select name="expire_month" id="expire">';
       echo"<option value='0'>Exp-Month</option>";
    		  foreach($month as $key => $value){
      echo "<option value=\"$value\" ";
    
     if($_POST["expire_month"] == "$value"){
      echo 'selected ="selected" ';
     }
     echo"> $value</option>";
     } //end of foreach
       echo '</select>';
    
    

    as you can see the all of the argument are inside the foreach loop that was the difference. Thanks Edward looking at your code i figure it out. The same code work for the day and year.

     echo '<select name="expire_day" id="expire">';
       echo"<option value='0'>Exp-Day</option>";
       for($day= 1; $day<=31; $day++){
      echo "<option value=\"$day\" ";
    
     if($_POST["expire_day"] == "$day"){
      echo 'selected = "selected" ';
     }
     echo ">$day</option>\n";
     }
     echo '</select>';
    

     

    and year

    echo '<select name="expire_year" id="expire">';
     echo"<option value='0'>exp-Year</option>";
     for($year = 2011; $year<=2016; $year++){
      echo "<option value=\"$year\" ";
    
     if($_POST["expire_year"] == "$year"){
      echo 'selected = "selected" ' ;
     }
     echo " >$year</option>"  ;
     }
       echo '</select>';
    

    Thanks guys.

  3. Thanks Larry / Edward for your quick respond, Well i tried to put the sticky code at the at the <select> input to make sticky but for some reason after i submit the form it hold no value. Here is how i'm making my input to make it sticky

    echo '<select name="event_month" id="a_place"  value=\"<?php if(isset($_POST['event_month'])) echo $_POST['event_month'];?>\">';
    

    everything else is working find but just the sticky part.

  4. Hi, i created a function for a pull down selection date just like in script 3.7 but where in the code do i should put the code to make it sticky, i already tried

    function event_date($value,$day, $year){
    
    /*echo'<script type="text/javascript" src="../js/jQuery_v1.4.4.js"> </script>';
       echo'<script type="text/javascript" src="../js/upload_js.js"></script>';
    */
    //make the month //
    $month = array(1 =>'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'Octuber', 'November', 'December');
    echo '<select name="event_month" id="a_place" value=\"<?php if (isset($_POST['event_month'])) echo $_POST['event_month'];\"
    >';
    
    echo'<option value="0">Month</option>';
    
    foreach($month as $key =>$value){
     echo "<option value=\"$key\">$value</option>";
    }
    if($_POST["event_month"] == "$value"){
     echo  'selected = "selected" ';
    
    }
    if(isset($value)) echo "$value";
     echo '</select>';
    	  // make the days
    echo '<select name=\"event_day\" id=\"a_place\"  >';
    echo '<option value="0">Day</option>';
    for($day=1; $day<=31; $day++){
    
     echo "<option value=\"$day\">$day </option>";
    
    }
    if($_POST["event_day"] == "$day"){
     echo 'selected = "selected" ';
    }else if( $month==2){
     for( $day=1; $day<=29; $day++){
      echo "<option value=\"$day\">$day</option>";
     }//end of for loop
    }// end of elseif
    if(isset($_POST['event_day']) ) echo $_POST['event_day'];
    
    echo '</select>';
    
    //make the year
    echo '<select name="event_year" id="a_place">';
    echo '<option value="0">Year</option>';
    for($year = 2011; $year<=2020; $year++){
     echo "<option value=\"$year\">$year</option>";
    }
    if($_POST["event_year"] == "$year"){
     echo 'selected = "selected" ';
    }
    echo '</select>';
    return TRUE;
    }//end of event_date function
    

     

    and it not working for me. Thanks

  5. OK, i have my function working now. The problem that i'm having now is that i can rip off the default value that in my case is the beginning of the date function that is "jan 1 12". I want the function to have a default value of a blank or 0 because right now the code always execute due to the default value. How can i alter my code in the function that it would print a blank at the option value. Can that be done or i would have to do it manually example

    <option>month</option><option value ='1'>jan</option>//and  so on
    <option>day</option><option value='1'>1</option> //and so  on
    <option>year</option><option value='12'>12</option>// an so on
    

     

    The following code is what i have now.

    //MAKE THE DATE PULL DONWN MENU//
    function event_date($event_month, $event_day, $event_year){
    
    //make the month //
    $month = array(1 =>'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'Octuber', 'November', 'December');
    echo '<select name="event_month">';
    foreach($month as $key =>$value){
     echo "<option value=\"$key\">$value</option>";
    
    }
    if($_POST["event_month"] == "$value"){
     echo 'selected = "selected" ';
    }
     echo '</select>';
    	  // make the days
    echo '<select name="event_day">';
    for($day=1; $day<=31; $day++){
     echo "<option value=\"$day\">$day</option>";
    }
    if($_POST["event_day"] == "$day"){
     echo 'selected = "selected" ';
    }else if( $month[2] == "selected"){
     for( $day=1; $day<=29; $day++){
      echo "<option value=\"$day\">$day</option>";
     }//end of for loop
    }// end of elseif
    
    echo '</select>';
    
    //make the year
    echo '<select name="event_year">';
    for($year = 2011; $year<=2020; $year++){
     echo "<option value=\"$year\">$year</option>";
    }
    if($_POST["event_year"] == "$year"){
     echo 'selected = "selected" ';
    }
    echo '</select>';
    return TRUE;
    
    }//end of event_date function
    
    // MAKE THE EXPIRATION PULL-DOWN MENU//
    function expiration($expire_month, $expire_day, $expire_year){
    
       $month = array(1 =>'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'Octuber', 'November', 'December');
       //make the month pulldown menu
       echo '<select name="expire_month" id="expire">';
    		  foreach($month as $key => $value){
      echo "<option value=\"$key\"> $value</option>";
     }
     if($_POST["expire_month"] == "$value"){
      echo 'selected ="selected" ';
     }
       echo '</select>';
    
       echo '<select name="expire_day" id="expire">';
       for($day= 1; $day<=31; $day++){
      echo "<option value=\"$day\">$day</option>\n";
     }
     if($_POST["expire_day"] == "$day"){
      echo 'selected = "selected" ';
     }
     echo '</select>';
    
     // MAKE  THE YEAR PULL-DOWN
     echo '<select name="expire_year" id="expire">';
     for($year = 2011; $year<=2016; $year++){
      echo "<option value=\"$year\" >$year</option>";
     }
     if($_POST["expire_year"] == "$year"){
      echo 'selected = "selected" ' ;
     }
       echo '</select>';
       return TRUE;
    }//end of expiration
    

     

    And the from where i call the function this what i have

     

    <p>
        <label for="date" class="label">Date:</label>
    	 <? event_date($_POST["event_month"], $_POST["event_day"], $_POST["event_year"]);?>
    	  </p>
    <p>
    	 <label for="expire_date" class="label">Expire Date:</label>
    		 <?php    expiration( $_POST["expire_month"], $_POST["expire_day"], $_POST["expire_year"]);  ?> 
    
       </p>
    

     

    Thanks.

    • Upvote 1
  6. Hi, i just create a function to to create a drop drop down input field in which allow the user to select a particular date, but how do i retrieve the date chosen by the user. This is the code that i have to to create the input field in the form.

     

     

    //MAKE THE DATE PULL DONWN MENU//
    function event_date($event_month, $event_day, $event_year){
    //make the month //
    $month = array(1 =>'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'Octuber', 'November', 'December');
    echo '<select name="$event_month">';
    foreach($month as $key =>$value){
    echo "<option value=\"$key\">$value</option>";}
    if($_POST["$event_month"] == "$event_month"){
    echo 'selected = "selected" ';
    }
    echo '</select>';
        // make the days
    echo '<select name="$event_day">';
    for($day=1; $day<=31; $day++){
    echo "<option value=\"$day\">$day</option>";
    }
    if($_POST["$event_day"] == "$event_day"){
    echo 'selected = "selected" ';
    }else if( $month[2] == "selected"){
    for( $day=1; $day<=29; $day++){
    echo "<option value=\"$day\">$day</option>";
    }//end of for loop
    }// end of elseif
    echo '</select>';//make the year
    echo '<select name="$event_year">';
    for($year = 2011; $year<=2020; $year++){
    echo "<option value=\"$year\">$year</option>";
    }
    if($_POST["$event_year"] == "$event_year"){
    echo 'selected = "selected" ';
    }
    echo '</select>';
    return TRUE;
    }//end of event_date function
    // MAKE THE EXPIRATION PULL-DOWN MENU//
    function expiration($expire_month, $expire_day, $expire_year){
    
    $month = array(1 =>'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'Octuber', 'November', 'December');
    //make the month pulldown menu
    echo '<select name="$expire_month" id="expire">';
    	   foreach($month as $key => $value){
    echo "<option value=\"$key\">$value</option>";
    }
    if($_POST["$expire_month"] == "$expire_month"){
    echo 'selected ="selected" ';
    }
    echo '</select>';
    echo '<select name="$expire_day" id="expire">';
       for($day= 1; $day<=31; $day++){
     echo "<option value=\"$day\">$day</option>\n";
     }
     if($_POST["$expire_day"] == "$expire_day"){
     echo 'selected = "selected" ';
     }
     echo '</select>';// MAKE  THE YEAR PULL-DOWN
    echo '<select name="$expire_year" id="expire">';
    for($year = 2011; $year<=2016; $year++){
    echo "<option value=\"$year\" >$year</option>";
    }
    if($_POST["$expire_year"] == "$year"){
    echo 'selected = "selected" ' ;
    }
    echo '</select>';
    return TRUE;
    }//end of expiration
    include("../include/footer.html"); 
    

     

    and this code below retrieve the date chosen by the user which i think is not working.

     

      //			 // EVENT DATE //				  //
    require_once("post_events.php");
    
    if(empty($_POST["$event_month"]) && empty($_POST["$event_day"]) && empty($_POST["$event_year"])){
    	    $errors[] = '<p class="error"> - Please enter the event date.</p>';
    }else{
    		  $date_month = $_POST["$event_month"];
     $date_day = $_POST["$event_day"];
     $date_year = $_POST["$event_year"];
     $date = $date_year . '-' . $date_month . '-'. $date_day ;
    }
    	   //	 expiration date //
    if( $_POST['place'] == 'onetime' && empty($_POST["$expire_month"]) && empty($_POST["$expire_day"]) && empty($_POST["$expire_year"]) ){
    	   $errors[] = '<p class="error"> - Plese enter the expiration date.</p>';
    }else{
    	   $m = $_POST["$expire_month"];
     $d = $_POST["$expire_day"];
     $y = $_POST["$expire_year"];
     $expiry_date = $y .'-'.$m.'-'.$d ;
    
    }
    

  7. Hi all.

    I'm being working on an insert query using prepare statement to store information retrieve from the user. this are the query that i'm using.

    $q = " INSERT INTO author(author_name) VALUES(?)";
    $stmt = mysqli_prepare($dbc, $q);
    mysqli_stmt_bind_param($stmt,'s', $author);
    $author_id = mysqli_insert_id($dbc);
    
    //            //                 //         //         
    $q = " INSERT INTO categories( category_name) VALUES(?)";
    $stmt = mysqli_prepare($dbc, $q);
    mysqli_stmt_bind_param($stmt, 's', $category);
    $category_id = mysqli_insert_id($dbc);
    
    
    ///        ///                ///              ///
    $q = "INSERT INTO titles(title, user_id, category_id) VALUES(?,?,?)";
    $stmt = mysqli_prepare($dbc, $q);
    mysqli_stmt_bind_param($stmt,'s,i,i', $title, $user_id, $category_id);                  //Line 289
    mysqli_stmt_execute($stmt) or die ("Error: " . mysqli_stmt_error($stmt) );            
    $title_id = mysqli_insert_id($dbc);
    

     

     

    For me everything look fine, but i getting the following error.

     

    Warning: mysqli_stmt_bind_param() [function.mysqli-stmt-bind-param]: Number of elements in type definition string doesn't match number of bind variables inC:\xampp\htdocs\index2\user_php\upload.php on line 289Error: No data supplied for parameters in prepared statement

    Can any one tell me what i doing wrong here. I suspect that mysqli_insert_id is causing the problem because i might no generating a id yet since the statement get execute down further the script.

     

     

  8. Hi bahaa, i'm not sure is this is what you are looking for but give a try.

       $q = " SELECT username FROM users WHERE username = ? ";
                 $stmt = mysqli_prepare ($con, $q);
                 mysqli_stmt_bind_param($stmt, 's', $username);
               mysqli_stmt_execute($stmt);
    if(mysqli_stmt_num_rows($stmt) != 0){
             echo "<p class='error'> The username you have chosen is already taken.</p>";
    }else{
                              //something else 
    }
    

     

    Hope this help or get you on the right track.

  9. Hi Ryan, it look like you are sending something to the browser before the session_start() function. Remember you can not have any space at the beginning of the of your page tags, HTML, PHP. Go to

    /home/ryandivi/public_html/template-registration/includes/config.inc.php:69  

    and see if there is a white space at the beginning of the you HTML tag or PHP tag and if there aren't none it could be your php.ini configuration. There are two different php.ini file, development and production environment. The production environment is what you want in when you move your site to you server.

    • Upvote 1
  10. Problem solved. I created three different HTML input to retrieve the value from each one individually for the month, day, and year.

    <p>
    
    <label for="expire_date" class="label">Expiry Date:</label>        
           <input type="text" name="month" size="1" maxlength="2" id="expire" value="<?php if(isset($_POST['month'])) echo $_POST['month']; ?>" /> /
           <input type="text" name="day" size="1" maxlength="2" id="expire" value="<?php if(isset($_POST['day'])) echo $_POST['day']; ?>"  /> /
           <input type="text" name="year" size="2" maxlength="4" id="expire" value="<?php if(isset($_POST['year'])) echo $_POST['year']; ?>"  /> mm/dd/yyyy
    </p>
    

     

    Now after retrieving the value from each HTML input, it get store into each variable individually.

    
    }elseif($_POST['place'] == 'onetime' && !empty($_POST['month']) && !empty($_POST['day']) && !empty($_POST['year'])  ){
    $m =  $_POST['month'];
    $d =  $_POST['day'];
    $y =  $_POST['year'];
    $exp = $y .'-' . $m .'-'. $d ;
    }
    
    
    if(empty($_POST['month']) && empty($_POST['day']) && empty($_POST['year']) ){
         $errors[] ="<p class='error'>Please enter the date fo this event.</p>";
    }elseif(!empty($_POST['month']) && !preg_match('/^([\d]{2})$/', $_POST['month']) ||  !empty($_POST['day']) && !preg_match('/^([\d]{2})$/', $_POST['day']) || !empty($_POST['year']) && !preg_match('/^([\d]{4})$/', $_POST['year']) ){
    $errors[] = "<p class='error'>Please enter the date in a valid format, e.g. (5/10/2015).</p>";
    }
    

    This is just part of my code, but so far i getting the result that i want. As you can see the variable $exp get the value from $m, $d, $y. Another point is that it get validated trough PCRE and beside the PCRE validation the HTML input maxlength allow me to dictate how many characters i allow. So i have to agree with antonio conte about using the three HTML input. Thanks all you guys for your help.

    • Upvote 1
  11. Thanks stuart for you approach, you right when you said that if i don't want to rely on javascript i can use dropdowns for the date, but i was thinking more like getting tree different variable e.g $m, $d, $y, then combine the tree variable into one $formatted_date = $m.$d.$y;. then make the insert query. I haven't try it yet, going to work on it. Thanks guys, your help is much appreciated.

  12. Thanks HarletSan for your insight, that is exactly what i trying to do, to insert the date in a default format, and you right Larry suggest the same in the book. But that where i having all my problems cause i allow the user to enter the date in tree different format that is e.g 12/10/2011 - 12-10-2011 - 12.10.2011 and when i try to insert the date into the database ("INSERT INTO events(expiry_date) VALUE($exp) " ) without formatting it, the column field just get 0000-00-00. So like stuart said a the beginning " If 0's are getting stored it simply means that the value you tried to enter into the field did not conform to the correct format " this mean, it has to be formatted before being inserted. Thank HartleSan.

×
×
  • Create New...