Jump to content

adam84

Members
  • Posts

    289
  • Joined

  • Last visited

Posts posted by adam84

  1. Between:

    INSERT INTO tbl_auth_user SET user_id='$user_id', user_password='$user_password' , ID = '3'

     

    and:

    INSERT INTO tbl_auth_user (user_id, user_password) VALUES ('user', PASSWORD('password'))

     

    I don't think the first example would work because you use the 'SET' keyword to update a table rather then to insert something into a table.

    UPDATE tbl_auth_user SET user_id='$user_id', user_password='$user_password' WHERE ID = '3'
    

    You code would work, but since you dont have a WHEREclause, it is going to update every row in your tbl_auth_user table. Which isn't a good idea

  2. $query = "SELECT SUM(week1-week1hours) AS theSum FROM staff JOIN project ON project.staff_id=staff.id WHERE project.staff_id='$id'";
    $result = mysql_query($query) or die(mysql_error());
    
    $totalRows = mysql_num_rows( $result );
    while($row = mysql_fetch_array($result)){ 
    
    if ($row['theSum'] > -1){
    	echo $row['theSum'] * $totalRows;
    else{
    	echo "<span class='red'>".$row['theSum'] . "</span>";
    }
    

  3. Javascript:

    function doCalc( index, total ){
    
    var num = document.getElementById('quant'+index).value;
    var gTotal = 0;
    
    if( !isNaN( num ) && num != '' )
    	document.getElementById('total'+index).innerHTML = (parseFloat(document.getElementById('price'+index).value) * parseInt(num)).toFixed(2);
    else
    	document.getElementById('total'+index).innerHTML = '0.00';
    
    for(var i = 0; i < total; i++ )
    	gTotal += parseFloat(document.getElementById('total'+i).innerHTML);
    
    document.getElementById('vTotal').innerHTML = gTotal.toFixed(2);
    }
    

     

    PHP

    <?php
    
    function populate_ordering_products($id){
    
    dbconnect();
    
    $sql = "SELECT * FROM product_spec WHERE category_id = ".$id;
    $result = mysql_query($sql);
    
    echo " 
    
    	<table width='842'>
    		<tr>
    			<td >Product ID</td>
    			<td >Energy</td>
    			<td >Brightness</td>
    			<td >Fitting</td>
    			<td >Quantity</td>
    			<td >Info?</td>
    		</tr>";
    
    		$totalRows = mysql_num_rows( $result );
    		$index = 0;
    
    		while(($row = mysql_fetch_row($result)) != false) {
    
    			$product_id = $row[1];
    			$product_name = get_productname($product_id);
    
    			echo "<tr>
    				<td>".$product_name."</td>
    				<td>".$row[2]."</td>
    				<td>".$row[3]."</td>
    				<td>".$row[4]."</td>
    
    				<td><input type='text' name='val$index' id='val$index' style='width:35px;' ONKEYUP='doCalc($index,$totalRows);'/></td>
    				<td><input type='text' name='tot_val$index' id='tot_val$index' style='width:35px;' DISABLED VALUE='5.00'/></td>
    			</tr>";
    
    		}
    
    		//I didnt know where you wanted the totals, so I just put it in the last row
    		echo "<TR><TD COLSPAN=3><B>Total: $</B> <SPAN NAME=vTotal ID=vTotal>0.00</SPAN></TR>";
    	echo "</table>";
    
    }
    
    ?>
    

     

    Hope this helps

  4. JS

    <SCRIPT>
    function doCalc( num ){
    //test to make sure that it is a number - to lazy to do it
    //do number formating
    document.getElementById('total').innerHTML = document.getElementById('price').value * num;
    }
    </SCRIPT>
    

    HTML

    Quantity: <input type="text" SIZE=3 NAME='quant' ID='quant' ONKEYUP='doCalc(this.value);'><BR>
    Price $<input SIZE=5 type="text" NAME='price' ID='price' DISABLED VALUE='5.00'><BR>
    Total: $<SPAN ID=total NAME=total>0.00</SPAN>
    

  5. I want to loop through all the checkboxes and check or uncheck each of the city box. But whe n the JS selAll function gets called, I always get an error that says

    "Error: document.cityFRM.city has no properties".

     

    Any Ideas?

     

    Javascript

    function selAll( check ){
        alert( document.cityFRM.city.length );
    }
    

     

     

    HTML

    
    <FORM NAME='cityFRM' ID='cityFRM' METHOD=GET ACTION='city.php'>
    
             <INPUT TYPE=CHECKBOX ONCLICK='javascript:selAll(this.checked);'>Check All<BR>
    
            <INPUT TYPE=CHECKBOX VALUE='New York' NAME='city[]' ID='city[]'>New York
            <INPUT TYPE=CHECKBOX VALUE='Chicago' NAME='city[]' ID='city[]'>Chicago
            <INPUT TYPE=CHECKBOX VALUE='Los Angeles' NAME='city[]' ID='city[]'>Los Angeles
            <INPUT TYPE=CHECKBOX VALUE='Detroit' NAME='city[]' ID='city[]'>Detroit
    </FORM>
    

     

    *I need to keep the the checkbox name an array, "city[]". I just want to know how to loop through them.

  6. if I am following you correct, would this work??

    <?php
    if((isset($_SESSION['errorstate'])) && ($_SESSION['errorstate'] == 1)) { //check for the sessions and if there is an error
                if( $_SESSION['errorstate'] < 1 )
                        $class = 'fade_valid';
                else
                        $class = 'fade_error';
    
    echo "<div id='message' class='$class'>";
    
    foreach($_SESSION['errormessage'] as $key => $value){ //print the errors
    	echo $value.'<br />';
    }
    
    echo "</div>";
    
    //clear the errors
    $_SESSION['errorstate'] = "";
    $_SESSION['errormessage'] = "";
    
    }
    ?>  

  7. function generate_titles($conn){
    $titles="";
    
    $query = "SELECT cState FROM tblState";
    
    $result = odbc_exec($conn, $query);
    
        while ($return = odbc_fetch_array($result)){ 
            $titles.="<option value='".$return[cState]."'>".$return[cState]."</option>";
        }
        return $titles;
    }
    

     

    You need to put quotes around the option value. If you dont put the quotes and there is a space in the value, only the first word will be set to the value. Like in your case, only 'new was set to the value rather then 'new jersey'

  8. $i=0;
    while($data = mysql_fetch_array($get_matches))
    {
       if($i == 0)
       {
          $temp = $data['date'];
       }
    
       if($data['date'] == $temp)
       {
          //print match
          echo"$data[hometeam] - $data[awayteam] $data[goals_home]-$data[goals_away]<br>";
       }
       else
       {
          break;
       }
    
       $i++;
    }
    
    

     

    but still nothing is printed :(

     

     

    This is just an idea on what you need to do. I do not know what you were doing.

        echo $data['hometeam'] ." - ". $data['awayteam'] . " " . $data['goals_home'] ." - " . $data['goals_away'] . "<br>";
    
    

  9. I am pretty sure, you can only insert one row at a time.

     

    Try somthing like this:

    $i=1;
    $successfull = 0;
    $flag = false;
    
    while($i<=$no_of_rooms){
    $q.="INSERT INTO `rooms` ( `name`,`property_id` ) VALUES ('$i', '$id');";
      	if( mysql_query($q) ){
       		$successfull++;
    }
    else { 
    	echo mysql_error();
    	$flag = true;
    	break;
    }
       	$i++;
    }
    
    if( $successfull > 0 && !$flag ){
    echo 'No worries';
    }else{ 
    echo 'Error, please try again';
    }
    

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