Jump to content

wildteen88

Staff Alumni
  • Posts

    10,480
  • Joined

  • Last visited

    Never

Posts posted by wildteen88

  1. If all $allwordsgenral contains a comma delimited list of words then change

             <optgroup label=\"Others added\">    //heres problem
             <option value=\"".$allwordsgeneral."\">".$allwordsgeneral."</option>
             </optgroup>";

    to

             <optgroup label=\"Others added\">\n";
            $words = explode(',', $allwordsgeneral);
            foreach($words as $word)
                $funcexpList .= "<option value=\"".$word."\">".$word."</option>\n";
    
            $funcexpList .= "</optgroup>";

     

    NOTE: When posting code please wrap it within

    
    

    or

    
    

    ) tags.

     

  2. Characters such as ' or " will cause problems within your sql queries. You need to escape these characters. To prevent this you should pass all string values to mysql_real_escape_string before using them within your queries. Example

    $name = mysql_real_escape_string($_POST['name']);

  3. What you want to do is change this

    	echo "<td><input type = 'text' name = 'udata[fname][{$list['id']}]' value = '{$list['fname']}' />\r\n";
    echo "<td><input type = 'text' name = 'udata[lname][{$list['id']}]' value = '{$list['lname']}' />\r\n";
    echo "<td><input type = 'text' name = 'udata[dob][{$list['id']}]' value = '{$list['dob']}' />\r\n";
    echo "<td><input type = 'text' name = 'udata[email][{$list['id']}]' value = '{$list['email']}' />\r\n";

    to

    	echo "<td><input type = 'text' name = 'udata[{$list['id']}][fname]' value = '{$list['fname']}' />\r\n";
    echo "<td><input type = 'text' name = 'udata[{$list['id']}][lname]' value = '{$list['lname']}' />\r\n";
    echo "<td><input type = 'text' name = 'udata[{$list['id']}][dob]' value = '{$list['dob']}' />\r\n";
    echo "<td><input type = 'text' name = 'udata[{$list['id']}][email]' value = '{$list['email']}' />\r\n";

     

    Next change

    // UPDATE: if we have name(s) to change...
    if($_POST['udata']) {   
    /*
    // for each name to change...   
    foreach ($_POST['udata'] as $input => $v) {
    	echo "$input = $v<br />";
    	$sql = "UPDATE test SET ";
    	foreach ($v as $id => $value) {
    		echo "$id = $value<br />";
    	}
    	$sql .= "WHERE ...";
    }
    echo "<hr />$sql<hr />";
    print_r($_POST['udata']);
    */
    
    for ($i = 0; $i < count($_POST['udata']['fname']); $i++) {
    	$fname = $_POST['udata']['fname'][$i];
    	echo "$i = $fname<br />";
    }
    
    /*
    foreach($_POST['cname'] as $cid => $cname) {      
    	// little bit of cleaning...      
    	$id = mysql_real_escape_string($cid);      
    	$fname = mysql_real_escape_string($cname);
    	$lname = mysql_real_escape_string($cname);
    	$dob = mysql_real_escape_string($cname);
    	$email = mysql_real_escape_string($cname);
    	// update name in the table        
    	$sql = "UPDATE test SET fname = '$fname', lname='$lname', dob='$dob', email='$email' WHERE id = '$id'";      
    	$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);   
    } // end foreach
    */
    } // end if  

    to

    // UPDATE: if we have name(s) to change...
    if($_POST['udata'])
    {   
        // update data
        foreach ($_POST['udata'] as $record_id => $fields)
        {
            $sql = "UPDATE test SET ";
            
            $field_data = array();
            foreach($fields as $name => $value)
            {
                $value = mysql_real_escape_string($value);
                $field_data[] = "$field = \"'$value'\"";
            }
            
            $sql .= implode(', ', $field_data);
            $sql .= "WHERE id=$record_id";
    
    
            echo "<hr />$sql<hr />";
            $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
        }
    } // end if

  4. To output a chunk of html you can do either of the following

    Using single quotes (make sure you escape any ' within your string using \')

    echo '<div class="textColor">
    <h1>title</h1>
    <p> Hello phpfreaks</p>
    <h2> some title</h2>
    <p> another paragraph</p>
    </div>';

     

    Or double quotes (make sure you escape any " within your string using \")

    echo "<div class=\"textColor\">
    <h1>title</h1>
    <p> Hello phpfreaks</p>
    <h2> some title</h2>
    <p> another paragraph</p>
    </div>";

     

    Or using heredoc syntax

    echo <<<HTML
    <div class="textColor">
    <h1>title</h1>
    <p> Hello phpfreaks</p>
    <h2> some title</h2>
    <p> another paragraph</p>
    </div>
    HTML;

     

    Or  you can go in/out of PHP

    <?php
    // your code here
    ?>
    <div class="textColor">
    <h1>title</h1>
    <p> Hello phpfreaks</p>
    <h2> some title</h2>
    <p> another paragraph</p>
    </div>
    <?php
    // some more code here
    ?>

  5. Then you should be setting up only two tables, users and diaries. When the user registers you add them in to the users table. When they add a diary entry you insert it into the diaries table. Creating separate tables for each user is bad database design.

  6. You most likely need to wrap $name,$Level,$CT,$Kills,$Deaths,$killdeaths,$AS within double quotes. You cannot pass multiple parameters to fwrite

        fwrite($open, "$name,$Level,$CT,$Kills,$Deaths,$killdeaths,$AS");

     

    fwrite can only take three arguments, quoted from the manual.

    int fwrite ( resource $handle , string $string [, int $length ] )

  7. Are you wanting to add all the keywords returned from your query into the $_SESSION['scope'] array? If so all you need to do is

    while($row = mysql_fetch_assoc($get));
    {
        $_SESSION['scope'][] = $row['keyword'];
    }

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