note 4835 deleted from Control Structures by ronabop

From: Date: Fri, 01 Sep 2000 02:31:42 +0000
Subject: note 4835 deleted from Control Structures by ronabop
Groups: php.notes 
Request: Send a blank email to php-notes+get-3833@lists.php.net to get a copy of this message
Exmaple: i have a form which passes values to another form which enters info into mysqlDB but first i want it to check if all fields are true,if thats the cse then check that there are no entried in the MySQL DB matching the one entered i tried somethin like this: <? if ($c_name && $ip_add && $rack && $rack_p && $localtion && $port) { mysql_select_db (test); $result = mysql_query ("SELECT * FROM information WHERE ip_add = '$ip_add' "); if ($row = mysql_fetch_array($result)) { print ("<font color=red><h3>Error: The IP_Address you entered</h4> "); print ("<font color=black><h3>IP_Address: </font><font color=red>$ip_add</font></h3>"); print ("<font color=red><h3> has been taken. Go back and enter a valid IP_Address.</h3>"); print (""); } else { mysql_select_db (test); $result = mysql_query ("SELECT * FROM information WHERE port = '$port' "); if ($row = mysql_fetch_array($result)) { print ("<font color=red><h3>Error: The Switch_Port number you entered</h4> "); print ("<font color=black><h3>Switch_Port: </font><font color=red>$port</font></h3>"); print ("<font color=red><h3> has been taken. Go back and enter a Port number.</h3>"); print (""); } else { trim ($c_name); trim ($ip_add); trim ($rack); trim ($rack_p); trim ($localtion); trim ($port); $query = "insert into information values ('$c_name','$ip_add','$rack','$rack_p','$localtion','$port')"; $result = mysql_db_query("test", $query); echo "<img src="img/hnet.gif"><font color=red><h2>Data inserted successfully.</font></h2><br>"; print "<b>The following information was entered to BOSNOC Database:</b><br><br>"; print "<b>Company_Name:</b> <font color=red>$c_name</font><br>"; print "<b>IP_Address:</b> <font color=red>$ip_add</font><br>"; print "<b>Rack:</b> <font color=red>$rack</font><br>"; print "<b>Rack_Port:</b> <font color=red>$rack_p</font><br>"; print "<b>Location:</b> <font color=red>$localtion</font><br>"; print "<b>Switch_Port:</b> <font color=red>$port</font>"; } } }// end of first "if" else { echo "<br>"; echo "<br>"; echo "<font color=red><h3>All Fields are required.</h3></font>"; echo "<font color=red><h4>Please go back and enter information.</h4></font>"; echo "<font color=red><h4>( please type UNKNOWN if you don't know the information )</h4></font>"; } include ('linkbottom.txt'); ?> </body> </html> </pre>

« previous php.notes (#3833) next »