s_ainley87 Posted February 28, 2008 Share Posted February 28, 2008 Hi there, i am currently trying and have been for a week to make by webpage recognise that a radio button is selected and so it can process the information however it is not :-( my code is below any advice would be great! <!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>Jetstore | Adminstration</title> </head> <body> <?php // This page allows the administrator to add a product. require_once ('include/mysql_connect.php'); // Connect to the database. require_once ('include/config.inc.php'); if (isset($_POST['submitted'])) { // Check if the form has been submitted. // Validate the product_name, image, category size, price, and description. // Check for a print name. if (!empty($_POST['product_name'])) { $pn = escape_data($_POST['product_name']); } else { $pn = FALSE; echo '<p><font color="red">Please enter the product\'s name!</font></p>'; } // Check for an image. if (is_uploaded_file ($_FILES['image']['tmp_name'])) { if (move_uploaded_file($_FILES['image']['tmp_name'], "uploads/{$_FILES['image']['name']}")) { // Move the file over. echo '<p>The file has been uploaded!</p>'; } else { // Couldn't move the file over. echo '<p><font color="red">The file could not be moved.</font></p>'; $i = FALSE; } $i = $_FILES['image']['name']; } else { $i = FALSE; } // Check for a price. if (is_numeric($_POST['price'])) { $p = (float) $_POST['price']; } else { $p = FALSE; echo '<p><font color="red">Please enter the product\'s price!</font></p>'; } // Check for a description if (!empty($_POST['description'])) { $d = escape_data($_POST['description']); } else { $d = '<i>No description available.</i>'; } // Validate the category. if ($_POST['category'] == 'new') { // If it's a new category, add the category to the database. $query = 'INSERT INTO category (category_name, category_desc) VALUES ('; if (!empty($_POST['category'])) { $query .= "'" . escape_data($_POST['category']) . "', "; } else { $query .= 'NULL, '; } // Check for a description. if (!empty($_POST['category_desc'])) { $query .= "'" . escape_data($_POST['category_desc']) . "')"; // Improved MySQL Version: $result = mysql_query($query,$dbc); $a = mysql_insert_id($dbc); //$result = mysql_query ($query or die (mysql_error)); // Run the query. //$a = mysql_insert_id(); // Get the category ID. } else { $a = FALSE; echo '<p><font color="red">Please enter the category\'s description!</font></p>'; } } elseif (($_POST['category'] == 'existing') && ($_POST['existing'] > 0)) { // Existing category. $a = (int) $_POST['existing']; } else { // No category selected. $a = FALSE; echo '<p><font color="red">Please enter or select the products\'s category!</font></p>'; } if ($pn && $p && $a && $i) { // If everything's OK. // Add the print to the database. $query = "INSERT INTO product (product_name, category_id, price, product_desc, image_name) VALUES ('$pn', '$a', $p,'$d', '$i')"; echo $query; if ($result = $query) { // Worked. echo $result; echo '<p>The product has been added.</p>'; } else { // If the query did not run OK. echo '<p><font color="red">Your submission could not be processed due to a system error.</font></p>'; } } else { // Failed a test. echo '<p><font color="red">Please click "back" and try again.</font></p>'; } } else { // Display the form. ?> <form enctype="multipart/form-data" action="admin.php" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="524288"> <fieldset><legend>Fill out the form to add a print to the catalog:</legend> <p><b>Product Name:</b> <input type="text" name="product_name" size="30" maxlength="60" /></p> <p><b>Image:</b> <input type="file" name="image" /> <small>The file name should not include spaces or other invalid characters and should have a file extension.</small></p> <p><b>Category:</b> <p><input name="category" type="radio" value="existing" /> Existing => <?php $query="SELECT category_id,category_name FROM category"; /* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */ $result = mysql_query ($query); echo "<select name=\"category\">Category Name</option>"; // printing the list box select command while($nt=mysql_fetch_array($result)){//Array or records stored in $nt echo "<option value=$nt[category_id]>$nt[category_name]</option>"; /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box ?> <p> <input type="radio" name="category" value="new" /> New => Category Name: <input type="text" name="category" size="25"/> <br /><br /> Category Description:<textarea name="category_desc" cols="40" rows="5"></textarea></p> <p>Price: <input type="text" name="price" size="10" maxlength="10" /> <small>Do not include the currency sign or commas.</small></p> <p>Product Description:<textarea name="description" cols="40" rows="5"></textarea></p ></fieldset> <div align="center"><input type="submit" name="submit" value="Submit" /></div> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php } // End of main conditional. ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/93583-radio-buttons-setting/ Share on other sites More sharing options...
jeremyphphaven Posted February 28, 2008 Share Posted February 28, 2008 You should just look for if(isset($_REQUEST['submit'])) Link to comment https://forums.phpfreaks.com/topic/93583-radio-buttons-setting/#findComment-479552 Share on other sites More sharing options...
s_ainley87 Posted February 28, 2008 Author Share Posted February 28, 2008 sorry i am a bit slow when it comes to PHP what would that do exactly? Link to comment https://forums.phpfreaks.com/topic/93583-radio-buttons-setting/#findComment-479556 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.