adding data to a database

garrensilverwing

New Member
Messages
148
Reaction score
0
Points
0
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:

freecrm

New Member
Messages
629
Reaction score
0
Points
0
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:
//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 
}
 

garrensilverwing

New Member
Messages
148
Reaction score
0
Points
0
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:

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
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.
 

garrensilverwing

New Member
Messages
148
Reaction score
0
Points
0
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
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
You are very welcomed
 
Top