JayLewis Posted March 19, 2007 Share Posted March 19, 2007 Everytime i open the document that this code is stored on it puts a new file into my database as NULL... the only way i can think of stopping it is using "isset" .. correct me if im wrong. if i am correct, how would i go about it? Thanks <? $username="***"; $password="***"; $database="***"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM games"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<b><center>Games List</center></b><br><br>"; $i=0; while ($i < $num) { $name=mysql_result($result,$i,"name"); $var = ''; echo "<b>$name<br>"; $i++; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/43312-isset/ Share on other sites More sharing options...
AndyB Posted March 19, 2007 Share Posted March 19, 2007 Not that script - it never executes an INSERT query. Must be something else. Quote Link to comment https://forums.phpfreaks.com/topic/43312-isset/#findComment-210300 Share on other sites More sharing options...
JayLewis Posted March 19, 2007 Author Share Posted March 19, 2007 This part does... <? $username="wwwjust_chris"; $password="123456"; $database="wwwjust_games"; $name=$_POST['name']; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "INSERT INTO games VALUES ('','$name')"; mysql_query($query); mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/43312-isset/#findComment-210307 Share on other sites More sharing options...
wildteen88 Posted March 19, 2007 Share Posted March 19, 2007 Your are not checking that _POST['name'] variable exists. SO if it doesn't exist you code is going insert NULL values for name column in MySQL. You should check that it exists first. Like so <?php $username="wwwjust_chris"; $password="123456"; $database="wwwjust_games"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); if(isset($_POST['name']) && !empty($_POST['name'])) { $name = mysql_real_escape_string($_POST['name']); $query = "INSERT INTO games VALUES ('','$name')"; $result = mysql_query($query); mysql_close(); } else { echo "Please ensure you have filled in the name form field!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/43312-isset/#findComment-210422 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.