Jump to content

saw

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Posts posted by saw

  1. I did not write that code myself, I use dreamweaver or rather I am trying to learn to use dreamweaver...I just started on this whole learn mysql php html project 3 days ago...I just want to learn enough to do this one project(or at least thats how it starts lol)

     

    I have been trying to use the code sample you provided, but just cant seem to figure it out.

    I have tried pasting it after the first instance of dob, I have tried pasting it in the form directly after dob and I have tried top and bottom of the page but nothing seems to work :(

     

    Thank you for your patience, sorry I am so new to this.

  2. willpower..Perhaps I dont understand but are you saying I should use a drop down box for the dob, I dont see how that would work as I need to be able to have many years worth of dates accepted. to many options for a drop down?

     

    --

     

    GuiltyGear . Thank you for the code example. I am not sure where to add it though, I have tried adding it directly after the GetSQLValueString($_POST['Dob'], "text"), 

    but that only results in a error.

     

    thank you

    saw

  3. Hello, I working with dreamweaver on a xampp winxp machine.

    I am trying to learn mysql and php. I appreciate any advice or help anyone can give.

     

    I Have a insert record form. I would like to make sure the user inputs a date in mm-dd-yyyy format.

     

    below is the code I have for this little form so far (without validation)

    Again thank you for looking.

    Saw

     

    <?php require_once('Connections/Insert.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
    
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
    
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }
    
    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
      $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    }
    
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
      $insertSQL = sprintf("INSERT INTO litter_num (Dob, Mother, Father) VALUES (%s, %s, %s)",
                           GetSQLValueString($_POST['Dob'], "text"),
                           GetSQLValueString($_POST['Mother'], "text"),
                           GetSQLValueString($_POST['Father'], "text"));
    
      mysql_select_db($database_Insert, $Insert);
      $Result1 = mysql_query($insertSQL, $Insert) or die(mysql_error());
    }
    ?><style type="text/css">
    <!--
    .style2 {
    font-size: 36px;
    font-weight: bold;
    }
    -->
    </style>
    <div align="center"><span class="style2">Create a New Litter Number</span></div>
    <p> </p>
    
    <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
      <table align="center">
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">Dob:</td>
          <td><input type="text" name="Dob" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">Mother:</td>
          <td><input type="text" name="Mother" value="" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">Father:</td>
          <td><input type="text" name="Father" value="" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right"> </td>
          <td><input type="submit" value="Insert record" /></td>
        </tr>
      </table>
      <input type="hidden" name="MM_insert" value="form1" />
    </form>
    <p> </p>

     

     

  4. Thank you, But I really have no idea what I am doing. I have only done the one tutorial that taught me how to make the input form.

     

    Could someone perhaps show an example of how to make a form that mixes text boxes and a list/menu or help me make the appropriate edit to the above code?

     

    I kinda learn by example...thank you again

  5. I am very new to mysql, thank you in advance for any help you can give.

     

    I have just learned how to make a form to input data into a mysql table.

    I have several text boxes that input the users text into the table.

     

    Name:

    Gender:

    DOB:

    etc

     

    I am now trying to replace the text box gender with a list/menu to choose female/male.

     

    I have managed to create the dynamic list/menu inside the form, but when I click on the button to insert the record I get an error "column gender can not be null"

     

    Any help is very much appreciated

    Saw

     

    My non working code.

    <?php require_once('Connections/Insert.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
    
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
    
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }
    
    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
      $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    }
    
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
      $insertSQL = sprintf("INSERT INTO `index` (Name, Gender, DOB, Mother, Father, Coat, Color, Vocal) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
                           GetSQLValueString($_POST['Name'], "text"),
                           GetSQLValueString($_POST['Sex'], "text"),
                           GetSQLValueString($_POST['DOB'], "text"),
                           GetSQLValueString($_POST['Mother'], "text"),
                           GetSQLValueString($_POST['Father'], "text"),
                           GetSQLValueString($_POST['Coat'], "text"),
                           GetSQLValueString($_POST['Color'], "text"),
                           GetSQLValueString($_POST['Vocal'], "text"));
    
      mysql_select_db($database_Insert, $Insert);
      $Result1 = mysql_query($insertSQL, $Insert) or die(mysql_error());
    
      $insertGoTo = "cats.php";
      if (isset($_SERVER['QUERY_STRING'])) {
        $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
        $insertGoTo .= $_SERVER['QUERY_STRING'];
      }
      header(sprintf("Location: %s", $insertGoTo));
    }
    
    mysql_select_db($database_Insert, $Insert);
    $query_Gender = "SELECT Sex FROM sex";
    $Gender = mysql_query($query_Gender, $Insert) or die(mysql_error());
    $row_Gender = mysql_fetch_assoc($Gender);
    $totalRows_Gender = mysql_num_rows($Gender);
    ?>
    <form method="post" name="form1" action="<?php echo $editFormAction; ?>">
      <table align="center">
        <tr valign="baseline">
          <td nowrap align="right">Name:</td>
          <td><input type="text" name="Name" value="" size="32"></td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Gender</td>
          <td><label>
            <select name="gender" id="gender">
              <?php
    do {  
    ?>
              <option value="<?php echo $row_Gender['Sex']?>"<?php if (!(strcmp($row_Gender['Sex'], $row_Gender['']))) {echo "selected=\"selected\"";} ?>><?php echo $row_Gender['Sex']?></option>
              <?php
    } while ($row_Gender = mysql_fetch_assoc($Gender));
      $rows = mysql_num_rows($Gender);
      if($rows > 0) {
          mysql_data_seek($Gender, 0);
      $row_Gender = mysql_fetch_assoc($Gender);
      }
    ?>
            </select>
          </label></td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">DOB:</td>
          <td><input type="text" name="DOB" value="" size="32"></td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Mother:</td>
          <td><input type="text" name="Mother" value="" size="32"></td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Father:</td>
          <td><input type="text" name="Father" value="" size="32"></td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Coat:</td>
          <td><input type="text" name="Coat" value="" size="32"></td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Color:</td>
          <td><input type="text" name="Color" value="" size="32"></td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right">Vocal:</td>
          <td><input type="text" name="Vocal" value="" size="32"></td>
        </tr>
        <tr valign="baseline">
          <td nowrap align="right"> </td>
          <td><input type="submit" value="Insert record"></td>
        </tr>
      </table>
      <input type="hidden" name="MM_insert" value="form1">
    </form>
    <p> </p>
    <?php
    mysql_free_result($Gender);
    ?>
    

  6. Hello, I hope to find help here. I thank you in advance for your time and assistance.

    I am a noob

    I have installed xampp and use dreamweaver to edit mysql and php on my localhost machine.

     

    I am attempting to do this tutorial I found on the web. which is just to display the details of a table.

    http://www.nebulex.com/index.php/tutorials/dreamweaver/mysqlphp/dynamic%20Tables/46?

     

    However I am getting an error

    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\cats.php on line 25

     

    Line 25 is..

    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>

     

    here is the whole code block.

    <table border="1" cellpadding="5" cellspacing="5">
      <tr>
        <td>id</td>
        <td>Name</td>
        <td>Sex</td>
        <td>DOB</td>
        <td>Mother</td>
        <td>Father</td>
        <td>Coat</td>
        <td>Color</td>
        <td>Vocal</td>
      </tr>
      <?php do { ?>
        <tr>
          <td><?php echo $row_Recordset1['id']; ?></td>
          <td><?php echo $row_Recordset1['Name']; ?></td>
          <td><?php echo $row_Recordset1['Sex']; ?></td>
          <td><?php echo $row_Recordset1['DOB']; ?></td>
          <td><?php echo $row_Recordset1['Mother']; ?></td>
          <td><?php echo $row_Recordset1['Father']; ?></td>
          <td><?php echo $row_Recordset1['Coat']; ?></td>
          <td><?php echo $row_Recordset1['Color']; ?></td>
          <td><?php echo $row_Recordset1['Vocal']; ?></td>
        </tr>
        <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
    </table>
    <?php require_once('Connections/Insert.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
    
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
    
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }
    
    mysql_select_db($database_Insert, $Insert);
    $query_Recordset1 = "SELECT * FROM `index`";
    $Recordset1 = mysql_query($query_Recordset1, $Insert) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);
    
    mysql_free_result($Recordset1);
    ?>
    

     

    Thanks again for looking and any assistance you can give

×
×
  • 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.