-
Posts
780 -
Joined
-
Last visited
Everything posted by mikebyrne
-
Return Form if no option has been selected
mikebyrne replied to mikebyrne's topic in Javascript Help
The script im using is: <script type="text/javascript"> function valid(f){ var rad=f['something'], i=0, r; while(r=rad[i++]){ if(r.checked){return true} } alert('Please select a radio button option');return false } </script> -
Return Form if no option has been selected
mikebyrne replied to mikebyrne's topic in Javascript Help
My code now looks like this but I cant get it to validate <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>e-commerce admin page sample | item</title> <link href="../Admin_files/admin.css" rel="stylesheet" type="text/css" /> <script type="text/JavaScript" src="../Admin_files/wrapper.js"></script> </head> <body> <div id="Box"> <div id="logoBox"><a href="http://www.btrax.com/" target="_blank"><img src="../Admin_files/logo.gif" width="51" height="125" border="0" /></a></div> <div id="contentBox"> <!-- logo start --> <div id="container"> <div class="padTop28"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <!-- logo finish --> <!-- menu start --> <div id="container"> <div id="menu1"> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../admin_files/start.php" class="black">Order</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../admin_files/sales.php" class="black">Sales</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_on"><!-- --></div> <div id="menu_text_on"><a href="../admin_files/list.php" class="black_on">Edit item</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../shipping/current.php" class="black">Postage fee</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../shipping/adminreg.php" class="black">Add User</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../shipping/current.php" class="black">Add Product</a></div> <div id="menu_space1"><!-- --></div> </div> <div class="clr"><!-- --></div> <div class="clr"><!-- --></div> <div class="padTop5"><!-- --></div> <div class="clr"><!-- --></div> <div id="dotted"><!-- --></div> <div class="clr"><!-- --></div> <div class="padTop5"><!-- --></div> <div class="clr"><!-- --></div> <div id="menu2"> <div id="menu_hide"><!-- --></div> <div id="menu_text_off"> </div> <div id="menu_space1"><!-- --></div> <div class="clr"><!-- --></div> <!-- --> </div> <div id="menu_space1"><!-- --></div> <div id="menu_on"><!-- --></div> <div id="menu_text_on"><a href="../admin_files/list.php" class="black_on">Games</a></div> <div id="menu_space2"> <!-- --> </div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../admin_files/dvdlist.php" class="black">DVD</a></div> <div id="menu_space2"> <!-- --> </div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../admin_files/cdlist.php" class="black">CD</a></div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> <!-- Double Space undernath CD --> <div class="clr"><!-- --></div> <div class="clr"><!-- --></div> <div class="padTop5"><!-- --></div> <div class="clr"><!-- --></div> <div class="clr"><!-- --></div> <div class="clr"><!-- --></div> <div class="padTop5"><!-- --></div> <div class="clr"><!-- --></div> <!-- menu finish --> <!-- top start --> <div id="container"> <div id="line"><!-- --></div> </div> <div class="clr"><!-- --></div> <div id="containerBg1"> <div class="padTop15"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <!-- top finish --> <!-- 1px space start --> <div id="containerBg1"> <div class="padTop1"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <!-- 1px space finish --> <!-- data top start --> <div id="containerBg3"> <div class="padTop1"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <!-- data top finish --> <!-- data content start --> <div id="containerBg4"> <!-- data start --> <form method="post" action="edit.php"> <table width="800" align="center" border="0" cellspacing="0" cellpadding="0"> <tr align="left"> <td><a href="#">SELECT</a></td> <td><a href="#">PRODCT NO</a></td> <td><a href="#">PRODUCT NAME</a></td> <td><a href="#">STOCK LEVEL</a></td> <td><a href="#">DISPLAY</a></td> <td><a href="#">PRICE</a></td> </tr> <script type="text/javascript"> function valid(f){ var rad=f['something'], i=0, r; while(r=rad[i++]){ if(r.checked){return true} } alert('Please select a radio button option');return false } </script> <?php // let's get some data include('adminconnect.php'); $query = "SELECT ProductNo,ProductName,Stockamount,Display,Price FROM Product WHERE Producttype = 'Game' "; $result = mysql_query($query) or die (mysql_error()); while ($row = mysql_fetch_array($result)){ // loop through and display ?> <tr align="left"> <td><input type="radio" value="<?php echo $row['ProductNo']; ?>" name="something" /></td> <td><a class="black"><?php echo $row['ProductNo'];?></a></td> <td><?php echo $row['ProductName'];?></td> <td><?php echo $row['Stockamount'];?></td> <td><?php echo $row['Display'] ;?></td> <td><?php echo $row['Price'];?></td> </tr> <tr><td colspan="6"><hr /></td><td></tr> <?php } ?> <tr><td><input type="submit" name="submit" value="Edit" /></td></tr> </table> </div> <div class="clr"><!-- --></div> <!-- data content finish --> <!-- data btm start --> <div id="containerBg3"> <div class="padTop1"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <!-- data btm finish --> <!-- btm start --> <div id="containerBg1"> <div class="padTop15"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <div id="container"> <div id="line"><!-- --></div> </div> <div class="clr"><!-- --></div> <div class="padTop16"><!-- --></div> <div class="clr"><!-- --></div> <!-- btm finish --> </div> </div> </body> </html> -
Return Form if no option has been selected
mikebyrne replied to mikebyrne's topic in Javascript Help
An example of the html output from the php code is: <tr align="left"> <td><input type="radio" value="1" name="something" /></td> <td><a class="black">1</a></td> <td>Call of Duty 4: Modern Warfare</td> <td>50</td> <td>yes</td> <td>55.99</td> </tr> <tr><td colspan="6"><hr /></td><td></tr> <tr align="left"> <td><input type="radio" value="2" name="something" /></td> <td><a class="black">2</a></td> <td>Assassin's Creed</td> <td>50</td> <td>yes</td> <td>55.99</td> </tr> <tr><td colspan="6"><hr /></td><td></tr> <tr align="left"> <td><input type="radio" value="5" name="something" /></td> <td><a class="black">5</a></td> <td>Ace Combat 6: Fires Of Liberation</td> <td>50</td> <td>yes</td> <td>55.99</td> </tr> <tr><td colspan="6"><hr /></td><td></tr> <tr align="left"> <td><input type="radio" value="3" name="something" /></td> <td><a class="black">3</a></td> <td>The Simpsons Game</td> <td>50</td> <td>yes</td> <td>57.99</td> </tr> <tr><td colspan="6"><hr /></td><td></tr> <tr align="left"> <td><input type="radio" value="4" name="something" /></td> <td><a class="black">4</a></td> <td>Need For Speed: ProStreet</td> <td>50</td> <td>yes</td> <td>55.99</td> </tr> -
Return Form if no option has been selected
mikebyrne replied to mikebyrne's topic in Javascript Help
Still cant get this to work!! -
At present my figures and table hedings arent perfectly in line. Would I be better having the table layout and sql BOTH within the PHP code? My code looks like: <form> <!-- data title start --> <div id="containerBg2"> <div class="padTop2"><!-- --></div> <div class="clr"><!-- --></div> <div class="titleBox"> <table width="850" border="0" cellspacing="0" cellpadding="0"> <tr align="left"> <td width="33"> </td> <td width="87"><a href="#">date</a></td> <td width="43" align="right"><a href="#">orders</a></td> <td width="118" align="right"><a href="#">revenue</a></td> <td width="569"> </td> </tr> </table> </div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <!-- data title finish --> <!-- 1px space start --> <div id="containerBg1"> <div class="padTop1"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <!-- 1px space finish --> <!-- data top start --> <div id="containerBg3"> <div class="padTop1"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <!-- data top finish --> <!-- data content start --> <div id="containerBg4"> <?php include('adminconnect.php'); $sql = mysql_query("SELECT * FROM sales "); while( $row = mysql_fetch_array($sql) ) { ?> <tr align="left"> <td width="87" align="center"><?php echo $row['Date'];?></td> <td width="43" align="Left"><?php echo $row['Total Orders'];?></td> <td width="118" align="center"><?php echo $row['Revenue'];?></td> </tr> <?php } ?> </table> <!-- data btm start --> <div id="containerBg3"> <div class="padTop1"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <!-- data btm finish --> <!-- btm start --> <div id="containerBg1"> <div class="padTop15"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <div id="container"> <div id="line"><!-- --></div> </div> <!-- btm finish --> </form>
-
At present my form loads and displays all goods "Games" from the database. If the user want to edit the detail the user selects the relevent radiobutton and presses edit However, at present I have no validation to return the form if the user selects NO option and presses Edit How can I code this validation using javascript?? Ive found an example but as a noobie to javascript im not sure how to combine it with my code Example <html> <title>Radio Button Validation</title> <body bgcolor="#FFFFFF"> <script language="JavaScript"> <!-- function radio_button_checker() { // set var radio_choice to false var radio_choice = false; // Loop from zero to the one minus the number of radio button selections for (counter = 0; counter < radio_form.radio_button.length; counter++) { // If a radio button has been selected it will return true // (If not it will return false) if (radio_form.radio_button[counter].checked) radio_choice = true; } if (!radio_choice) { // If there were no selections made display an alert box alert("Please select a letter.") return (false); } return (true); } --> </script> <form method="get" action="http://www.codeave.com/html/get.asp" onsubmit="return radio_button_checker()" name="radio_form"> <input type="radio" value="A" name="radio_button">A <br> <input type="radio" value="B" name="radio_button">B <br> <input type="radio" value="C" name="radio_button">C <br> <input type="radio" value="D" name="radio_button">D <br> <input type="submit" value="Submit"> </form> </body> </html> My full code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>e-commerce admin page sample | item</title> <link href="../Admin_files/admin.css" rel="stylesheet" type="text/css" /> <script type="text/JavaScript" src="../Admin_files/wrapper.js"></script> </head> <body> <div id="Box"> <div id="logoBox"><a href="http://www.btrax.com/" target="_blank"><img src="../Admin_files/logo.gif" width="51" height="125" border="0" /></a></div> <div id="contentBox"> <!-- logo start --> <div id="container"> <div class="padTop28"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <!-- logo finish --> <!-- menu start --> <div id="container"> <div id="menu1"> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../admin_files/new.php" class="black">order</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../admin_files/sales.php" class="black">sales</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_on"><!-- --></div> <div id="menu_text_on"><a href="../admin_files/list.php" class="black_on">Edit item</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../shipping/current.php" class="black">Postage fee</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../shipping/current.php" class="black">Add User</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../shipping/current.php" class="black">Add Product</a></div> <div id="menu_space1"><!-- --></div> </div> <div class="clr"><!-- --></div> <div class="clr"><!-- --></div> <div class="padTop5"><!-- --></div> <div class="clr"><!-- --></div> <div id="dotted"><!-- --></div> <div class="clr"><!-- --></div> <div class="padTop5"><!-- --></div> <div class="clr"><!-- --></div> <div id="menu2"> <div id="menu_hide"><!-- --></div> <div id="menu_text_off"> </div> <div id="menu_space1"><!-- --></div> <div class="clr"><!-- --></div> <!-- --> </div> <div id="menu_space1"><!-- --></div> <div id="menu_on"><!-- --></div> <div id="menu_text_on"><a href="../admin_files/list.php" class="black_on">Games</a></div> <div id="menu_space2"> <!-- --> </div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../admin_files/dvdlist.php" class="black">DVD</a></div> <div id="menu_space2"> <!-- --> </div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../admin_files/cdlist.php" class="black">CD</a></div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> <!-- Double Space undernath CD --> <div class="clr"><!-- --></div> <div class="clr"><!-- --></div> <div class="padTop5"><!-- --></div> <div class="clr"><!-- --></div> <div class="clr"><!-- --></div> <div class="clr"><!-- --></div> <div class="padTop5"><!-- --></div> <div class="clr"><!-- --></div> <!-- menu finish --> <!-- top start --> <div id="container"> <div id="line"><!-- --></div> </div> <div class="clr"><!-- --></div> <div id="containerBg1"> <div class="padTop15"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <!-- top finish --> <!-- 1px space start --> <div id="containerBg1"> <div class="padTop1"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <!-- 1px space finish --> <!-- data top start --> <div id="containerBg3"> <div class="padTop1"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <!-- data top finish --> <!-- data content start --> <div id="containerBg4"> <!-- data start --> <form method="post" action="edit.php"> <table width="800" align="center" border="0" cellspacing="0" cellpadding="0"> <tr align="left"> <td><a href="#">SELECT</a></td> <td><a href="#">PRODCT NO</a></td> <td><a href="#">PRODUCT NAME</a></td> <td><a href="#">STOCK LEVEL</a></td> <td><a href="#">DISPLAY</a></td> <td><a href="#">PRICE</a></td> </tr> <?php // let's get some data include('adminconnect.php'); $query = "SELECT ProductNo,ProductName,Stockamount,Display,Price FROM Product WHERE Producttype = 'GAMES' "; $result = mysql_query($query) or die (mysql_error()); while ($row = mysql_fetch_array($result)){ // loop through and display ?> <tr align="left"> <td><input type="radio" value="<?php echo $row['ProductNo']; ?>" name="something" /></td> <td><a class="black"><?php echo $row['ProductNo'];?></a></td> <td><?php echo $row['ProductName'];?></td> <td><?php echo $row['Stockamount'];?></td> <td><?php echo $row['Display'] ;?></td> <td><?php echo $row['Price'];?></td> </tr> <tr><td colspan="6"><hr /></td><td></tr> <?php } ?> <tr><td><input type="submit" name="submit" value="Edit" /></td></tr> </table> </div> <div class="clr"><!-- --></div> <!-- data content finish --> <!-- data btm start --> <div id="containerBg3"> <div class="padTop1"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <!-- data btm finish --> <!-- btm start --> <div id="containerBg1"> <div class="padTop15"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <div id="container"> <div id="line"><!-- --></div> </div> <div class="clr"><!-- --></div> <div class="padTop16"><!-- --></div> <div class="clr"><!-- --></div> <!-- btm finish --> </div> </div> </body> </html>
-
Return form if no option has been selected
mikebyrne replied to mikebyrne's topic in PHP Coding Help
In my case each radio button is generated by a loop so a little confused as to how i would name the radio buttons etc? Also how would I rename the form line below etc like your example as I use "something" in edit.php, the page that my edit button refers too <td><input type="radio" value="<?php echo $row['ProductNo']; ?>" name="something" /></td> -
Return form if no option has been selected
mikebyrne replied to mikebyrne's topic in PHP Coding Help
Looks very good, but I wouldnt have a clue where to start in terms of putting my code with that. Think I'll have to find the javascript section for this one !! -
Return form if no option has been selected
mikebyrne replied to mikebyrne's topic in PHP Coding Help
My complete code is actally: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>e-commerce admin page sample | item</title> <link href="../Admin_files/admin.css" rel="stylesheet" type="text/css" /> <script type="text/JavaScript" src="../Admin_files/wrapper.js"></script> </head> <body> <div id="Box"> <div id="logoBox"><a href="http://www.btrax.com/" target="_blank"><img src="../Admin_files/logo.gif" width="51" height="125" border="0" /></a></div> <div id="contentBox"> <!-- logo start --> <div id="container"> <div class="padTop28"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <!-- logo finish --> <!-- menu start --> <div id="container"> <div id="menu1"> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../admin_files/new.php" class="black">order</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../admin_files/sales.php" class="black">sales</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_on"><!-- --></div> <div id="menu_text_on"><a href="../admin_files/list.php" class="black_on">Edit item</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../shipping/current.php" class="black">Postage fee</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../shipping/current.php" class="black">Add User</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../shipping/current.php" class="black">Add Product</a></div> <div id="menu_space1"><!-- --></div> </div> <div class="clr"><!-- --></div> <div class="clr"><!-- --></div> <div class="padTop5"><!-- --></div> <div class="clr"><!-- --></div> <div id="dotted"><!-- --></div> <div class="clr"><!-- --></div> <div class="padTop5"><!-- --></div> <div class="clr"><!-- --></div> <div id="menu2"> <div id="menu_hide"><!-- --></div> <div id="menu_text_off"> </div> <div id="menu_space1"><!-- --></div> <div class="clr"><!-- --></div> <!-- --> </div> <div id="menu_space1"><!-- --></div> <div id="menu_on"><!-- --></div> <div id="menu_text_on"><a href="../admin_files/list.php" class="black_on">Games</a></div> <div id="menu_space2"> <!-- --> </div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../admin_files/dvdlist.php" class="black">DVD</a></div> <div id="menu_space2"> <!-- --> </div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="../admin_files/cdlist.php" class="black">CD</a></div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> <!-- Double Space undernath CD --> <div class="clr"><!-- --></div> <div class="clr"><!-- --></div> <div class="padTop5"><!-- --></div> <div class="clr"><!-- --></div> <div class="clr"><!-- --></div> <div class="clr"><!-- --></div> <div class="padTop5"><!-- --></div> <div class="clr"><!-- --></div> <!-- menu finish --> <!-- top start --> <div id="container"> <div id="line"><!-- --></div> </div> <div class="clr"><!-- --></div> <div id="containerBg1"> <div class="padTop15"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <!-- top finish --> <!-- 1px space start --> <div id="containerBg1"> <div class="padTop1"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <!-- 1px space finish --> <!-- data top start --> <div id="containerBg3"> <div class="padTop1"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <!-- data top finish --> <!-- data content start --> <div id="containerBg4"> <!-- data start --> <form method="post" action="edit.php"> <table width="800" align="center" border="0" cellspacing="0" cellpadding="0"> <tr align="left"> <td><a href="#">SELECT</a></td> <td><a href="#">PRODCT NO</a></td> <td><a href="#">PRODUCT NAME</a></td> <td><a href="#">STOCK LEVEL</a></td> <td><a href="#">DISPLAY</a></td> <td><a href="#">PRICE</a></td> </tr> <?php // let's get some data include('adminconnect.php'); $query = "SELECT ProductNo,ProductName,Stockamount,Display,Price FROM Product WHERE Producttype = 'GAMES' "; $result = mysql_query($query) or die (mysql_error()); while ($row = mysql_fetch_array($result)){ // loop through and display ?> <tr align="left"> <td><input type="radio" value="<?php echo $row['ProductNo']; ?>" name="something" /></td> <td><a class="black"><?php echo $row['ProductNo'];?></a></td> <td><?php echo $row['ProductName'];?></td> <td><?php echo $row['Stockamount'];?></td> <td><?php echo $row['Display'] ;?></td> <td><?php echo $row['Price'];?></td> </tr> <tr><td colspan="6"><hr /></td><td></tr> <?php } ?> <tr><td><input type="submit" name="submit" value="Edit" /></td></tr> </table> </div> <div class="clr"><!-- --></div> <!-- data content finish --> <!-- data btm start --> <div id="containerBg3"> <div class="padTop1"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <!-- data btm finish --> <!-- btm start --> <div id="containerBg1"> <div class="padTop15"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <div id="container"> <div id="line"><!-- --></div> </div> <div class="clr"><!-- --></div> <div class="padTop16"><!-- --></div> <div class="clr"><!-- --></div> <!-- btm finish --> </div> </div> </body> </html> I like the sound of the javascript option but i've no idea how to code it -
At present my form loads and displays all goods "Games" from the database. If the user want to edit the detail the user selects the relevent radiobutton and presses edit However, at present I have no validation to return the form if the user selects NO option and presses Edit How can I code this validation?? <!-- data start --> <form method="post" action="edit.php"> <table width="800" align="center" border="0" cellspacing="0" cellpadding="0"> <tr align="left"> <td><a href="#">SELECT</a></td> <td><a href="#">PRODCT NO</a></td> <td><a href="#">PRODUCT NAME</a></td> <td><a href="#">STOCK LEVEL</a></td> <td><a href="#">DISPLAY</a></td> <td><a href="#">PRICE</a></td> </tr> <?php // let's get some data include('adminconnect.php'); $query = "SELECT ProductNo,ProductName,Stockamount,Display,Price FROM Product WHERE Producttype = 'GAMES' "; $result = mysql_query($query) or die (mysql_error()); while ($row = mysql_fetch_array($result)){ // loop through and display ?> <tr align="left"> <td><input type="radio" value="<?php echo $row['ProductNo']; ?>" name="something" /></td> <td><a class="black"><?php echo $row['ProductNo'];?></a></td> <td><?php echo $row['ProductName'];?></td> <td><?php echo $row['Stockamount'];?></td> <td><?php echo $row['Display'] ;?></td> <td><?php echo $row['Price'];?></td> </tr> <tr><td colspan="6"><hr /></td><td></tr> <?php } ?> <tr><td><input type="submit" name="submit" value="Edit" /></td></tr> </table>
-
Thanks, just wasnt sure why it was used. Still cant figure out why im now getting the errors Im getting the following errors with the new code when all the fields are complete and valid got no address1 got no address1 got no address2 got no address3 got no address4 .gggggggggg.Error in SQL: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM adminusers WHERE username ='gggggggggg'' at line 1
-
Im getting the following errors with the new code when all the fields are complete and valid got no address1 got no address1 got no address2 got no address3 got no address4 .gggggggggg.Error in SQL: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM adminusers WHERE username ='gggggggggg'' at line 1
-
thanks for the help. What does the below command actually do? mysql_real_escape_string(trim($_POST['name']));
-
At present my form puts all the info into the database after validation as it should but when the form is returned to screen Name Address Address1 Address2 Address3 County Zip are still present and I cant figure out why these are showing and Address4 Telephone Username Email Passwod return blank as I want? my complete code is: <?php require_once("adminconnect.php"); $tbl_name="adminusers"; $name = $_POST['name']; $address = $_POST['address']; $address1 = $_POST['address1']; $address2 = $_POST['address2']; $address3 = $_POST['address3']; $address4 = $_POST['address4']; $county = $_POST['county']; $zip = $_POST['zip']; $telephone = $_POST['telephone']; $email = $_POST['email']; $password =$_POST['password']; $username = $_POST['username']; $num =$_POST ['num']; if($_POST["action"] == "signup"){ $valid=1; if ($_POST['name']=="") { echo 'got no name<br>'; $valid=0; $style_name = "background-color:#FF5959"; $error_name = "Your name seems to be mising?<br>"; } if ($address == "" || strlen($address) < 2) { echo 'got no address1<br>';//added by me to denote failure in this statement $valid=0; $style_address = "background-color:#FF5959"; $error_address = "There is a problem with the address field?<br>"; } if ($address1 == "" || strlen($address1) < 2) { echo 'got no address1<br>';//added by me to denote failure in this statement $valid=0; $style_address = "background-color:#FF5959"; $error_address1 = "There is a problem with the address field?<br>"; } if ($address2 == "" || strlen($address2) < 2) { echo 'got no address2<br>';//added by me to denote failure in this statement $valid=0; $style_address = "background-color:#FF5959"; $error_address2 = "There is a problem with the address field?<br>"; } if ($address3 == "" || strlen($address3) < 2) { echo 'got no address3<br>';//added by me to denote failure in this statement $valid=0; $style_address = "background-color:#FF5959"; $error_address3 = "There is a problem with the address field?<br>"; } if ($address4 == "" || strlen($address4) < 2) { echo 'got no address4<br>';//added by me to denote failure in this statement $valid=0; $style_address = "background-color:#FF5959"; $error_address4 = "There is a problem with the address field?<br>"; } if ($county == "" || strlen($county)<2) { echo 'got no county<br>'; $valid=0; $style_county = "background-color:#FF5959"; $error_county = "The County field is blank?<br>"; } if ($zip == "" || strlen($zip)<2) { echo 'got no zip<br>'; $valid=0; $style_zip = "background-color:#FF5959"; $error_zip = "Theres a problem with the zip code?<br>"; } if (!eregi("^[0-9]+",$telephone)) { echo 'got no phone<br>'; $valid=0; $style_telephone = "background-color:#FF5959"; $error_telephone = "Theres a problem with the telephone number?<br>"; } if (!eregi("^[A-Za-z0-9.-]+",$email)) { echo 'got no mail'; $valid=0; $style_email = "background-color:#FF5959"; $error_email = "Theres a problem with the email address?<br>"; } if ($password == "" || strlen($password)<7) { echo 'got no password'; $valid=0; $style_password = "background-color:#FF5959"; $error_password = "Theres a problems with your password?<br>"; } $user = mysql_real_escape_string(htmlspecialchars($_POST['username'])); $sql = "SELECT name FROM adminusers WHERE username ='$user'"; echo ".$user."; $result = mysql_query($sql) or die("Error in SQL: ".mysql_error()); $row = mysql_fetch_array($result); $count = mysql_num_rows($result); $test = $row['name']; if ($count > 0) { // username should only exist once. $valid=0; $style_username = "background-color:#FF5959"; $error_username = "Error! The username " . $user . " already exists in the database."; } if ($password == "" || strlen($password)<7) { $valid=0; $style_password = "background-color:#FF5959"; $error_password = "Theres a problems with your password?<br>"; } if ($valid==1) { $sql="INSERT INTO $tbl_name(name, address, address1, address2, address3, address4, county, zip, telephone, email, username, password, usertype)VALUES('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password' , 2)"; echo $sql; $result=mysql_query($sql)or die(mysql_error()."<p>With Query<br>$sql"); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>e-commerce admin page sample |item</title> <link href="/Admin_files/admin.css" rel="stylesheet" type="text/css" /> <script type="text/JavaScript" src="file:///C|/Users/Mike/Documents/Admin_files/wrapper.js"></script> </head> <body> <div id="Box"> <div id="logoBox"><a href="http://www.btrax.com/" target="_blank"><img src="file:///C|/Users/Mike/Documents/Admin_files/logo.gif" width="51" height="125" border="0" /></a></div> <div id="contentBox"> <!-- logo start --> <div id="container"> <div class="padTop28"> <!-- --> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- logo finish --> <!-- menu start --> <div id="container"> <div id="menu1"> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="file:///C|/Users/Mike/Documents/admin_files/new.php" class="black"> Order</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="file:///C|/Users/Mike/Documents/admin_files/sales.php" class="black"> Sales</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_on"><a href="file:///C|/Users/Mike/Documents/admin_files/list.php" class="black"> Edit item</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="file:///C|/Users/Mike/Documents/shipping/current.php" class="black"> Postage fee</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_on"><!-- --></div> <div id="menu_text_off"><a href="file:///C|/Users/Mike/Documents/shipping/current.php" class="black_on"> Add User</a></div> <div id="menu_space1"><!-- --></div> <div id="menu_off"><!-- --></div> <div id="menu_text_off"><a href="file:///C|/Users/Mike/Documents/shipping/current.php" class="black"> Add Product</a></div> <div id="menu_space1"><!-- --></div> </div> <div class="clr"><!-- --></div> <div class="clr"> <!-- --> </div> <div class="padTop5"> <!-- --> </div> <div class="clr"> <!-- --> </div> <div id="dotted"> <!-- --> </div> <div class="clr"> <!-- --> </div> <div class="padTop5"> <!-- --> </div> <div class="clr"> <!-- --> </div> <div id="menu2"> <div id="menu_hide"> <!-- --> </div> <div id="menu_text_off"> </div> <div id="menu_space1"> <!-- --> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <div class="padTop38"> <!-- --> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- menu finish --> <!-- top start --> <div id="container"> <div id="line"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <div id="containerBg1"> <div class="padTop15"> <!-- --> </div> <div class="clr"> <!-- --> </div> <div id="titleText">REGISTER EMPLOYEE</div> <div class="clr"> <!-- --> </div> <div class="padTop15"> <!-- --> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- top finish --> <!-- data title start --> <div id="containerBg2"> <div class="padTop2"> <!-- --> </div> <div class="clr"> <!-- --> </div> <form name="form" method="post" action="adminreg.php"> <table align="center" width="546"> <tr valign="baseline"> <td nowrap align="right" width="95">Name:</td> <td nowrap align="right"> <input name="name" type="text" size="32" style="font-size: 8pt; $style_name; float:left" value="<?php echo $name; ?>"></td> <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_name; ?></font></td> </tr> <tr valign="baseline"> <td nowrap align="right" width="95">Address:</td> <td nowrap align="right"> <input name="address" type="text" size="32" style="font-size: 8pt; $style_address; float:left" value="<?php echo $address; ?>"></td> <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_address; ?></font></td> </tr> <tr valign="baseline"> <td nowrap align="right" width="95">Address1:</td> <td nowrap align="right"> <input name="address1" type="text" size="32" style="font-size: 8pt; $style_address1; float:left" value="<?php echo $address1; ?>"></td> <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_address1; ?></font></td> </tr> <tr valign="baseline"> <td nowrap align="right" width="95">Address2:</td> <td nowrap align="right"> <input name="address2" type="text" size="32" style="font-size: 8pt; $style_address2; float:left" value="<?php echo $address2 ;?>"></td> <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_address2; ?></font></td> </tr> <tr valign="baseline"> <td nowrap align="right" width="95">Address3:</td> <td nowrap align="right"> <input name="address3" type="text" size="32" style="font-size: 8pt; $style_address3; float:left" value="<?php echo $address3; ?>"></td> <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_address3; ?></font></td> </tr> <tr valign="baseline"> <td nowrap align="right" width="95">Address4:</td> <td nowrap align="right"> <input name="address4" type="text" size="32" style="font-size: 8pt; $style_address4; float:left" value="<?php $address4; ?>"></td> <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_address4;?></font></td> </tr> <tr valign="baseline"> <td nowrap align="right" width="95">County:</td> <td nowrap align="right"> <input name="county" size="32" style="font-size: 8pt; $style_county; float:left" value="<?php echo $county; ?>"></td> <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_county ?></font></td> </tr> <tr valign="baseline"> <td nowrap align="right" width="95">Zip:</td> <td nowrap align="right"> <input name="zip" size="32" style="font-size: 8pt; $style_zip; float:left" value="<?php echo $zip; ?>"></td> <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_zip;?></font></td> </tr> <tr valign="baseline"> <td nowrap align="right" width="95">Telephone:</td> <td nowrap align="right"> <input name="telephone" size="32" style="font-size: 8pt; $style_telephone; float:left" value="<?php $telephone; ?>"></td> <td width="269"><font color="#FF0000" style="font-size: 8pt"><? echo $error_telephone; ?></font></td> </tr> <tr valign="baseline"> <td nowrap align="right" width="95">Email:</td> <td nowrap align="right"> <input name="email" size="32" style="font-size: 8pt; $style_email; float:left" value="<?php $email;?>"></td> <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_email;?></font></td> </tr> <tr valign="baseline"> <td nowrap align="right" width="95">Username:</td> <td nowrap align="right"> <input name="username" size="32" style="font-size: 8pt; $style_username; float:left"></td> <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_username; ?></font></td> </tr> <tr valign="baseline"> <td nowrap align="right" width="95">Password:</td> <td nowrap align="right"> <input name="password" size="32" style="font-size: 8pt; $style_password; float:left"type="password"></td> <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_password; ?></font></td> </tr> <tr valign="baseline"> <td nowrap align="right" width="95"> </td> <td nowrap align="right"> <input type=hidden name=action value="signup"> <input type="submit" value="Insert record" style="float: left"> </td> <td width="269"> </td> </tr> </table> </form> </div> <!-- btm start --> <div id="containerBg1"> <div class="padTop15"><!-- --></div> <div class="clr"><!-- --></div> </div> <div class="clr"><!-- --></div> <div id="container"> <div id="line"><!-- --></div> </div> <!-- btm finish --> </div> </div> </body> </html>
-
After validation name doesnt post to database???
mikebyrne replied to mikebyrne's topic in PHP Coding Help
I've changed it to $test = $row['name']; and that seems to have done the trick -
After validation name doesnt post to database???
mikebyrne replied to mikebyrne's topic in PHP Coding Help
Yeah I see what you mean $name = $row['name']; is used as part of this validation $user = mysql_real_escape_string(htmlspecialchars($_POST['username'])); $sql = "SELECT name FROM adminusers WHERE username ='$user'"; echo ".$user."; $result = mysql_query($sql) or die("Error in SQL: ".mysql_error()); $row = mysql_fetch_array($result); $count = mysql_num_rows($result); $name = $row['name']; if ($count > 0) { // username should only exist once. $valid=0; $style_username = "background-color:#FF5959"; $error_username = "Error! The username " . $user . " already exists in the database."; } Would you recommend I change the varible names? If so, how would you word it? -
After validation name doesnt post to database???
mikebyrne replied to mikebyrne's topic in PHP Coding Help
INSERT INTO adminusers(name, address, address1, address2, address3, address4, county, zip, telephone, email, username, password, usertype)VALUES('', 'kjsfksjdisjdsklj', 'aixasixuxiau', 'iduwiuewieu','iudisudisuci', 'isucdiuvdifuiof','idudiufdifueiof' ,'ocdicodicsodisoi', '92839483984390', 'oskfodjfoefkodvop', 'bisgosowo', 'okcodfodfosi' , 2) seems to be leaving name out -
After validation name doesnt post to database???
mikebyrne replied to mikebyrne's topic in PHP Coding Help
if ($valid==1) { $sql="INSERT INTO $tbl_name(name, address, address1, address2, address3, address4, county, zip, telephone, email, username, password, usertype)VALUES('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password' , 2)"; echo $result; $result=mysql_query($sql)or die(mysql_error()."<p>With Query<br>$sql"); } The echo seems to be Resource id #4 -
Once my code runs through the validation process ok and posts all the data to the database apart from the name field. I cant figure out why though?? My code is <?php require_once("adminconnect.php"); $tbl_name="adminusers"; $name = $_POST['name']; $address = $_POST['address']; $address1 = $_POST['address1']; $address2 = $_POST['address2']; $address3 = $_POST['address3']; $address4 = $_POST['address4']; $county = $_POST['county']; $zip = $_POST['zip']; $telephone = $_POST['telephone']; $email = $_POST['email']; $password =$_POST['password']; $username = $_POST['username']; $num =$_POST ['num']; if($_POST["action"] == "signup"){ $valid=1; if ($_POST['name']=="") { echo 'got no name<br>'; $valid=0; $style_name = "background-color:#FF5959"; $error_name = "Your name seems to be mising?<br>"; } if ($address == "" || strlen($address) < 2) { echo 'got no address1<br>';//added by me to denote failure in this statement $valid=0; $style_address = "background-color:#FF5959"; $error_address = "There is a problem with the address field?<br>"; } if ($address1 == "" || strlen($address1) < 2) { echo 'got no address1<br>';//added by me to denote failure in this statement $valid=0; $style_address = "background-color:#FF5959"; $error_address1 = "There is a problem with the address field?<br>"; } if ($address2 == "" || strlen($address2) < 2) { echo 'got no address2<br>';//added by me to denote failure in this statement $valid=0; $style_address = "background-color:#FF5959"; $error_address2 = "There is a problem with the address field?<br>"; } if ($address3 == "" || strlen($address3) < 2) { echo 'got no address3<br>';//added by me to denote failure in this statement $valid=0; $style_address = "background-color:#FF5959"; $error_address3 = "There is a problem with the address field?<br>"; } if ($address4 == "" || strlen($address4) < 2) { echo 'got no address4<br>';//added by me to denote failure in this statement $valid=0; $style_address = "background-color:#FF5959"; $error_address4 = "There is a problem with the address field?<br>"; } if ($county == "" || strlen($county)<2) { echo 'got no county<br>'; $valid=0; $style_county = "background-color:#FF5959"; $error_county = "The County field is blank?<br>"; } if ($zip == "" || strlen($zip)<2) { echo 'got no zip<br>'; $valid=0; $style_zip = "background-color:#FF5959"; $error_zip = "Theres a problem with the zip code?<br>"; } if (!eregi("^[0-9]+",$telephone)) { echo 'got no phone<br>'; $valid=0; $style_telephone = "background-color:#FF5959"; $error_telephone = "Theres a problem with the telephone number?<br>"; } if (!eregi("^[A-Za-z0-9.-]+",$email)) { echo 'got no mail'; $valid=0; $style_email = "background-color:#FF5959"; $error_email = "Theres a problem with the email address?<br>"; } if ($password == "" || strlen($password)<7) { echo 'got no password'; $valid=0; $style_password = "background-color:#FF5959"; $error_password = "Theres a problems with your password?<br>"; } $user = mysql_real_escape_string(htmlspecialchars($_POST['username'])); $sql = "SELECT name FROM adminusers WHERE username ='$user'"; echo ".$user."; $result = mysql_query($sql) or die("Error in SQL: ".mysql_error()); $row = mysql_fetch_array($result); $count = mysql_num_rows($result); $name = $row['name']; if ($count > 0) { // username should only exist once. $valid=0; $style_username = "background-color:#FF5959"; $error_username = "Error! The username " . $user . " already exists in the database."; } if ($password == "" || strlen($password)<7) { $valid=0; $style_password = "background-color:#FF5959"; $error_password = "Theres a problems with your password?<br>"; } if ($valid==1) { $sql="INSERT INTO $tbl_name(name, address, address1, address2, address3, address4, county, zip, telephone, email, username, password, usertype)VALUES('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password' , 2)"; $result=mysql_query($sql)or die(mysql_error()."<p>With Query<br>$sql"); } ?> The sql for the database is CREATE TABLE `adminusers` ( `name` varchar(255) collate latin1_general_ci default NULL, `address` varchar(255) collate latin1_general_ci default NULL, `address1` varchar(255) collate latin1_general_ci default NULL, `address2` varchar(255) collate latin1_general_ci default NULL, `address3` varchar(255) collate latin1_general_ci default NULL, `address4` varchar(255) collate latin1_general_ci default NULL, `county` varchar(255) collate latin1_general_ci default NULL, `zip` varchar(255) collate latin1_general_ci default NULL, `telephone` decimal(10,0) default NULL, `email` varchar(255) collate latin1_general_ci default NULL, `username` varchar(255) collate latin1_general_ci default NULL, `password` varchar(255) collate latin1_general_ci default NULL, `usertype` decimal(10,0) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
-
At present my valdation page looks like this <?php require_once("adminconnect.php"); $name = $_POST['name']; $address = $_POST['address']; $address1 = $_POST['address1']; $address2 = $_POST['address2']; $address3 = $_POST['address3']; $address4 = $_POST['address4']; $county = $_POST['county']; $zip = $_POST['zip']; $telephone = $_POST['telephone']; $email = $_POST['email']; $password =$_POST['password']; $username = $_POST['username']; $num =$_POST ['num']; if($_POST["action"] == "signup"){ $valid=1; if ($_POST['name']=="") { echo 'got no name<br>'; $valid=0; $style_name = "background-color:#FF5959"; $error_name = "Your name seems to be mising?<br>"; } if ($address == "" || strlen($address) < 2) { echo 'got no address1<br>';//added by me to denote failure in this statement $valid=0; $style_address = "background-color:#FF5959"; $error_address = "There is a problem with the address field?<br>"; } if ($address1 == "" || strlen($address1) < 2) { echo 'got no address1<br>';//added by me to denote failure in this statement $valid=0; $style_address = "background-color:#FF5959"; $error_address1 = "There is a problem with the address field?<br>"; } if ($address2 == "" || strlen($address2) < 2) { echo 'got no address2<br>';//added by me to denote failure in this statement $valid=0; $style_address = "background-color:#FF5959"; $error_address2 = "There is a problem with the address field?<br>"; } if ($address3 == "" || strlen($address3) < 2) { echo 'got no address3<br>';//added by me to denote failure in this statement $valid=0; $style_address = "background-color:#FF5959"; $error_address3 = "There is a problem with the address field?<br>"; } if ($address4 == "" || strlen($address4) < 2) { echo 'got no address4<br>';//added by me to denote failure in this statement $valid=0; $style_address = "background-color:#FF5959"; $error_address4 = "There is a problem with the address field?<br>"; } if ($county == "" || strlen($county)<2) { echo 'got no county<br>'; $valid=0; $style_county = "background-color:#FF5959"; $error_county = "The County field is blank?<br>"; } if ($zip == "" || strlen($zip)<2) { echo 'got no zip<br>'; $valid=0; $style_zip = "background-color:#FF5959"; $error_zip = "Theres a problem with the zip code?<br>"; } if (!eregi("^[0-9]+",$telephone)) { echo 'got no phone<br>'; $valid=0; $style_telephone = "background-color:#FF5959"; $error_telephone = "Theres a problem with the telephone number?<br>"; } if (!eregi("^[A-Za-z0-9.-]+",$email)) { echo 'got no mail'; $valid=0; $style_email = "background-color:#FF5959"; $error_email = "Theres a problem with the email address?<br>"; } if ($password == "" || strlen($password)<7) { echo 'got no password'; $valid=0; $style_password = "background-color:#FF5959"; $error_password = "Theres a problems with your password?<br>"; } $user = mysql_real_escape_string(htmlspecialchars($_POST['username'])); $sql = "SELECT name FROM adminusers WHERE username ='$user'"; echo ".$user."; $result = mysql_query($sql) or die("Error in SQL: ".mysql_error()); $row = mysql_fetch_array($result); $count = mysql_num_rows($result); $name = $row['name']; if ($count > 0) { // username should only exist once. echo "Error! The username " . $name . " already exists in the database."; } else { echo "Success! The username " .$user . " does not already exist in the database."; } } ?> Im not sure how I can incorprate yours within the code. Im trying to keep this a neat as possible
-
THAT SEEMS TO HAVE FIXED IT!! Now how can I tidy it up to include the validation for leaving the field blank? something along the lines of: if ($user == "" ||($count > 0) { echo 'got no password'; $valid=0; $style_password = "background-color:#FF5959"; $error_password = "Theres a problems with your password?<br>";
-
No this still doesnt fix the problem. Im running out of ideas now :'( $user = mysql_real_escape_string(htmlspecialchars($_POST['name'])); $sql = "SELECT name FROM adminusers WHERE username ='$user'"; echo ".$user."; $result = mysql_query($sql) or die("Error in SQL: ".mysql_error()); $row = mysql_fetch_array($result); $count = mysql_num_rows($result); $name = $row['name']; if ($count > 0) { // username should only exist once. echo "Error! The username " . $name . " already exists in the database."; } else { echo "Success! The username " .$user . " does not already exist in the database."; } $user has to be the problem??
-
<?php $user = mysql_real_escape_string(htmlspecialchars($_POST['name'])); $sql = "SELECT name FROM adminusers WHERE name ='$user'"; $result = mysql_query($sql) or die("Error in SQL: ".mysql_error()); $row = mysql_fetch_array($result); $count = mysql_num_rows($result); $name = $row['name']; if ($count > 0) { // username should only exist once. echo "Error! The username " . $name . " already exists in the database."; } else { echo "Success! The username " .$user . " does not already exist in the database."; } } ?> I leave every field blank but the username where I type in xxx but i stiil get the echo Success! The username does not already exist in the database. The SQL of the database is: CREATE TABLE `adminusers` ( `name` varchar(255) collate latin1_general_ci default NULL, `address` varchar(255) collate latin1_general_ci default NULL, `address1` varchar(255) collate latin1_general_ci default NULL, `address2` varchar(255) collate latin1_general_ci default NULL, `address3` varchar(255) collate latin1_general_ci default NULL, `address4` varchar(255) collate latin1_general_ci default NULL, `county` varchar(255) collate latin1_general_ci default NULL, `zip` varchar(255) collate latin1_general_ci default NULL, `telephone` decimal(10,0) default NULL, `email` varchar(255) collate latin1_general_ci default NULL, `username` varchar(255) collate latin1_general_ci default NULL, `password` varchar(255) collate latin1_general_ci default NULL, `usertype` decimal(10,0) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; -- ---------------------------- -- Records -- ---------------------------- INSERT INTO `adminusers` VALUES ('Test', 'yyy', 'yfgfg', 'tftrtrt', 'dtddtdtd', 'tdtdtdtd', 'tdtduhlllkk', 'oooioi', '787875675', 'hjhjhkhjkhjkh', 'xxx', '7676767678', null); As you can see I only have 1 record and the username IS xxx Cant figure it out!! the form section that applies is: <tr valign="baseline"> <td nowrap align="right" width="95">Username:</td> <td nowrap align="right"> <input name="username" size="32" style="font-size: 8pt; $style_username; float:left"></td> <td width="269"><font color="#FF0000" style="font-size: 8pt"><?php echo $error_username; ?></font></td> </tr>
-
Cant figure out why I cant get the if ($count == 1) statement to work???
-
Sorry i left it out Still haing the problem with the username that exists not giving the error Im getting the echo The username does not already exist in the database.