Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2007
    Location
    UK
    Posts
    2,470
    Tokens
    2,975

    Latest Awards:

    Default Update MySQL Database via HTML and PHP. [Help]

    I know this is pretty basic stuff, not done anything with it though for a few years.

    I'm looking to update a Database, the structure is like this:

    Database
    - Website
    -- News

    Main database > Table > Row.

    I know I need to use the UPDATE which I have attempted to do, but no luck, just wondered if anyone can direct me in the right direction.

    Cheers.

    Edit:

    Just to add, this I what I have so far:

    HTML Code:
    <form method="post" action="<?php $_PHP_SELF ?>"><textarea border='1' name='NewsUpdate' maxlength='500' cols='125' rows='10'/></textarea><br><center><input size='15'type='submit' value='update' /></center></form>
    Last edited by Jack!; 16-11-2013 at 11:07 PM.

  2. #2
    Join Date
    Nov 2013
    Location
    Australia
    Posts
    2,405
    Tokens
    9,762
    Habbo
    Wennn.

    Latest Awards:

    Default

    I don't really have experience with PHP, but I do know how to update a database with Python. Are you using MySQL Database? This link looks helpful: http://www.tutorialspoint.com/php/mysql_update_php.htm



    @habboxgraphics on Twitter

  3. #3
    Join Date
    Oct 2006
    Posts
    9,905
    Tokens
    26,858
    Habbo
    Zak

    Latest Awards:

    Default

    PHP Code:
    <form action='register.php' method='POST'>    
     <table>            
      <tr>                
       <td>                
        Enter your first name:                
       </td>                                
       <td>                
        <input type='text' name='firstname' value='<?php echo $firstname?>'>               
       </td>            
      </tr>                        
      <tr>                
      <td>               
       Enter your surname:                
      </td>                                
      <td>                
       <input type='text' name='surname' value='<?php echo $surname?>'>                
      </td>            
     </tr>                        
     <tr>                
      <td>                
       Enter your username:                
      </td>                                
      <td>                
       <input type='text' name='username' value='<?php echo $username?>'>               
      </td>            
     </tr>                        
     <tr>                
      <td align="left">                
       Enter your password:               
      </td>                                
      <td>               
       <input type='password' name='password'>                
      </td>            
     </tr>                        
     <tr>                
      <td>                
       Repeat your password:                
      </td>                                
      <td>               
       <input type='password' name='verifypassword'>                
      </td>            
     </tr>    
    </table>    
     <br>    
      <input type='submit' name='submit' value='Register'>
     </form>
      <br>  
        <?php
           $submit 
    $_POST['submit'];
           
    $firstname strip_tags($_POST['firstname']);
           
    $surname strip_tags($_POST['surname']);
           
    $username strip_tags($_POST['username']);
           
    $password strip_tags($_POST['password']);
           
    $verifypassword strip_tags($_POST['verifypassword']);$date date("Y-m-d");
       
         if (
    $submit) {            
         
    $query mysql_query("SELECT * FROM users WHERE username='$username'");    
         
    $numrows mysql_num_rows($query);        

         if(
    $numrows){    die("This user already exists");    }         

         if(
    $firstname&&$surname&&$username&&$password&&$verifypassword) {            
         if(
    $password==$verifypassword) {            
         if(
    strlen($firstname)>25 || strlen($surname)>25 || strlen($username)>25) {                
         die(
    "Error: Max character limit exceeded - All fields must be below 25 characters");           
         } else if(
    strlen($password) > 25 || strlen($password) < 6) {              
        die(
    "Error: Your password must be between 6 and 25 characters.");           
        } else                        
        
    $password md5($password);            
        
    $verifypassword =md5($verifypassword);         

         
    mysql_select_db("yourdb") or die("Error selecting database");                            
        
    $query mysql_query("INSERT INTO users VALUES ('','$firstname','$surname','$admin','$username','$password','$date')");                            
      
        die(
    "You have been successfully registered");                            
        } else        echo 
    "Error: Your passwords do not match.";        
        } else    echo 
    "Error: Please fill in <b>every field</b>";           
     }
    ?>
    A bit like that?

    I used this in one of website pages years ago. (sorry about the formatting - just had to rejig it in here -.-)

    I know the code is an insert into but UPDATE code is very similar (eg. UPDATE tablename SET field='' WHERE otherfield>2
    Last edited by Zak; 17-11-2013 at 11:06 AM.

  4. #4
    Join Date
    Jul 2007
    Location
    UK
    Posts
    2,470
    Tokens
    2,975

    Latest Awards:

    Default

    Code:
    if($_POST['submit']){
    				 	$_POST['textarea'] = str_replace("'", "&#39;", $_POST['textarea']); 
    					$con->query("UPDATE `website` SET NewsShort = '".$_POST['textarea']."'");
    					echo "<center><h3>You have changed the news.</h3></center>";
    					unset($_POST);
    					
    				}else{
    					echo "<h2>New News:</h2>
    					You may add in HTML codes.<br><br>
    					<form name='input' action='' method='post'>
    					<textarea border='1' name='textarea' maxlength='500' cols='125' rows='10'/></textarea><br><center><input size='15'type='submit' name='submit'value=' Submit ' /></center>
    					</form><br>";
    					$text = $_POST['textarea'];
    					$submit = $_POST['submit'] = 1;
    				}
    				
    			}
    		?>
    Did it like that in the end, just the PHP bit there, the field bit isn't difficult.

  5. #5
    Join Date
    Oct 2006
    Posts
    9,905
    Tokens
    26,858
    Habbo
    Zak

    Latest Awards:

    Default

    Quote Originally Posted by Jack! View Post
    Code:
    if($_POST['submit']){
                         $_POST['textarea'] = str_replace("'", "&#39;", $_POST['textarea']); 
                        $con->query("UPDATE `website` SET NewsShort = '".$_POST['textarea']."'");
                        echo "<center><h3>You have changed the news.</h3></center>";
                        unset($_POST);
                        
                    }else{
                        echo "<h2>New News:</h2>
                        You may add in HTML codes.<br><br>
                        <form name='input' action='' method='post'>
                        <textarea border='1' name='textarea' maxlength='500' cols='125' rows='10'/></textarea><br><center><input size='15'type='submit' name='submit'value=' Submit ' /></center>
                        </form><br>";
                        $text = $_POST['textarea'];
                        $submit = $_POST['submit'] = 1;
                    }
                    
                }
            ?>
    Did it like that in the end, just the PHP bit there, the field bit isn't difficult.
    Glad you figured it out. Kinda guessed you would, PHP is a very easy language to understand and manipulate!

Posting Permissions

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