Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 4 FirstFirst 1234 LastLast
Results 16 to 30 of 55
  1. #16
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in
    I get the above error when I do that.

  2. #17
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    May need quotes now its not a number:

    PHP Code:
    $result mysqli_query($con,"SELECT * FROM IGarmy WHERE username = '".$_SESSION['Username']."'"); 
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  3. #18
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Yep, that did it thanks!

  4. #19
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    How do I get it to work as an update form now?

    This is the form.
    PHP Code:
    <?php
    $con
    =mysqli_connect("host","user","password","database");
    // Check connection
    if (mysqli_connect_errno())
      {
      echo 
    "Failed to connect to MySQL: " mysqli_connect_error();
      }

    $result mysqli_query($con,"SELECT * FROM IGarmy WHERE Comname = '".$_SESSION['Comname']."'");    

    echo 
    "<form method='post' action='update.php'>";
    echo 
    "<table border='0'>
    <tr>
    <th>Commanders Information</th>
    </tr>"
    ;

    while(
    $row mysqli_fetch_array($result))
      {
      echo 
    "<tr>";
      echo 
    "</tr>";
      echo 
    "</tr>";
        echo 
    "</table>";
        echo 
    "<table>";
        echo 
    "<tr>";
      echo 
    "<th>Commanders Name:</th> <td><input type='text' name='Comname' value='$row[Comname]' size='50'>";
          echo 
    "<tr>";
      echo 
    "<th>Password:</th> <td><input type='password' name='password' value='$row[password]'>";
      echo 
    "</tr>";
        echo 
    "</table>";
        echo 
    "<table>";
        echo 
    "<tr>";
      echo 
    "<tr>";
      echo 
    "</tr>";
      echo 
    "</tr>";
       echo 
    "<th></th> <td></td>";
        echo 
    "</tr>";
      echo 
    "<tr>
    <th>Imperial Guard Regiment Information</th>
    </tr>"
    ;
      echo 
    "<th>Regiment Name:</th> <td><input type='text' name='name' value='$row[name]' size='35'>";
          echo 
    "<tr>";
      echo 
    "<th>Homeworld:</th> <td><input type='text' name='homeworld' value='$row[homeworld]' size='35'>";
      echo 
    "</tr>";
        echo 
    "<th>Estimated Regiment Size:</th> <td><input type='text' name='regsize' value='$row[regsize]' size='35'>";
      echo 
    "</tr>";
      echo 
    "<th>Unit Type:</th> <td><input type='text' name='unittype' value='$row[unittype]'>";
          echo 
    "<tr>";
      echo 
    "<th>Gender:</th> <td><input type='text' name='gender' value='$row[gender]'>";
      echo 
    "</tr>";
      echo 
    "<th>Allegiance:</th> <td><input type='text' name='allegiance' value='$row[allegiance]'>";
          echo 
    "<tr>";
      echo 
    "<th>Prefered Special Weapon:</th> <td><input type='text' name='specialweapon' value='$row[specialweapon]'>";
      echo 
    "</tr>";
      echo 
    "<th>Prefered Heavy Weapon:</th> <td><input type='text' name='heavyweapon' option     value='$row[heavyweapon]' >";
          echo 
    "<tr>";
          echo 
    "</tr>";
      echo 
    "</tr>";
       echo 
    "<th></th> <td></td>";
        echo 
    "</tr>";
        echo 
    "</table>";
        echo 
    "<table>";
        echo 
    "<tr>";
        echo 
    "<th>Background:</th> <tr></tr> <td>";
          echo 
    "<textarea cols=\"75\" rows=\"15\"> $row[Background] </textarea><br>";
          echo 
    "</tr>";
      echo 
    "<th>Historical Figures:</th> <tr> <td>";
      echo 
    "<textarea cols=\"75\" rows=\"15\">$row[HistoricalFigures]</textarea><br>";
      echo 
    "</tr>";
        echo 
    "<th>Notable Campaigns:</th> <tr> <td>";
      echo 
    "<textarea cols=\"75\" rows=\"15\">$row[campaigns]</textarea><br>";
      echo 
    "</tr>";
      }
    echo 
    "</table>";
    echo 
    "<input type=\"submit\" name=\"submit\" value=\"Update Information\">";
    echo 
    "</form>";

    mysqli_close($con);
    ?>
    This is the update page
    PHP Code:
    <?php
    include("config.php");

    // connect to the mysql server
    $link mysql_connect($server$db_user$db_pass)
    or die (
    "Could not connect to mysql because ".mysql_error());

    // select the database
    mysql_select_db($database)
    or die (
    "Could not select database because ".mysql_error());

    mysql_query("UPDATE IGarmy SET Comname = '".$_POST['Comname']."', password = '".$_POST['password']."', name = '".$_POST['name']."', homeworld = '".$_POST['homeworld']."', regsize = '".$_POST['regsize']."', unittype '".$_POST['unittype']."', gender = '".$_POST['gender']."', allegiance = '".$_POST['allegiance']."', specialweapon = '".$_POST['specialweapon']."', heavyweapon = '".$_POST['heavyweapon']."', Background = '".$_POST['Background']."', HistoricalFigures = '".$_POST['HistoricalFigures']."', campaigns = '".$_POST['campaigns']."')
    WHERE Comname = '"
    .$_POST['Comname']."' AND password = '".$_POST['password']."'");

    $resmysql_query($update);

    ?>
    Last edited by Foster; 02-27-2013 at 03:16 PM.

  5. #20
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    post your current code please
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  6. #21
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    I was editing the previous post when you messaged.

  7. #22
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    its good practice to have users inputs striped against hacker attempts

    this sanitize script you can put in config.php

    PHP Code:
    function sanitize($input) {
        if (
    is_array($input)) {
            foreach(
    $input as $var=>$val) {
                
    $output[$var] = sanitize($val);
            }
        }
        else {
            if (
    get_magic_quotes_gpc()) {
                
    $input stripslashes($input);
            }
            
    $input  cleanInput($input);
            
    $output mysql_real_escape_string($input);
        }
        return 
    $output;


    then try this:

    ps you just had an extra ) after campaigns and fields like name and password need backsticks as below
    its the key to the left of 1 on your keyboard.

    PHP Code:
    sanitize($_POST);

    mysql_query("UPDATE IGarmy SET 
    `Comname` = '"
    .$_POST['Comname']."', 
    `password` = '"
    .$_POST['password']."', 
    `name` = '"
    .$_POST['name']."', 
    `homeworld` = '"
    .$_POST['homeworld']."', 
    `regsize` = '"
    .$_POST['regsize']."', 
    `unittype` '"
    .$_POST['unittype']."', 
    `gender` = '"
    .$_POST['gender']."', 
    `allegiance` = '"
    .$_POST['allegiance']."', 
    `specialweapon` = '"
    .$_POST['specialweapon']."', 
    `heavyweapon` = '"
    .$_POST['heavyweapon']."', 
    `Background` = '"
    .$_POST['Background']."', 
    `HistoricalFigures` = '"
    .$_POST['HistoricalFigures']."', 
    `campaigns` = '"
    .$_POST['campaigns']."'
    WHERE `Comname` = '"
    .$_POST['Comname']."' AND `password` = '".$_POST['password']."'"); 
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  8. #23
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Nope that doesn't work, the sanitize script gives an error and with out it still doesn't update.

  9. #24
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    is your password encoded? ie md5()

    also you can try HAVING instead of AND

    PHP Code:
    'Comname']."' HAVING `password` 
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  10. #25
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    No the password isn't encoded. Changing AND to Having hasn't made a difference.

  11. #26
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    whats happening or what error are you getting?

    load up PHPMYADMIN and try the query direct

    Code:
    UPDATE IGarmy SET 
    `Comname` = 'Arcticwarrio', 
    `password` = '1234', 
    `name` = 'Gra', 
    `homeworld` = 'Earth', 
    `regsize` = '24', 
    `unittype` 'warrior', 
    `gender` = 'male', 
    `allegiance` = 'streaking squirrels', 
    `specialweapon` = 'axe', 
    `heavyweapon` = 'maul', 
    `Background` = 'blue', 
    `HistoricalFigures` = 'shakespear', 
    `campaigns` = 'yes'
    WHERE `Comname` = 'Arcticwarrio' AND `password` = '1234'
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  12. #27
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    #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 ''warrior',
    `gender` = 'male',
    `allegiance` = 'streaking squirrels',
    `speci' at line 7
    Gives the above error.

  13. #28
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    I went back through this and reviewed the code you gave me, at that point I noticed a missing = which was causing the error. Most of the problem is now resolved and most of the form is updating. The text area sections aren't though, they are below.

    PHP Code:
    echo "<th>Background:</th> <tr></tr> <td>";
          echo 
    "<textarea cols=\"75\" rows=\"15\"> $row[Background] </textarea><br>";
          echo 
    "</tr>";
      echo 
    "<th>Historical Figures:</th> <tr> <td>";
      echo 
    "<textarea cols=\"75\" rows=\"15\">$row[HistoricalFigures]</textarea><br>";
      echo 
    "</tr>";
        echo 
    "<th>Notable Campaigns:</th> <tr> <td>";
      echo 
    "<textarea cols=\"75\" rows=\"15\">$row[campaigns]</textarea><br>";
      echo 
    "</tr>"
    Edit: I've just found the reason for this is because I have set it as a textarea, however I don't know how to set the height and width of the box any other way.
    Last edited by Foster; 02-27-2013 at 09:22 PM.

  14. #29
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    they have no names!

    <textarea name="campaigns" cols=\"75\" rows=\"15\">$row[campaigns]</textarea>
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  15. #30
    Regular Coder
    Join Date
    Nov 2011
    Posts
    250
    Thanks
    8
    Thanked 4 Times in 4 Posts
    I don't know how I managed to miss that. It's fixed though, thank you!


 
Page 2 of 4 FirstFirst 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •