Jump to content

Grodo

Members
  • Posts

    74
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Grodo's Achievements

Member

Member (2/5)

0

Reputation

  1. Ok I figured it to check against resources you have to use the is_resource function in php http://us2.php.net/manual/en/function.is-resource.php
  2. How can I run a check on $admin to see if the connection to the db was successful? $admin echos out Resource id #1 when the connection is successful or displays the error if it isnt. However I can not check if $admin=='Resource id #1' for some reason. It just tends to ignore that the check is even there. if(isset($_POST["submit"])) { $admin=openDB($_SERVER['SERVER_ADDR'],msql_database,$_POST['username'],$_POST['password']); } else { show_admin(); } and this is the openDB function function openDB($server,$db,$user,$password) { $MYSQL_Server = $server; $MYSQL_DB = $db; $MYSQL_User = $user; $MYSQL_Password = $password; // Connect to database $dbID = mysql_connect($MYSQL_Server, $MYSQL_User, $MYSQL_Password) or die("<p>Unable to connect to the ' . 'database server at this time.</p>"); mysql_select_db( $MYSQL_DB ) or die("'<p>Unable to locate Catalog Request ' . 'database at this time.</p>'"); return( $dbID ); } and this is the showAdmin function function show_Admin() { global $HTTP_POST_VARS; ?> <form method="post" action=""> <table bord"0" width="100%" cellpadding="5" cellspacing="0"> <tr> <td><b>Username</b></td> <td><input type="text" name="username" size="25"></td> </tr> <tr> <td><b>Password</b></td> <td><input type="text" name="password" size="25"></td> </tr> <tr> <td> </td> <td> <input type="submit" name="submit" value="Send"> <input type="reset" value="Reset"> </td> </tr> </table> <?php }
  3. Ok I figured it out had to use a ghetto if statement (HEY IT WORKS) Still open for suggestions! //Check if one of the boxes is selected If ($tm==1) { // Do Nothing } elseif ($fm==1) { // Do Nothing } elseif ($sm==1) { // Do Nothing } else { $print_again = true; $message[]="Please select a catalog"; }
  4. Hello Thanks for looking at my post... So here is the scoop. I have three checkboxes (toolmag,sinkmag,faucetmag). What I am trying to do is have php check if one or more of the checkboxes are checked. I akready got the validation code down now all that is left is to form the IF and Or statement. This is the part im lost one. I know that if statments can have multiple conditions. But how can you tell the if statement if this condition is not met go to the next and when non of the conditions meet go to the else. I know that in Java the operator was ||. Attached below is the checkbox html code as well as the php code for checkbox validation. <input type="checkbox" name="toolmag">Tool Catalog<BR> <input type="checkbox" name="sinkmag">Vanity / Stainless Steel Sink Catalog<BR> <input type="checkbox" name="faucetmag">Faucet Catalog<BR> // CheckBox Tool Cat if($_POST['toolmag']) { $tm=1; } else { $tm=0; } // CheckBox Sink Cat if($_POST['sinkmag']) { $sm=1; } else { $sm=0; } // CheckBox Faucet Cat if($_POST['faucetmag']) { $fm=1; } else { $fm=0; }
  5. Seems like my host is rubish I would love to see that loop work. I just cant get it
  6. Hi, Ok I have a fuction it works great however its really slow and lags the page. I was wondering what i could do to speed it up a bit. I was thinking to make a for loop to check variables such as this: $sizeBlah=sizeof($message); $listVars[fname] = "fname"; $listVars[lname] = "lname"; $listMessage[0] = "Please insert you first name"; $listMessage[1] = "Please insert you last name"; for ($blah=0;$blah <=$sizeBlah;$blah++) { global $HTTP_POST_VARS, $error, $print_again, $message; // Validate first name $error[$listVars[$blah]] = false; if($_POST[$listVars[$blah]]=="") { $error[$listVars[$blah]] = true; $print_again = true; $message[]=$listMessage[$blah]; } } However I cant get this to work function check_form() { global $HTTP_POST_VARS, $error, $print_again, $message; // Validate first name $error['fname'] = false; if($_POST["fname"]=="") { $error['fname'] = true; $print_again = true; $message[]="Please insert you first name<br>"; } // Validate last name $error['lname'] = false; if($_POST["lname"]=="") { $error['lname'] = true; $print_again = true; $message[]="Please insert you last name<br>"; } // Validate Address $error['address1'] = false; if($_POST["address1"]=="") { $error['address1'] = true; $print_again = true; $message[]="Please enter a valid address<br>"; } // Validate City $error['city'] = false; if($_POST["city"]=="") { $error['city'] = true; $print_again = true; $message[]="Please enter a valid city<br>"; } // Validate State $error['state'] = false; if($_POST["state"]=="") { $error['state'] = true; $print_again = true; $message[]="Please enter a valid State or Territory<br>"; } // Validate Country $error['country'] = false; if($_POST["country"]=="") { $error['country'] = true; $print_again = true; $message[]="Please enter a valid country<br>"; } // Validate Postal code $error['zip'] = false; if($_POST["zip"]=="") { $error['zip'] = true; $print_again = true; $message[]="Please enter a valid zip<br>"; } }
  7. Your not escaping your quotes and not passing a value this is my guess <?php print"<a href='delete.php?emp_id={$emp_id['emp_id']}'>Remove</a><br />";?></td> try this <?php print"<a href='delete.php?emp_id={$emp_id['.$emp_id.']}'>Remove</a><br />";?></td> I am still learning php but that what i assume is going on
  8. Ok thanks to every one for the help i received the problem was a simple logic error.... The hidden div was on top when the browser read it it saw that it was calling $message at the time $message was = NULL; and unfortunally the variables in php dont update after they have been read. For those following this thread here is the now working code. Always Thanking, GRODO <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <LINK REL=StyleSheet HREF="dimming.css" TYPE="text/css"> <SCRIPT LANGUAGE="JavaScript" SRC="dimmingdiv.js"> </script> <script language="javascript"> function displayWindow() { var w, h, l, t; w = 400; h = 200; l = screen.width/4; t = screen.height/4; // no title // displayFloatingDiv('windowcontent', '', w, h, l, t); // with title displayFloatingDiv('windowcontent', 'Floating and Dimming Div', w, h, l, t); } </script> <style type="text/css"> body, table { font-size:13px; font-family:verdana,arial,helvetica,sans-serif; color:#000; background-color:#FFF; } body { margin:50px; } input, select, textarea { font-size:13px; font-family:verdana,arial,helvetica,sans-serif; } h1 { font-family:Arial, Verdana, Helvetica, Lucida, sans-serif; font-size:22px; color:maroon; margin:0px 0px 30px 0px; } .formErrors { color:maroon; } </style> <title>Form Validation</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php $HTTP_POST_VARS = NULL; $print_again = NULL; $error = NULL; $message = NULL; function error_bool($error, $field) { if($error[$field]) { print("<td style=color:red>"); } else { print("<td>"); } } function show_form() { global $HTTP_POST_VARS, $print_again, $error; ?> <form method="post" action=""> <table bord"0" width="100%" cellpadding="5" cellspacing="0"> <tr> <?php error_bool($error, "fname"); ?><b>First Name *</b></td> <td><input type="text" name="fname" value="<?php $_REQUEST['fname'] ?>" size="25"></td> </tr> <tr> <?php error_bool($error, "lname"); ?><b>Last Name *</b></td> <td><input type="text" name="lname" value="<?php $_REQUEST['lname'] ?>" size="25"></td> </tr> <tr> <td>Email</td> <td><input type="text" name="email" value="<?php $_REQUEST['email'] ?>" size="25"></td> </tr> <tr> <td>Company</td> <td><input type="text" name="company" value="<?php $_POST['company'] ?>" size="25"></td> </tr> <tr> <?php error_bool($error, "address1"); ?><b>Address 1*</b></td> <td><input type="text" name="address1" value="<?php $_REQUEST['address1'] ?>" size="25"></td> </tr> <tr> <td>Address 2</td> <td><input type="text" name="address2" value="<?php $_REQUEST['address2'] ?>" size="25"></td> </tr> <tr> <?php error_bool($error, "city"); ?><b>City*</b></td> <td><input type="text" name="city" value="<?php $_REQUEST['city'] ?>" size="25"></td> </tr> <tr> <?php error_bool($error, "state"); ?><b>State / Territory*</b></td> <td><input type="text" name="state" value="<?php $_REQUEST['state'] ?>" size="25"></td> </tr> <tr> <?php error_bool($error, "country"); ?><b>Country*</b></td> <td><input type="text" name="country" value="<?php $_REQUEST['country'] ?>" size="25"></td> </tr> <tr> <?php error_bool($error, "zip"); ?><b>Postal Code*</b></td> <td><input type="text" name="zip" value="<?php $_REQUEST['zip'] ?>" size="25"></td> </tr> <tr> <td>Phone</td> <td><input type="text" name="phone" value="<?php $_REQUEST['phone'] ?>" size="25"></td> </tr> <tr> <td><b>Catalog</b></td> <td> <input type="checkbox" name="toolmag">Tool Catalog<BR> <input type="checkbox" name="sinkmag">Vanity / Stainless Steel Sink Catalog<BR> <input type="checkbox" name="faucetmag">Faucet Catalog<BR> </td> </tr> <tr> <td>Special Instructions</td> <td> <textarea name="message" cols="50" rows="8"><?php $_REQUEST['message'] ?></textarea> </td> </tr> <tr> <td> </td> <td> <input type="submit" name="submit" value="Send"> <input type="reset" value="Reset"> </td> </tr> </table> </form> <a href="javascript:displayWindow();">Here</a> <? } if(isset($_POST["submit"])) { check_form(); } else { show_form(); } // Function to check the form function check_form() { global $HTTP_POST_VARS, $error, $print_again, $message; // Validate first name $error['fname'] = false; if($_POST["fname"]=="") { $error['fname'] = true; $print_again = true; $message[]="Please insert you first name<br>"; } // Validate last name $error['lname'] = false; if($_POST["lname"]=="") { $error['lname'] = true; $print_again = true; $message[]="Please insert you last name<br>"; } // Validate Address $error['address1'] = false; if($_POST["address1"]=="") { $error['address1'] = true; $print_again = true; $message[]="Please enter a valid address<br>"; } // Validate City $error['city'] = false; if($_POST["city"]=="") { $error['city'] = true; $print_again = true; $message[]="Please enter a valid city<br>"; } // Validate State $error['state'] = false; if($_POST["state"]=="") { $error['state'] = true; $print_again = true; $message[]="Please enter a valid State or Territory<br>"; } // Validate Country $error['country'] = false; if($_POST["country"]=="") { $error['country'] = true; $print_again = true; $message[]="Please enter a valid country<br>"; } // Validate Postal code $error['zip'] = false; if($_POST["zip"]=="") { $error['zip'] = true; $print_again = true; $message[]="Please enter a valid zip<br>"; } if($print_again) { show_form(); echo '<div style="width: 518px; height: 400px;visibility:hidden" id="windowcontent"> <table > <tr> <td>Your Form Has The Following Errors:</td> </tr> <tr> <td>'.$message[0].'</td> </tr> <tr> <td>'.$message[1].'</td> </tr> <tr> <td>'.$message[2].'</td> </tr> <tr> <td>'.$message[3].'</td> </tr> <tr> <td>'.$message[4].'</td> </tr> <tr> <td>'.$message[5].'</td> </tr> <tr> <td>'.$message[6].'</td> </tr> </table> </div>'; echo "<SCRIPT LANGUAGE='javascript'>displayWindow();</SCRIPT>"; } else { show_form(); $message[]="All Fields are valid <br> Now, In this way you can validate the other textfield as well<br> You can insert data into table"; } } // for ($x=1;$x<=6;$x++) { echo "$message[$x]"; } ?> <!-- the following hidden div will be used by the script --> </body> </html>
  9. Alright! I got one of the messages to appear! However now the trick is to cycle through the array and display all errors. The problem was I was echoing and had a var with a semicolon ending the line echo ' Echo some stuff' .$message;. 'Some more stuff; So that error has been fixed
  10. I think I know what might be wrong... The div is at the top so when the browser reads it it sees $message and sets it to null so what i need to echo the div out escape quotes and then combine the rest this is my whole code I am still trying to figure out y its giving me an unexpected . error. (Isnt the . operator in php the same as + in js?) <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <LINK REL=StyleSheet HREF="dimming.css" TYPE="text/css"> <SCRIPT LANGUAGE="JavaScript" SRC="dimmingdiv.js"> </script> <script language="javascript"> function displayWindow() { var w, h, l, t; w = 400; h = 200; l = screen.width/4; t = screen.height/4; // no title // displayFloatingDiv('windowcontent', '', w, h, l, t); // with title displayFloatingDiv('windowcontent', 'Floating and Dimming Div', w, h, l, t); } </script> <style type="text/css"> body, table { font-size:13px; font-family:verdana,arial,helvetica,sans-serif; color:#000; background-color:#FFF; } body { margin:50px; } input, select, textarea { font-size:13px; font-family:verdana,arial,helvetica,sans-serif; } h1 { font-family:Arial, Verdana, Helvetica, Lucida, sans-serif; font-size:22px; color:maroon; margin:0px 0px 30px 0px; } .formErrors { color:maroon; } </style> <title>Form Validation</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php $HTTP_POST_VARS = NULL; $print_again = NULL; $error = NULL; $message = NULL; function error_bool($error, $field) { if($error[$field]) { print("<td style=color:red>"); } else { print("<td>"); } } function show_form() { global $HTTP_POST_VARS, $print_again, $error; ?> <form method="post" action=""> <table bord"0" width="100%" cellpadding="5" cellspacing="0"> <tr> <?php error_bool($error, "fname"); ?><b>First Name *</b></td> <td><input type="text" name="fname" value="<?php $_REQUEST['fname'] ?>" size="25"></td> </tr> <tr> <?php error_bool($error, "lname"); ?><b>Last Name *</b></td> <td><input type="text" name="lname" value="<?php $_REQUEST['lname'] ?>" size="25"></td> </tr> <tr> <td>Email</td> <td><input type="text" name="email" value="<?php $_REQUEST['email'] ?>" size="25"></td> </tr> <tr> <td>Company</td> <td><input type="text" name="company" value="<?php $_POST['company'] ?>" size="25"></td> </tr> <tr> <?php error_bool($error, "address1"); ?><b>Address 1*</b></td> <td><input type="text" name="address1" value="<?php $_REQUEST['address1'] ?>" size="25"></td> </tr> <tr> <td>Address 2</td> <td><input type="text" name="address2" value="<?php $_REQUEST['address2'] ?>" size="25"></td> </tr> <tr> <?php error_bool($error, "city"); ?><b>City*</b></td> <td><input type="text" name="city" value="<?php $_REQUEST['city'] ?>" size="25"></td> </tr> <tr> <?php error_bool($error, "state"); ?><b>State / Territory*</b></td> <td><input type="text" name="state" value="<?php $_REQUEST['state'] ?>" size="25"></td> </tr> <tr> <?php error_bool($error, "country"); ?><b>Country*</b></td> <td><input type="text" name="country" value="<?php $_REQUEST['country'] ?>" size="25"></td> </tr> <tr> <?php error_bool($error, "zip"); ?><b>Postal Code*</b></td> <td><input type="text" name="zip" value="<?php $_REQUEST['zip'] ?>" size="25"></td> </tr> <tr> <td>Phone</td> <td><input type="text" name="phone" value="<?php $_REQUEST['phone'] ?>" size="25"></td> </tr> <tr> <td><b>Catalog</b></td> <td> <input type="checkbox" name="toolmag">Tool Catalog<BR> <input type="checkbox" name="sinkmag">Vanity / Stainless Steel Sink Catalog<BR> <input type="checkbox" name="faucetmag">Faucet Catalog<BR> </td> </tr> <tr> <td>Special Instructions</td> <td> <textarea name="message" cols="50" rows="8"><?php $_REQUEST['message'] ?></textarea> </td> </tr> <tr> <td> </td> <td> <input type="submit" name="submit" value="Send"> <input type="reset" value="Reset"> </td> </tr> </table> </form> <a href="javascript:displayWindow();">Here</a> <? } if(isset($_POST["submit"])) { check_form(); } else { show_form(); } // Function to check the form function check_form() { global $HTTP_POST_VARS, $error, $print_again, $message; // Validate first name $error['fname'] = false; if($_POST["fname"]=="") { $error['fname'] = true; $print_again = true; $message[]="Please insert you first name<br>"; } // Validate last name $error['lname'] = false; if($_POST["lname"]=="") { $error['lname'] = true; $print_again = true; $message[]="Please insert you last name<br>"; } // Validate Address $error['address1'] = false; if($_POST["address1"]=="") { $error['address1'] = true; $print_again = true; $message[]="Please enter a valid address<br>"; } // Validate City $error['city'] = false; if($_POST["city"]=="") { $error['city'] = true; $print_again = true; $message[]="Please enter a valid city<br>"; } // Validate State $error['state'] = false; if($_POST["state"]=="") { $error['state'] = true; $print_again = true; $message[]="Please enter a valid State or Territory<br>"; } // Validate Country $error['country'] = false; if($_POST["country"]=="") { $error['country'] = true; $print_again = true; $message[]="Please enter a valid country<br>"; } // Validate Postal code $error['zip'] = false; if($_POST["zip"]=="") { $error['zip'] = true; $print_again = true; $message[]="Please enter a valid zip<br>"; } if($print_again) { show_form(); echo '<div style="width: 518px; height: 287px;visibility:hidden" id="windowcontent"> <table > <tr> <td>Your Form Has The Following Errors:</td> </tr> <tr> <td>$message</td> </tr> <tr><td colspan="2"><br />Click the X to close</td></tr> </table> </div>'; echo "<SCRIPT LANGUAGE='javascript'>displayWindow();</SCRIPT>"; } else { show_form(); $message[]="All Fields are valid <br> Now, In this way you can validate the other textfield as well<br> You can insert data into table"; } } // for ($x=1;$x<=6;$x++) { echo "$message[$x]"; } ?> <!-- the following hidden div will be used by the script --> </body> </html>
  11. Ok i tried to move globals outside of the function and then my error highlighting stopped working. I put the globals back and boom error highlighting works. Seems like message is still coming null should I maybe make a $string = checkform(). Or is there something wrong with there globals global $HTTP_POST_VARS, $error, $print_again, $message;
  12. That doesnt seem like that the answer... But thanks! Now do I put <td> <?php foreach ($message as $v) { echo "-$v"; } ?> </td> ? Seems that $message is NULL but when i set a for loop in the function it displays the messages Could it be because the function is not returning anything?
  13. Well that expains it came back as NULL. Seems to me like the function is not setting $message which lists all the errors. Here is code for the function that should be set $message to the error. function check_form() { global $HTTP_POST_VARS, $error, $print_again, $message; // Validate first name $error['fname'] = false; if($_POST["fname"]=="") { $error['fname'] = true; $print_again = true; $message[0]="Please insert you first name<br>"; } // Validate last name $error['lname'] = false; if($_POST["lname"]=="") { $error['lname'] = true; $print_again = true; $message[1]="Please insert you last name<br>"; } // Validate Address $error['address1'] = false; if($_POST["address1"]=="") { $error['address1'] = true; $print_again = true; $message[2]="Please enter a valid address<br>"; } // Validate City $error['city'] = false; if($_POST["city"]=="") { $error['city'] = true; $print_again = true; $message[3]="Please enter a valid city<br>"; } // Validate State $error['state'] = false; if($_POST["state"]=="") { $error['state'] = true; $print_again = true; $message[4]="Please enter a valid State or Territory<br>"; } // Validate Country $error['country'] = false; if($_POST["country"]=="") { $error['country'] = true; $print_again = true; $message[5]="Please enter a valid country<br>"; } // Validate Postal code $error['zip'] = false; if($_POST["zip"]=="") { $error['zip'] = true; $print_again = true; $message[6]="Please enter a valid zip<br>"; } if($print_again) { show_form(); echo "<SCRIPT LANGUAGE='javascript'>displayWindow();</SCRIPT>"; } else { show_form(); $message="All Fields are valid <br> Now, In this way you can validate the other textfield as well<br> You can insert data into table"; } }
  14. Hello, Thank you for your time. In the code attached below it does not seem like the loop is being activated am I doing something wrong? $message is array and is marked as a global and contains up to a total of 6 values. I am really stumped on this one PLEASE HELP Thanks Grodo <div style="width: 518px; height: 287px;visibility:hidden" id="windowcontent"> <table > <tr> <td>Your Form Has The Following Errors:</td> </tr> <tr> <td><?php for ($xi=1;$xi<=6;$xi++) { echo "$message[$xi]"; } ?><td> </tr> <tr><td colspan="2"><br />Click the X to close</td></tr> </table> </div>
  15. I got it working on extemely inefficent code but if some one can figure out how to incorperate a function with a loop that would be awesome for the time being im just gonna be using the code posted below.... Who knows it might help some one out. <?php // Database info // Database: xxx_1234 // User: xxx_5678 // Passwd: xxpassxx // Table Name: xtable // MYSQL DB Host: 127.0.0.0 //Define Globals global $error; global $postVar; global $errored; global $fname; global $lname; global $address1; global $city; global $state; global $country; global $zip; // Connect to the database server $dbcnx = @mysql_connect('127.0.0.0', 'xxx_5678', 'xxpassxx'); if (!$dbcnx) { exit('<p>Unable to connect to the ' . 'database server at this time.</p>'); } // Select the Catalog request database if (!@mysql_select_db('xxx_1234')) { exit('<p>Unable to locate Catalog Request ' . 'database at this time.</p>'); } if ($_POST['company'] != NULL) { $company = $_POST['company']; $sql = "INSERT INTO xtable SET company='$company'"; mysql_query($sql); echo 'Successfully wrote' . $company .'to Database'; } else { include 'catalog.php'; } ?>
×
×
  • 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.