bob2588 Posted October 28, 2009 Share Posted October 28, 2009 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 More sharing options...
GingerRobot Posted October 28, 2009 Share Posted October 28, 2009 So what is your question? Does the above not work? What does it do? What doesn't it do? Link to comment https://forums.phpfreaks.com/topic/179382-solved-field-chack/#findComment-946501 Share on other sites More sharing options...
mikesta707 Posted October 28, 2009 Share Posted October 28, 2009 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 More sharing options...
bob2588 Posted October 28, 2009 Author Share Posted October 28, 2009 it works but if the 4 fields form the form are not filled out is tell them to go back and fix it but it still make the file db.php i want it to check to see if they are filled out if they are then make the file if not tell them to go back bob Link to comment https://forums.phpfreaks.com/topic/179382-solved-field-chack/#findComment-946510 Share on other sites More sharing options...
bob2588 Posted October 28, 2009 Author Share Posted October 28, 2009 Thanks mikesta707 that whats i was trying to do bob Link to comment https://forums.phpfreaks.com/topic/179382-solved-field-chack/#findComment-946511 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.