Jump to content

[SOLVED] Help - If Statement


DarkPrince2005

Recommended Posts

Can anybody help me on how i would change the attached code to just save the filled in fields to the database if a file is not uploaded?

 

<?php

ini_set('display_errors','On');
error_reporting(E_ALL);

ini_set('upload_max_filesize','5M');

ini_set('max_execution_time','180');

ini_set('max_input_time','180');

mysql_connect("localhost","root","");

  mysql_select_db("npa");
  
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}


$query = mysql_query("INSERT INTO case_management (date, applicant, respondent, case_number, judge, representative, offence, outcome, relief, occupation, region, status, case_summary, name, size, type, content ) ".
"VALUES ('$_POST[date]','$_POST[applicant]','$_POST[respondent]','$_POST[case_number]','$_POST[judge]','$_POST[representative]','$_POST[offence]','$_POST[outcome]','$_POST[relief]','$_POST[occupation]','$_POST[region]','$_POST[status]',\"$_POST[case_summary]\",'$fileName', '$fileSize', '$fileType', '$content')");


//mysql_query($query) or die('Error, query failed'); 
echo "<script language=JavaScript>window.location='add.html'</script>";
}
else
{
$sql = mysql_query("INSERT INTO case_management (date, applicant, respondent, case_number, judge, representative, offence, outcome, relief, occupation, region, status, case_summary, name, size, type, content ) VALUES ('$_POST[date]','$_POST[applicant]','$_POST[respondent]','$_POST[case_number]','$_POST[judge]','$_POST[representative]','$_POST[offence]','$_POST[outcome]','$_POST[relief]','$_POST[occupation]','$_POST[region]','$_POST[status]',\"$_POST[case_summary]\",'', '', '', '','')");

echo "<script language=JavaScript>window.location='add.html'</script>";
};
?>

Link to comment
Share on other sites

Try this

<?php
ini_set('display_errors','On');
error_reporting(E_ALL);
ini_set('upload_max_filesize','5M');
ini_set('max_execution_time','180');
ini_set('max_input_time','180');

mysql_connect("localhost","root","");
mysql_select_db("npa");

if(isset($_POST['upload']) // submit button is pressed

{ 

if($_FILES['userfile']['size'] > 0) // file is being selected 
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

		if(!get_magic_quotes_gpc())
		{
			$fileName = addslashes($fileName);
		}


$query = mysql_query("INSERT INTO case_management (date, applicant, respondent, case_number, judge, representative, offence, outcome, relief, occupation, region, status, case_summary, name, size, type, content ) ".
"VALUES ('$_POST[date]','$_POST[applicant]','$_POST[respondent]','$_POST[case_number]','$_POST[judge]','$_POST[representative]','$_POST[offence]','$_POST[outcome]','$_POST[relief]','$_POST[occupation]','$_POST[region]','$_POST[status]',\"$_POST[case_summary]\",'$fileName', '$fileSize', '$fileType', '$content')");


//mysql_query($query) or die('Error, query failed'); 
echo "<script language=JavaScript>window.location='add.html'</script>";
}
else
{
$sql = mysql_query("INSERT INTO case_management (date, applicant, respondent, case_number, judge, representative, offence, outcome, relief, occupation, region, status, case_summary, name, size, type, content ) VALUES ('$_POST[date]','$_POST[applicant]','$_POST[respondent]','$_POST[case_number]','$_POST[judge]','$_POST[representative]','$_POST[offence]','$_POST[outcome]','$_POST[relief]','$_POST[occupation]','$_POST[region]','$_POST[status]',\"$_POST[case_summary]\",'', '', '', '','')");

echo "<script language=JavaScript>window.location='add.html'</script>";
}
}
?>

Link to comment
Share on other sites

It's still not saving to the database if I don't upload a file

 

<?php

ini_set('display_errors','On');
error_reporting(E_ALL);

ini_set('max_execution_time','180');

ini_set('max_input_time','180');

mysql_connect("192.168.42.112:3306","npa","fa11en");
//mysql_connect("localhost","root","");

  mysql_select_db("npa");
  
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}


$query = mysql_query("INSERT INTO case_management (date, applicant, respondent, case_number, judge, representative, offence, outcome, relief, occupation, region, status, case_summary, name, size, type, content ) ".
"VALUES ('$_POST[date]','$_POST[applicant]','$_POST[respondent]','$_POST[case_number]','$_POST[judge]','$_POST[representative]','$_POST[offence]','$_POST[outcome]','$_POST[relief]','$_POST[occupation]','$_POST[region]','$_POST[status]',\"$_POST[case_summary]\",'$fileName', '$fileSize', '$fileType', '$content');");
}
else
{
$sql = mysql_query("INSERT INTO case_management (date, applicant, respondent, case_number, judge, representative, offence, outcome, relief, occupation, region, status, case_summary, name, size, type, content ) VALUES ('$_POST[date]','$_POST[applicant]','$_POST[respondent]','$_POST[case_number]','$_POST[judge]','$_POST[representative]','$_POST[offence]','$_POST[outcome]','$_POST[relief]','$_POST[occupation]','$_POST[region]','$_POST[status]',\"$_POST[case_summary]\",'', '', '', '','');");


};
echo "<script language=JavaScript>window.location='add.html'</script>";
?>

Link to comment
Share on other sites

Does this line work :

 

$sql = mysql_query("INSERT INTO case_management (date, applicant, respondent, case_number, judge, representative, offence, outcome, relief, occupation, region, status, case_summary, name, size, type, content ) VALUES ('$_POST[date]', '$_POST[applicant]', '$_POST[respondent]',  '$_POST[case_number]', '$_POST[judge]', '$_POST[representative]','$_POST[offence]', '$_POST[outcome]', '$_POST[relief]', '$_POST[occupation]', '$_POST[region]', '$_POST[status]',\"$_POST[case_summary]\",'', '', '', '','');");

 

how about you do this :

$sqlString = "INSERT INTO case_management (date, applicant, respondent, case_number, judge, representative, offence, outcome, relief, occupation, region, status, case_summary, name, size, type, content ) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','', '', '', '','')";

$sql = sprintf($sqlString,$_POST[date], $_POST[applicant], $_POST[respondent], $_POST[case_number], $_POST[judge], $_POST[representative], $_POST[offence],  $_POST[outcome], $_POST[relief], $_POST[occupation], $_POST[region], $_POST[status], $_POST[case_summary]);

echo "This is my sql string".$sql;

if($execSql = mysql_query($sql)){
echo "it worked";
} else {
echo "IT FAILED".mysql_error();
}

 

Your sql just might be incorrect. Do you require default fields?

Link to comment
Share on other sites

here's the working bit:

 

if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}


$query = mysql_query("INSERT INTO case_management (date, applicant, respondent, case_number, commisioner, representative, region, offence, charge, dispute, outcome, relief, status, case_summary, name, size, type, content ) ".
"VALUES ('$_POST[date]','$_POST[applicant]','$_POST[respondent]','$_POST[case_number]','$_POST[commisioner]','$_POST[representative]','$_POST[region]','$_POST[offence]','$_POST[charge]','$_POST[dispute]','$_POST[outcome]','$_POST[relief]','$_POST[status]',\"$_POST[case_summary]\",'$fileName', '$fileSize', '$fileType', '$content');");


echo "<script language=JavaScript>window.location='add.html'</script>";

}else {
mysql_query("INSERT INTO case_management (date, applicant, respondent, case_number, commisioner, representative, region, offence, charge, dispute, outcome, relief, status, case_summary, name, size, type, content ) ".
"VALUES ('$_POST[date]','$_POST[applicant]','$_POST[respondent]','$_POST[case_number]','$_POST[commisioner]','$_POST[representative]','$_POST[region]','$_POST[offence]','$_POST[charge]','$_POST[dispute]','$_POST[outcome]','$_POST[relief]','$_POST[status]',\"$_POST[case_summary]\",'', '', '', '');");

echo "<script language=JavaScript>window.location='add.html'</script>";;

};

Link to comment
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.