Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.