+ Reply to Thread
Results 1 to 6 of 6

Thread: adding data to a database

  1. #1
    garrensilverwing's Avatar
    garrensilverwing is offline x10 Sophmore garrensilverwing is an unknown quantity at this point
    Join Date
    Nov 2008
    Posts
    148

    adding data to a database

    i'm trying to build a database full of information on games that i have on my site the problem i am having is the information is not storing in the database (i get no error messages)... here is my code thanks for the help in advance

    for gamesdb.php:
    Code:
    <?php
    	require "../dbgames_connect.php";
    	if(!$_POST['submit']) {
     ?>
    <html>
    <head>
    <title>add games to database</title>
    </head>
    <body>
    <div>
    		<form method="post" action="gamesdb.php">
    		<input name="wFirst" type="text" tabindex="1" style="height: 22px"> white first name<br>
    		<input name="wLast" type="text" tabindex="2"> white last name<br>
    		<input name="wRating" type="text" tabindex="3"> white rating<br>
    		<input name="bFirst" type="text" tabindex="4"> black first name<br>
    		<input name="bLast" type="text" tabindex="5"> black last name<br>
    		<input name="bRating" type="text" tabindex="6"> black rating<br>
    		<input name="eco" type="text" tabindex="7"> eco<br>
    		<input name="result" type="text" tabindex="8"> result<br>
    		<input name="year" type="text" tabindex="9"> year<br>
    		<input name="link" type="text" tabindex="10"> link<br>
    		<input name="Submit1" type="submit" value="submit"  tabindex="11"></form>
    </div>
    </body>
    </html>
    <?php
    	}
    	else {
    
    		$wFirst=protect($_POST['wFirst']);
    		$wLast=protect($_POST['wLast']);
    		$wRating=protect($_POST['wRating']);
    		$bFirst=protect($_POST['bFirst']);
    		$bLast=protect($_POST['bLast']);
    		$bRating=protect($_POST['bRating']);
    		$eco=protect($_POST['eco']);
    		$result=protect($_POST['result']);
    		$year=protect($_POST['year']);
    		$link=protect($_POST['link']);
    		$sql = "INSERT into `games`(`wFirst`,`wLast`,`wRating`,`bFirst`,`bLast`,`bRating`,`eco`,`result`,`year`,`link`)
    		VALUES ('$wFirst','$wLast','$wRating','$bFirst','$bLast','$bRating','$eco','$result','$year','$link');";
    		mysql_query($sql) or die(mysql_error());
    		echo "Thank you for submitting the game information.";
    	}	
    ?>
    for ../dbgames_connect.php:
    Code:
    <?php 
    $username = "frostbit_admin";
    $password = "***"; 
    $server = "localhost";
    $database="frostbit_games";
    $mysqlconnection = mysql_connect($server, $username, $password); 
    if (!$mysqlconnection) { 
       die('There was a problem connecting to the mysql server. Error returned: '. mysql_error()); 
    } 
    $databaseconnection = mysql_select_db($database); 
    if (!$databaseconnection) { 
       die('There was a problem using that mysql database. Error returned: '. mysql_error()); 
    } 
    function protect($string)
    {
      $string = mysql_real_escape_string($string);
      return $string;
    }
     ?>
    Edit:
    well i figured it out on my own, thanks for not calling me an idiot anyone i had to change the name of my submit button to submit not Submit1 which wast he default haha
    Last edited by garrensilverwing; 05-09-2009 at 05:21 PM. Reason: Automerged Doublepost

  2. #2
    freecrm's Avatar
    freecrm is offline x10 Elder freecrm is an unknown quantity at this point
    Join Date
    May 2008
    Location
    UK
    Posts
    629

    Re: adding data to a database

    I'm curious..

    Why the need for double semi-colon at the end of your sql statement?

    Also, in addition, you could review your protect() function.. (misson helped me on this).

    PHP Code:
    //create function to make db safe     
    function protect($string){
        if (
    get_magic_quotes_gpc())// if system setting magic quotes is on 
        
    {  
            
    $string stripslashes($string);//strip out escape slashes  
        

        return 
    mysql_real_escape_string(strip_tags($string));// sanitise string 


  3. #3
    garrensilverwing's Avatar
    garrensilverwing is offline x10 Sophmore garrensilverwing is an unknown quantity at this point
    Join Date
    Nov 2008
    Posts
    148

    Re: adding data to a database

    Code:
    $sql = "INSERT into `games`(`wFirst`,`wLast`,`wRating`,`bFirst`,`bLast`,`bRating`,`eco`,`result`,`year`,`link`)
    		VALUES ('$wFirst','$wLast','$wRating','$bFirst','$bLast','$bRating','$eco','$result','$year','$link');";
    you're refering to this? i dont know how to explain it but $sql is going to be going inside of a function and i want to make sure it recognizes that insert and value need to be seperate

    thanks for the tip with the protect function, though all the information will be submitted by me i will add that to both my database connect files
    Last edited by garrensilverwing; 05-09-2009 at 06:04 PM.

  4. #4
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: adding data to a database

    You check if " $_POST['submit'] " is set, but in you code, you set the name of the submit to " Submit1 ".
    change one of the two, and you should be good.
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

  5. #5
    garrensilverwing's Avatar
    garrensilverwing is offline x10 Sophmore garrensilverwing is an unknown quantity at this point
    Join Date
    Nov 2008
    Posts
    148

    Re: adding data to a database

    Quote Originally Posted by xav0989 View Post
    You check if " $_POST['submit'] " is set, but in you code, you set the name of the submit to " Submit1 ".
    change one of the two, and you should be good.
    yup thanks, i found that out after looking back at it an hour later or so :D

  6. #6
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: adding data to a database

    You are very welcomed
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

+ Reply to Thread

Similar Threads

  1. HELP! Adding data on my database tables...
    By darylcarpo in forum Programming Help
    Replies: 7
    Last Post: 11-08-2008, 09:21 PM
  2. How to create MySQL database and user
    By Jesse in forum Tutorials
    Replies: 11
    Last Post: 06-04-2008, 12:25 PM
  3. HTML help...
    By anuj_web in forum Programming Help
    Replies: 5
    Last Post: 05-08-2008, 11:22 AM
  4. PHP BB 2.0.16 Manual instalation
    By GFIV in forum Free Hosting
    Replies: 8
    Last Post: 09-14-2005, 12:40 PM
  5. Pentagon creating student database
    By Iceman in forum Off Topic
    Replies: 1
    Last Post: 06-24-2005, 01:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers