Jump to content

Isset


JayLewis

Recommended Posts

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++;
}

?>

 

Link to comment
https://forums.phpfreaks.com/topic/43312-isset/
Share on other sites

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();
?>

Link to comment
https://forums.phpfreaks.com/topic/43312-isset/#findComment-210307
Share on other sites

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!";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/43312-isset/#findComment-210422
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.