Jump to content

[SOLVED] Field Chack


bob2588

Recommended Posts

i want this script to run a check on the fields before  before it make the file any ideas

<?php
if(isset($_POST['Submit'])){
if($_POST['host'] =="") {
echo"Please Fill Out the Host Filed";
}
if($_POST['user'] =="") {
echo"<br>Please fill Out the Username Filed";
}
if($_POST['pass'] =="") {
echo"<br>Please Fill Out the Password";
}
if($_POST['db_name'] =="") {
echo"<br>please fill Out the Databases name";
}

$db_host=$_POST['host'];
$db_user=$_POST['user'];
$db_pass=$_POST['pass'];
$db_dbname=$_POST['db_name'];
$file = 'db.php';
$host = '$host=" '.$test .' ";' ."\n";
$user = '$user="bob";' ."\n";
$pass = '$pass="test";' ."\n";
$db_name = '$$db_name="bob_ad";' ."\n";
$query ='$link = mysql_connect($host, $user, $pass);' ."\n";
$db = 'mysql_select_db($db_name);' ."\n";

//file_put_contents($file, $host);
//file_put_contents($file, $user, FILE_APPEND);
//file_put_contents($file,$pass, FILE_APPEND);
//file_put_contents($file,$db_name, FILE_APPEND);
//file_put_contents($file,$query, FILE_APPEND);
//file_put_contents($file,$db, FILE_APPEND);

echo"File Done <br> $db_host";
}
else
{
echo"<form name='form1' method='post' action=''>

<table width='259' height='192' border='1' align='center'>
  <tr>
    <td colspan='2'>Data Base Conntection </td>
  </tr>
  <tr>
    <td width='140'>Host</td>
    <td width='103'><label>
      <input type='text' name='host' id='host'>
    </label></td>
  </tr>
  <tr>
    <td>Username</td>
    <td><label>
      <input type='text' name='user' id='usern'>
    </label></td>
  </tr>
  <tr>
    <td>Password</td>
    <td><label>
      <input type='text' name='pass' id='pass'>
    </label></td>
  </tr>
  <tr>
    <td>Database Name</td>
    <td><label>
      <input type='text' name='db_name' id='db_name'>
    </label></td>
  </tr>
  <tr>
    <td colspan='2' align='center'><label>
      <input type='submit' name='Submit' id='Submit' value='Submit'>
    </label></td>
  </tr>
</table>
<form name='form1' method='post' action=''>
</form>";
}
?>



thanks bob

 

Link to comment
https://forums.phpfreaks.com/topic/179382-solved-field-chack/
Share on other sites

if(isset($_POST['Submit'])){
if($_POST['host'] =="") {
echo"Please Fill Out the Host Filed";

}
if($_POST['user'] =="") {
echo"<br>Please fill Out the Username Filed";
}
if($_POST['pass'] =="") {
echo"<br>Please Fill Out the Password";
}
if($_POST['db_name'] =="") {
echo"<br>please fill Out the Databases name";
}

 

You want to exit the script when those if statements run true. if you don't, as it is now, it will just tell you you should fill out what ever field, but still do the query.

 

if(isset($_POST['Submit'])){
if($_POST['host'] =="") {
echo"Please Fill Out the Host Filed";
exit();
}
if($_POST['user'] =="") {
echo"<br>Please fill Out the Username Filed";
exit();
}
if($_POST['pass'] =="") {
echo"<br>Please Fill Out the Password";
exit();
}
if($_POST['db_name'] =="") {
echo"<br>please fill Out the Databases name";
exit();
}

 

you could also do something like

$error = false;
if(isset($_POST['Submit'])){
if($_POST['host'] =="") {
echo"Please Fill Out the Host Filed";
$error = true;
}
if($_POST['user'] =="") {
echo"<br>Please fill Out the Username Filed";
$error = true;
}
if($_POST['pass'] =="") {
echo"<br>Please Fill Out the Password";
$error = true;
}
if($_POST['db_name'] =="") {
echo"<br>please fill Out the Databases name";
$error = true;
}

if ($error){
exit();
}

if you wanted to get all the error messages

Link to comment
https://forums.phpfreaks.com/topic/179382-solved-field-chack/#findComment-946502
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.