PHP - Passing Database Value Without A Form
I'm trying to make a quiz powered by PHP and jQuery, with all the data (questions, answers, ID's, etc.) stored in a database.
Similar TutorialsI have created a PHP form which includes validation, however.. everytime the validation passes, php redirects the form to another page where mysql code is to insert the variables... for some reason the variables are not being sent at all. Any suggestions. page 1 <?php error_reporting(E_ALL); ini_set('display_errors', 1); ?> <?php function VerifyForm(&$values, &$errors) { // Do all necessary form verification // Validate Model Number if (strlen($values['model']) < 4) { $errors['model'] = 'Model Number too short'; } elseif( strlen($values['model']) > 20) { $errors['model'] = 'Model Number too long';} // Validate Price if (is_numeric($values['price']) == 0){ $errors['price'] = 'No Price has been entered';} // Validate Product if(($values['product']) == 0){ $errors['product'] = 'No Product has been selected';} // Validate Image $imageinfo = getimagesize($_FILES['photo']['tmp_name']); if($imageinfo['mime'] != 'image/gif' && $imageinfo['mime'] != 'image/jpeg' && isset($imageinfo)){ $errors['photo'] = 'Image format must be either JPEG or GIF';} // Validate Description if (strlen($values['description']) == 0){ $errors['description'] = 'Description is too short';} return (count($errors) == 0); } function DisplayForm($values, $errors) { ?> <!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=UTF-8" /> <title>Test Area</title> <link rel="stylesheet" href="test.css" type="text/css" media="screen" /> </head> <body> <div id="container"> <h1>Add a Product</h1> <form method="post" id="customForm" action="" enctype="multipart/form-data"> <table> <tr> <td>Model Number:</td> <td><input id="model" type="text" size="30" name="model" value="<?php echo htmlentities($values['model']); ?>"/></td> <td class="error"><p style="color:#FF0000"><?php echo isset($errors['model']) ? $errors['model'] : ''; ?></p></td> </tr> <tr> <td>Choose a Product:</td> <td> <select class="product" name="product"> <option value="0">Please select an option below</option> <option value="19lcdtv">19" LCD TV</option> <option value="22lcdtv">22" LCD TV</option> <option value="26lcdtv">26" LCD TV</option> <option value="32lcdtv">32" LCD TV</option> <option value="37lcdtv">37" LCD TV</option> <option value="37plasmatv">37" Plasma TV</option> <option value="3D">3D Technology</option> <option value="42lcdtv">42" LCD TV</option> <option value="42plasmatv">42" Plasma TV</option> <option value="46plasmatv">46" Plasma TV</option> <option value="50plasmatv">50" Plasma TV</option> <option value="54plasmatv">54" Plasma TV</option> <option value="58plasmatv">58" Plasma TV</option> <option value="65plasmatv">65" Plasma TV</option> <option value="bluraydiscs">Bluray Discs</option> <option value="blurayhomecinema">Bluray Home Cinema System</option> <option value="blurayplayer">Bluray Player</option> <option value="blurayportable">Bluray Portable</option> <option value="blurayrecorder">Bluray Recorder</option> <option value="breadmaker">Breadmakers</option> <option value="cdradio">CD, Radio and Cassette Players</option> <option value="convectorheater">Convector Heaters</option> <option value="cylindercleaner">Cylinder Cleaner</option> <option value="answerphone">DECT Answer Phone</option> <option value="phone">DECT Phone</option> <option value="fire">Dimplex Fires</option> <option value="dishwasher">Dishwashers</option> <option value="dvddiscs">DVD Discs</option> <option value="dvdplayer">DVD Player</option> <option value="dvdportable">DVD Portable</option> <option value="dvdrecorder">DVD Recorder</option> <option value="epilator">Epilators</option> <option value="fanheater">Fan Heaters</option> <option value="freezers">Freezers</option> <option value="fridgefreezer">Fridge-Freezers</option> <option value="hdcamcorder">HD Camcorders</option> <option value="hddcamcorder">HDD Camcorders</option> <option value="homecinema">Home Cinema System</option> <option value="iron">Irons</option> <option value="kettle">Kettles</option> <option value="beauty">Ladies Shavers/Beauty</option> <option value="leads">Leads</option> <option value="shaver">Mens Shavers/Grooming</option> <option value="microsystem">Microsystems</option> <option value="microwavegrill">Microwave (Grill)</option> <option value="microwavesolo">Microwave (Solo)</option> <option value="microwavecombi">Microwave Combination</option> <option value="dvtapes">Mini DV Tapes</option> <option value="minisystems">Minisystems</option> <option value="pvr">Personal Video Recorder (PVR)</option> <option value="projector">Projector</option> <option value="pure">Pure Radios</option> <option value="fridges">Refridgerators</option> <option value="sdcamcorder">SD Camcorders</option> <option value="sdcards">SD/SDHC/SDXC Cards</option> <option value="straighteners">Straighteners</option> <option value="stylishcamera">Stylish Cameras</option> <option value="superzoomcamera">Super Zoom Cameras</option> <option value="toaster">Toasters</option> <option value="tumbledryer">Tumble Dryers</option> <option value="uprightcleaner">Upright Cleaner</option> <option value="brackets">Wall Bracket</option> <option value="washingmachine">Washing Machine</option> </select> </td> <td class="error"><p style="color:#FF0000"><?php echo isset($errors['product']) ? $errors['product'] : ''; ?></p></td> </tr> <tr> <td>Price:</td> <td><input id="price" type="text" size="30" name="price" value="<?php echo isset($values['price']) ? $values['price'] : htmlentities($values['price']) ; '';?>"/></td> <td class="error"><p style="color:#FF0000"><?php echo isset($errors['price']) ? $errors['price'] : ''; ?></p></td> </tr> <tr> <td>Please upload an Image:</td> <td><input id="photo" type="file" size="30" name="photo" value="<?php echo isset($values['photo']) ? htmlentities($values['photo']) : ''; ?>"/></td> <td class="error"><p style="color:#FF0000"><?php echo isset($errors['photo']) ? $errors['photo'] : ''; ?></p></td> </tr> <tr> <td valign="top">Description:</td> <td> <textarea id="description" name="description" cols="" rows=""><?php echo isset($values['description']) ? htmlentities($values['description']) : ''; ?></textarea> </td> <td class="error"><p style="color:#FF0000"><?php echo isset($errors['description']) ? $errors['description'] : ''; ?></p></td> </tr> <tr> <td><input id="submit" name="submit" type="submit" value="Submit" /></td> </tr> </table> </form> </div> </body> </html> <?php } function ProcessForm($values) { //INSERT VARIABLES FROM INSERT_ADD.PHP // Replace with actual page or redirect :P header ("Location: http://www.example.com"); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $formValues = $_POST; $formErrors = array(); if (!VerifyForm($formValues, $formErrors)) DisplayForm($formValues, $formErrors); else ProcessForm($formValues); } else DisplayForm(null, null); ?> This is the page which includes database details and insert commands <?php $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name=""; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); //This is the directory where images will be saved $target = "images/"; $target = $target . basename( $_FILES['photo']['name']); // Get values from form $model=$_POST['model']; $product=$_POST['product']; $description=$_POST['description']; $price=$_POST['price']; $photo=($_FILES['photo']['name']); // Insert data into mysql $sql="INSERT INTO $tbl_name(model, product, description, price, photo)VALUES('$model', '$product', '$description', '$price', '$photo')"; $result=mysql_query($sql); if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "<center>The file " . basename($_FILES['photo']['name']) . " has been uploaded, and your information has been added to the directory</center>"; } else { //Gives and error if its not echo "Sorry, There was a problem Uploading your Details."; } // close connection mysql_close(); ?> Hola, I'm trying to create a web form to insert info into my database using session variables. I'm at my wits end at this point. The reset button does its job but when you click submit it doesn't do anything. I'm using the template from the lynda.com essential php web form tutorials. Any help would be appreciated Here is the client-side header code I'm working with, <?php header("Expires: Thu, 17 May 2001 10:17:17 GMT"); // Date in the past header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header ("Pragma: no-cache"); // HTTP/1.0 session_start(); if (!isset($_SESSION['SESSION'])) require ( "include/session_init.php"); $arVal = array(); require_once("include/session_funcs1.php"); // make sure the seesion vars are initialized... reset ($arVal); while (list ($key, $val) = each ($arVal)) { if (!isset($_SESSION[$key])) $_SESSION[$key] = ""; } if ($_SESSION["eventgenre_sel"] == "") $_SESSION["eventgenre_sel"] = 0; // if the bFlg is true then some validation problems in the data. // namely a blank field or a submission without the feedback page. // just present a general error... $flg = ""; $error = ""; if (isset($HTTP_GET_VARS["flg"])) $flg = $HTTP_GET_VARS["flg"]; switch ($flg) { case "red": $error = "<br><font class=\"txt12_red\">Please fill out all the required fields.<br>Please Try Again.<BR></font>"; break; case "blue": $error = "<br><font class=\"txt12_red\">Your Session has Expired.<br>Please Try Again.</font><BR>"; break; case "pink": $error = "<br><font class=\"txt12_red\"><BR>The Special Code you entered is not valid.<br>Please Try Again or Leave that field blank.</font><BR>"; break; case "white": $error = "<br><font class=\"txt12_red\"><BR>The fields are too long for our Database.<br>Please correct your data via this form.</font><BR>"; break; default: $error = ""; } ?> <?php echo $_SERVER['SCRIPT_NAME']."<BR>"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="detect800.css"/> <link rel="stylesheet" type="text/css" href="detect1024.css"/> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="detect.js"></script> <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/base/ui.all.css" rel="stylesheet" type="text/css" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js" type="text/javascript"></script> <script src="jquery.ui.datetimepicker.js" type="text/javascript"></script> <script type="text/javascript"> $(function() { $('#eventdate').datetimepicker(); }); </script> <script src="imageflow.js" type="text/javascript"></script> <script src="highslide-full.js" type="text/javascript"></script> <script src="autosuggest.js" type="text/javascript"></script> <script type="text/javascript"> hs.graphicsDir = 'graphics/'; </script> <script language="javascript"> function SubmitForm() { var form = document.forms[0]; var bRequired = true; if((form.eventname.value.length < 1) || (form.eventvenue.value.length < 1) || (form.eventdate.value.length < 1) || (form.eventgenre.value.length < 1) || (form.eventprice.value.length < 1) || (form.eventpromoter.value.length < 1) || (form.eventflyer.value.length < 1)) { alert("Please fill out all the required fields."); bRequired = false; } if (!bRequired) return false; form.eventgenre_sel.value = form.state.selectedIndex; form.submit(); } function ResetForm() { var form = document.forms[0]; form.eventname.value = ""; form.eventvenue.value = ""; form.eventdate.value = ""; form.eventgenre.value = ""; form.eventprice.value = ""; form.eventpromoter.value = ""; form.eventflyer.value = ""; form.eventgenre_sel.value = ""; } </script> </head> This is the client side form code <form action="scripts/register.php" method="post" name="userevent" id="userevent"> <input name="eventgenre_sel" type="hidden" id="eventgenre_sel" value="<?php echo $_SESSION['eventgenre_sel'] ?>" /> <?php echo $error; ?> <fieldset> <label for="eventname" accesskey="n" ><span>Event Name</span> <input type="text" name="eventname" id="eventname" value="<?php echo $_SESSION['eventname_sel'] ?>" size="32" maxlength="30" /></label> <div id="autosuggest"><ul><li></li></ul></div> <label for="eventvenue" accesskey="v" ><span>Event Venue</span> <input type="text" name="eventvenue" id="eventvenue" size="32" value="<?php echo $_SESSION['eventvenue'] ?>" maxlength="30" /></label> <script type="text/javascript"> var venues = new Array("Republik", "HiFi Club", "Bamboo Tiki Room", "Tantra", "Jubilee Auditorium", "Ironwood Stage & Grill", "Broken City", "Soda", "Amsterdam Rhino", "Olympic Plaza", "Stampede Casino", "Habitat Living Sound", "Cantos Music Foundation", "Flames Central", "Prince's Island Park", "Beat Niq Jazz & Social Club", "Giuseppe's Italian Market", "BLVD", "Fourth on 4th", "Opus on 8th", "Local 510", "Local 522", "Raw Bar", "Jupiter Restaurant & Bar", "Vern's", "Lord Nelson's", "Kings Head Pub", "Blind Beggar Pub", "Viscous Circle", "Milk Tiger Lounge", "Pengrowth Saddledome", "Tubby Dog", "Marquee Room", "Distillery Public House", "Cafe Koi", "Mikey's Juke Joint & Eatery", "Palomino", "Atlantic Trap & Gill", "Drake Inn", "Radiopark Music Room", "Rusty Cage South", "Big Al's Good Times Bar", "Rose & Crown", "Tudor Rose Pub", "Elbow River Casino & Lounge", "Rusty Cage Central", "Rusty Cage South", "Rusty Cage North", "Olive Grove", "Shamrock Hotel", "Woody's Taphouse Southland", "Woody's Taphouse Country Hills", "Murrieta's West Coast Bar & Grill", "Stageline Saloon", "Pig & Pint", "Ranchman's", "Red Pepper Pub", "Stavro's Steak House & Lounge Ranchlands", "Stageline Saloon", "Whiskey"); new AutoSuggest(document.getElementById("eventvenue"),venues); </script> <label for="eventdate" accesskey="d" ><span>Event Date</span> <input type="text" name="eventdate" id="eventdate" value="<?php echo $_SESSION['eventdate'] ?>" size="32" maxlength="30" /></label> <label for="eventgenre" accesskey="g" ><span>Event Genre</span> <select name="eventgenre" id="eventgenre"> <option value="none">--select one--</option> <option value="HipHop">Hip-Hop</option> <option value="Funk">Funk</option> <option value="Soul">Soul</option> <option value="Metal">Metal</option> <option value="Punk">Punk</option> <option value="Blues">Blues</option> <option value="Jazz">Jazz</option> <option value="Trance">Trance</option> <option value="Breaks">Breaks</option> <option value="Electro">Electro</option> <option value="House">House</option> <option value="DNB">Drum'N'Bass</option> <option value="Dubstep">Dubstep</option> <option value="Lounge">Lounge</option> <option value="Top40">Top 40</option> </select> </label> <label for="eventprice" accesskey="p" ><span id="eventprice">Event Price</span> <input type="text" name="eventprice" id="eventprice" value="<?php echo $_SESSION['eventprice'] ?>" size="6" maxlength="4"/></label> <label for="eventpromoter" accesskey="c" ><span id="eventpromoter">Event Promoter</span> <input type="text" name="eventpromoter" id="eventpromoter" value="<?php echo $_SESSION['eventpromoter'] ?>" size="25" maxlength="23"/></label> <label for="eventflyer" accesskey="f" ><span id="eventflyer">Event Flyer (jpg or png MAX 300kb)</span> <input type="file" name="eventflyer" id="eventflyer" value="<?php echo $_SESSION['eventflyer'] ?>" size="25" maxlength="23"/></label> <input type="button" name="Reset" value="Reset" onclick="ResetForm();"> <input type="button" name="Submit" value="Submit" onsubmit="return validateForm(this);" onclick="SubmitForm(); return false; " > </fieldset> </form> <script language="javascript"> // set the selection box values... var form = document.forms[0]; form.eventgenre.selectedIndex = parseInt("<?php echo $_SESSION['eventgenre_sel'] ?>"); </script> And this is the server-side code. <?php $debug = FALSE; /************************************************************ Adjust the headers... ************************************************************/ header("Expires: Thu, 17 May 2001 10:17:17 GMT"); // Date in the past header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header ("Pragma: no-cache"); // HTTP/1.0 /***************************************************************************** Check the session details. we will store all the post variables in session variables this will make it easier to work with the verification routines *****************************************************************************/ session_start(); if (!isset($_SESSION['SESSION'])) require_once( "include/session_init.php" ); $arVal = array(); require_once("include/session_funcs1.php"); reset ($_POST); while (list ($key, $val) = each ($_POST)) { if ($val == "") $val = "NULL"; $arVals[$key] = (get_magic_quotes_gpc()) ? $val : addslashes($val); if ($val == "NULL") $_SESSION[$key] = NULL; else $_SESSION[$key] = $val; if ($debug) echo $key . " : " . $arVals[$key] . "<br>"; } /********************************************************************************************** Make sure session variables have been set and then check for required fields otherwise return to the registration form to fix the errors. **********************************************************************************************/ // check to see if these variables have been set... if ((!isset($_SESSION["eventname"])) || (!isset($_SESSION["eventvenue"])) || (!isset($_SESSION["eventdate"])) || (!isset($_SESSION["eventgenre"])) || (!isset($_SESSION["eventprice"])) || (!isset($_SESSION["eventpromoter"])) || (!isset($_SESSION["eventflyer"]))) { resendToForm("?flg=red"); } // form variables must have something in them... if ($_SESSION['eventname'] == "" || $_SESSION['eventvenue'] == "" || $_SESSION['eventdate'] == "" || $_SESSION['eventgenre'] == "" || $_SESSION['eventprice'] == "" || $_SESSION['eventpromoter'] == "" || $_SESSION['eventflyer'] == "") { resendToForm("?flg=red"); } // make sure fields are within the proper range... if (strlen($_SESSION['eventname']) > 35 || strlen($_SESSION['eventvenue']) > 35 || strlen($_SESSION['eventdate']) > 35 || strlen($_SESSION['eventgenre']) > 35 || strlen($_SESSION['eventprice']) > 35 || strlen($_SESSION['eventpromoter']) > 35 || strlen($_SESSION['eventflyer']) > 35 ) { resendToForm("?flg=white"); } /********************************************************************************************** Insert into the database... **********************************************************************************************/ $query = "INSERT INTO td_events (seventname, seventvenue, seventdate, seventgenre, seventprice, seventpromoter, seventflyer) " ."VALUES (".$arVals['eventname'].", ".$arVals['eventvenue'].", ".$arVals['eventdate'].", ".$arVals['eventgenre'] .", ".$arVals['eventprice'].", ".$arVals['eventpromoter'].", ".$arVals['eventflyer'].")"; //echo $query; $result = mysql_query($query) or die("Invalid query: " . mysql_error() . "<br><br>". $query); $insertid = mysql_insert_id(); /*** This following function will update session variables and resend to the form so the user can fix errors ***/ function resendToForm($flags) { reset ($_POST); // store variables in session... while (list ($key, $val) = each ($_POST)) { $_SESSION[$key] = $val; } // go back to the form... //echo $flags; header("Location: ./user_registration.php".$flags); exit; } ?> <p>SUCCESS!<br> The event was entered in the database!<br> You probably want to redirect to a thank you page or send an email to the user for confirmation.<br> <br> <br> Here are the variables...<br> <?php reset ($arVals); while (list ($key, $val) = each ($arVals)) { echo $key . " : " . $arVals[$key] . "<br>"; } echo "<br><br>The SQL Statment was:<br>"; echo $query."<br><br><br><br>"; ?> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <?php /********************************************************************************************** CREATES THUMBNAIL **********************************************************************************************/ //define a maxim size for the uploaded images define ("MAX_SIZE","1024"); // define the width and height for the thumbnail // note that theese dimmensions are considered the maximum dimmension and are not fixed, // because we have to keep the image ratio intact or it will be deformed define ("WIDTH","500"); define ("HEIGHT","650"); // this is the function that will create the thumbnail image from the uploaded image // the resize will be done considering the width and height defined, but without deforming the image function make_thumb($img_name,$filename,$new_w,$new_h) { //get image extension. $ext=getExtension($img_name); //creates the new image using the appropriate function from gd library if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext) || !strcmp("JPG",$ext)) $src_img=imagecreatefromjpeg($img_name); if(!strcmp("png",$ext) || !strcmp("PNG",$ext)) $src_img=imagecreatefrompng($img_name); //gets the dimmensions of the image $old_x=imageSX($src_img); $old_y=imageSY($src_img); // next we will calculate the new dimmensions for the thumbnail image // the next steps will be taken: // 1. calculate the ratio by dividing the old dimmensions with the new ones // 2. if the ratio for the width is higher, the width will remain the one define in WIDTH variable // and the height will be calculated so the image ratio will not change // 3. otherwise we will use the height ratio for the image // as a result, only one of the dimmensions will be from the fixed ones $ratio1=$old_x/$new_w; $ratio2=$old_y/$new_h; if($ratio1>$ratio2) { $thumb_w=$new_w; $thumb_h=$old_y/$ratio1; } else { $thumb_h=$new_h; $thumb_w=$old_x/$ratio2; } // we create a new image with the new dimmensions $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); // resize the big image to the new created one imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); // output the created image to the file. Now we will have the thumbnail into the file named by $filename if(!strcmp("png",$ext)) imagepng($dst_img,$filename); else imagejpeg($dst_img,$filename); //destroys source and destination images. imagedestroy($dst_img); imagedestroy($src_img); } // This function reads the extension of the file. // It is used to determine if the file is an image by checking the extension. function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } // This variable is used as a flag. The value is initialized with 0 (meaning no error found) // and it will be changed to 1 if an error occurs. If the error occurs the file will not be uploaded. $errors=0; // checks if the form has been submitted if(isset($_POST['Submit'])) { //reads the name of the file the user submitted for uploading $image=$_FILES['eventflyer']['name']; // if it is not empty if ($image) { // get the original name of the file from the clients machine $filename = stripslashes($_FILES['eventflyer']['name']); // get the extension of the file in a lower case format $extension = getExtension($filename); $extension = strtolower($extension); // if it is not a known extension, we will suppose it is an error, print an error message // and will not upload the file, otherwise we continue if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "JPG") && ($extension != "PNG") && ($extension != "png")) { echo '<h1>Unknown extension!</h1>'; $errors=1; } else { // get the size of the image in bytes // $_FILES[\'image\'][\'tmp_name\'] is the temporary filename of the file in which // the uploaded file was stored on the server $size=getimagesize($_FILES['eventflyer']['tmp_name']); $sizekb=filesize($_FILES['eventflyer']['tmp_name']); //compare the size with the maxim size we defined and print error if bigger if ($sizekb > MAX_SIZE*500) { echo '<h1>You have exceeded the size limit!</h1>'; $errors=1; } //we will give an unique name, for example the time in unix time format $image_name=$filename; //the new name will be containing the full path where will be stored (images folder) $newname="flyers/".$image_name; $copied = copy($_FILES['eventflyer']['tmp_name'], $newname); //we verify if the image has been uploaded, and print error instead if (!$copied) { echo '<h1>Copy unsuccessfull!</h1>'; $errors=1; } else { // the new thumbnail image will be placed in images/thumbs/ folder $thumb_name='flyers/thumb_'.$image_name; // call the function that will create the thumbnail. The function will get as parameters // the image name, the thumbnail name and the width and height desired for the thumbnail $thumb=make_thumb($newname,$thumb_name,WIDTH,HEIGHT); }} }} //If no errors registred, print the success message and show the thumbnail image created if(isset($_POST['Submit']) && !$errors) { echo "<h1>Thumbnail created Successfully!</h1>"; echo '<img src="'.$thumb_name.'">'; } ?> Hi there. I have this course registering website whereby i will need to : 1. pull out all course info and display (done that) 2. when user choose the course they are interested in using radio button and click submit , it will display you're registered and update the database to decrease the head count by 1. i m stuck on the radio button part... after i click submit nothing happens... Please advice... thanks a lot Code: [Select] <html> <head> <title>TimeTable</title> </head> <body> <h1> Here is the timetable</h1> <?php @ $db = new mysqli('localhost', 'root', '', 'mylifestyle'); if (mysqli_connect_errno()) { echo 'Error: Could not connect to database. Please try again later.'; exit; } $query = "SELECT course.CourseName , course.Instructor , course.ClassSize , courseschedule.Date ,courseschedule.Time , courseschedule.Location FROM course INNER JOIN courseschedule ON course.CourseID = courseschedule.CourseID"; $result = $db->query($query); $num_results = $result->num_rows; echo "<table border='1'> <tr> <th>Course Name</th> <th>Instructor</th> <th>Class size</th> <th>Date</th> <th>Time</th> <th>Location</th> <th>Register</th> </tr>"; ?> <?php for ($i=0; $i <$num_results; $i++) { $row = $result->fetch_assoc();?> <tr> <form action = "" method = "post"> <td><? echo $row['CourseName']; ?></td> <td><? echo $row['Instructor']; ?></td> <td><? echo $row['ClassSize']; ?></td> <td><? echo $row['Date']; ?></td> <td><? echo $row['Time']; ?></td> <td><? echo $row['Location']; ?></td> <td align="center"><input name="radio" type="radio" id="radio[]" value="<? echo $row['ClassSize']; ?>"></td> </tr> <?php } ?> <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="submit" type="submit" id="submit" value="submit"></td> <?php if($submit){ for($i=0;$i<$num_results;$i++){ $del_id = $radio[$i]; $query = "UPDATE course SET ClassSize = ClassSize -1 Where id='$del_id'"; $result = mysql_query($query); } // if successful redirect to delete_multiple.php if($result){ echo "$CourseName was deleted from database - myliftstyle!!<br />"; // Compute the item costs and total cost } } ?> </div> </body> </html> [attachment deleted by admin] after cloasing connection of database i still got the values form database. Code: [Select] <?php session_start(); /* * To change this template, choose Tools | Templates * and open the template in the editor. */ require_once '../database/db_connecting.php'; $dbname="sahansevena";//set database name $con= setConnections();//make connections use implemented methode in db_connectiong.php mysql_select_db($dbname, $con); //update the time and date of the admin table $update_time="update admin set last_logged_date =CURDATE(), last_log_time=CURTIME() where username='$uname'limit 3,4"; //my admin table contain 5 colums they are id, username,password, last_logged_date, last_log_time $link= mysql_query($update_time); // mysql_select_db($dbname, $link); //$con=mysql_connect('localhost', 'root','ijts'); $result="select * from admin where username='a'"; $result=mysql_query($result); mysql_close($con); //here i just check after closing data baseconnection whether i do get reselts but i do, why? echo "after the cnnection was closed"; if(!$result){ echo "cont fetch data"; }else{ $row= mysql_fetch_array($result); echo "id".$row[0]."usrname".$row[1]."passwped".$row[2]."date".$row[3]."time".$row[4]; } // echo "<html>"; //echo "<table border='1' cellspacing='1' cellpadding='2' align='center'>"; // echo "<thead>"; // echo"<tr>"; // echo "<th>"; // echo ID; // echo"</th>"; // echo" <th>";echo Username; echo"</th>"; // echo"<th>";echo Password; echo"</th>"; // echo"<th>";echo Last_logged_date; echo "</th>"; // echo "<th>";echo Last_logged_time; echo "</th>"; // echo" </tr>"; // echo" </thead>"; // echo" <tbody>"; //while($row= mysql_fetch_array($result,MYSQL_BOTH)){ // echo "<tr>"; // echo "<td>"; // echo $row[0]; // echo "</td>"; // echo "<td>"; // echo $row[1]; // echo "</td>"; // echo "<td>"; // echo $row[2]; // echo "</td>"; // echo "<td>"; // echo $row[3]; // echo "</td>"; // echo "<td>"; // echo $row[4]; // echo "</td>"; // echo "</tr>"; // } // echo" </tbody>"; // echo "</table>"; // echo "</html>"; session_destroy(); session_commit(); echo "session and database are closed but i still get values from doatabase session is destroyed".$_SESSION['admin']; ?> session is destroyed but database connection is not closed. thanks Hi, im trying to pass the information of a specific data to be edited in another form which is edit_doc.php. However, when i click "Edit" it doesnt seem to work. Only edit_doc.php opens but the information the does not appear. Is ther any mistake in the codes? while ($rows = mysql_fetch_assoc($run)) { echo"<tr>"; echo "<td>". $rows['file_ref'] ."</td>"; echo "<td>". $rows['file_name'] ."</td>"; echo "<td>". $rows['owner'] ."</td>"; echo "<td>". $rows['url'] ."</td>"; echo "<td><a href=edit_doc.php?id=$rows>" . "Edit" . "</a></td>"; echo "<td><a href=delete.php?id=$rows>" . "Delete" . "</a></td>"; echo "</tr>"; } echo "</table>"; } Thankz Can anyone explain to me why this system isnt working? I have no clue why it shouldnt be. The pin number is passed from a form to this script, which then determines if a users pin is correct and if so, forwards them onto the relevant page. Otherwise, it returns them to the login. <?php session_start(); $pin=$_POST['pin']; if ($pin='7221') { $_SESSION['pin']='7221'; $_SESSION['name']='Keith D Whelpton'; header('Location: phonesystem.php'); } elseif ($pin='3585') { $_SESSION['pin']='3585'; $_SESSION['name']='Luke S Barnes'; header('Location: phonesystem.php'); } else { header('Location: phonelogin.php'); } ?> //i've been looking at this same code for two whole days now and ive changed it lots of times but it can only get worse //i can't pass the value of the variable $today which has a date datatype //this is the part where i get the value of $today <?php $query="SELECT DISTINCT today FROM arrastre order by today desc"; $result=mysql_query($query); while($row=mysql_fetch_object($result)){ $today=$row->today; echo "<option value=$today>$today</option>"; } ?> //here's is the part where i use $today to get $tcl //except for a major problem that when the while loop returns more than one $tcl, i get more than one button, but that's not the problem because that is how it's supposed to work. The problem is that when there are more than one buttons, only the last button would work, the only button that displays values <?php if(isset($_POST['godate'])){ $today=$_POST['today']; $query="SELECT DISTINCT tcl FROM arrastre WHERE today='$today' ORDER BY tcl ASC"; $result=mysql_query($query); while($row=mysql_fetch_array($result)){ $tcl=$row['tcl']; $today=$row['today']; ?> <input type="hidden" name="tcl" value="<?php echo $tcl;?>"> <input type=submit name="tcl" value="<?php echo $tcl; ?>"> <?php } } ?> //thsi is another problem if(isset($_POST['tcl'])){ $tcl=$_POST['tcl']; $today=$_POST['today']; $query = "select * from arrastre where tcl=$tcl and today='$today' order by tcl asc"; $result = mysql_query($query); $totalcollections = 0; while($row=mysql_fetch_array($result)){ $orno=$row['orno']; $billnmbr=$row['billnmbr']; $payor=$row['payor']; $arrastre=$row['arrastre']; $wharfage=$row['wharfage']; $total=$row['total']; $today=$row['today']; //*i deleted the display part to make this shorter a little }} //the $today variable is empty in this post and i have no idea how to successfully pass this value so i could use it in my $query //thanks for your time I was using a api from google but whenever i pass it though a form via post, it gets me error. Invalid value ''.https://google.com.'/'. Values must match the following regular expression: '(?i)http(s)?://.*' [locationType] => parameter [location] => url ) ) [code] => 400 [message] => Invalid value ''.https://google.com.'/'. Values must match the following regular expression: '(?i)http(s)?://.*' ) )
<?php if(isset($_POST['url'])){ $url = $_POST['url']; ( I hid code rest code because of api But i get above error. ) $val = json_decode($result, true); //return $val; print_r($val); } ?> <form action="" method="post"> Url <input type="url" name="url"> </form>
What should be added to pass url variable correctly? I tried using w3school method but i still get the same error. Edited February 22, 2019 by cyberRobotextracted non-code from code block On one of my calculators : https://bizztools.net/2017/qccu/bizztools2015_budgetTest.php
When you press on the envelope in the middle you can send a form to yourself. I've added the code in the file that gets used to send the form to the person's email.
for ($i = 0; $i <= 79; $i++) { $item_Annual[$i] = number_format($_REQUEST['itemAnnualDisplay[$i]']); } Body: (each line of the form has a different value for $item_Annual) from 1 to 79 <TD bgcolor="#EEEEEE" align="left" valign="middle" height="1"><Font style="font-family:Arial; font-size: 12px;"><font color="#000000"> '.$currencySymbol.$item_Annual[1].' </TD>
for ($i = 0; $i <= 6; $i++) { $incomeSubtotal += $values[$i] * $periods[$i]; $itemAnnual[$i] = $values[$i] * $periods[$i]; $return['itemAnnualDisplay[$i]'] = $itemAnnual[$i]; } //New addtions are lines 3 and 4, the others were already there
Now, I've done some process of elimination and when testing to see if $periods[$i] and values[$i] would show up on the form, the values were zero for each. So each $itemAnnual[$i]is calculated to be $0. You can see from the form screenshot, the subtotals are calculating, but the individual items are not. Could this have anything to do with the form on the calculator page? It's in bootstrap.
Help please!!
<head> <script language="javascript" type="text/javascript" src="datetimepicker.js"> </script> </head> <form action="main.php?id=test.php" method="post"> <p>Start Date: <input name="start" id="start" type="text" size="10"> <a href="javascript:NewCal('start','ddmmyyyy')"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a> End Date: <input name="end" id="end" type="text" size="10"> <a href="javascript:NewCal('end','ddmmyyyy')"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a> <input name="submit" type="submit" value="Look Up"> </form> <?php if(isset($_POST['submit'])) { $start = $_POST['start']; $end = $_POST['end']; $sql = "SELECT * FROM `corps` WHERE `notedate` BETWEEN '$start' AND '$end'"; $results = mysql_query($sql) OR DIE(mysql_error()); $numrow = mysql_num_rows($results) ; $i = 0; While ($i < $numrow) $shownotes = mysql_result($results,$i,'notes'); echo $shownotes."<br>"; { Echo "Records found ".$i."<br>"; $i++; } } The $start, and $end don't seem to be getting any values Hello all, I'm new to php and I'm running into some trouble. I'm hoping someone will be able to help me. Here is the code I already have: <?php include "include/dbc.php"; include "include/header.inc"; ?> <style type="text/css"> .mydate{ color:#00F; text-decoration:underline; cursor:pointer; } </style> <script type="text/javascript"> function displayDate(d){ var date=new Date(); var D=date.getDate(); date.setDate(D+d); var YYYY=date.getFullYear(); var MM=date.getMonth()+1; MM<10?MM='0'+MM:null; var DD=date.getDate(); DD<10?DD='0'+DD:null; var span=document.getElementById('date'); span.innerHTML= 'Entries for '+MM+'/'+DD+'/'+YYYY; } onload=function(){displayDate(0)}; </script> <h1>Food Diary</h1> <div class="full"> <center><div><span class="mydate" onclick="displayDate(-1)"><img src="images/left_arrow.png" border="0">Yesterday</span> <span id="date" style="font-size:2em;"></span> <span class="mydate" onclick="displayDate(1)">Tomorrow<img src="images/right_arrow.png" border="0"></span></div><br /> <a href="#" onclick="displayDate(0);return false;">Today</a> </center> <div class="full"> <form name="exercise" id="exercise" method="GET" action=""> <center><table> <tr> <td><h3>Add an Activity</h3></td> </tr> <tr> <td><input name="NewSearchString" style="width: 100px" type="text"/> <input type="submit" value="Search" /> </td> </tr> <tr> <td> <select name="activity"> <option value="_">Activity Browse...</option> <option value="all">All Activities</option> <option value="biking">Biking</option> <option value="condition">Conditioning</option> <option value="dancing">Dancing</option> <option value="fish">Fishing & Hunting</option> <option value="Home">Home Activities</option> <option value="misc">Miscellaneous</option> <option value="music">Music Playing</option> <option value="occupation">Occupation</option> <option value="running">Running</option> <option value="sports">Sports</option> <option value="walking">Walking</option> <option value="water">Water Activities</option> <option value="winter">Winter Activities</option> </select> <input type="submit" value="Submit" /></td></tr></table></center></form> </td> </tr> </table> </center> <table width="100%"> <tr bgcolor="#66CC33"> <td><div>Activity</div></td> <td><div>Specific Activity</div></td> <td><div>Time (hh:mm)</div></td> <td><div>Distance</div></td> <td><div>Units</div></td> </tr> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td> </tr> <?php if(isset($_GET[activity])) { $category=$_GET[activity]; $result = mysql_query("SELECT * FROM exercise WHERE type='$category'"); ?> <form action="add_activity.php" method="post"> <?php while($row = mysql_fetch_array($result)) { echo '<tr><td><div>'.$row[Type].'</div></td>'; echo '<td><div>'.$row[Name].'<input type="hidden" name="exerciseid" value="'.$row[No].'"></div></td>'; echo '<td><div><input type="text" name="duration"></div></td>'; echo '<td><div><input type="text" name="distance"></div></td>'; echo '<td><div><select> <option value="mile">mile</option> <option value="Km">km</option> <option value="M">m</option> <option value="Yard">yrd</option> <option value="Feet">ft</option> </select></div></td></tr>'; } mysql_close(); ?> <tr><td colspan="6" align="center"><input type="submit" name="submit" value="Add Activities"></td></tr> </form> <?php } ?> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td> </tr></table> This code is supposed to pull info from a database and place it in a table. Once the user clicks the add activities button at the bottom, there values are supposed to be passed and displayed in the second page. Here's what I have for the second page: <?php include "include/dbc.php"; include "include/header.inc"; $activity = $_POST['activity']; $exercise = $_POST['exercise']; $duration = $_POST['duration']; $distance = $_POST['distance']; echo $exercise; echo $duration; echo $distance; ?> (Keep in mind that I am using this code to test the functionality of the page before I make it look nice) When I pass the values to the 2nd page, I get a black screen. Nothing is passing and I don't know why. Am I going about this the wrong way? Is there something I need to do to make the code better? Any suggestions are appreciated. Thanks in advance. I have managed to create an update script that allows a user to submit changes to their details but I need help to finish of the code. I'm using sessions to login in members, here is my update.php code. After while($member = mysql_fetch_array($result)) { I would like to retrieve the new values entered by them to be displayed back to the previous form which uses $_SESSION to hold their information when they previously login. Any suggestions or ideas, as I think it's to do with clearing the session but unfamiliar on how to proceed. <?php include("config.php"); mysql_connect("$dbhost","$dbuser","$dbpass") or die(mysql_error()); mysql_select_db("$dbname") or die(mysql_error()); $id= mysql_real_escape_string($_POST['member_id']); $fname= mysql_real_escape_string($_POST['firstname']); $lname= mysql_real_escape_string($_POST['lastname']); $address= mysql_real_escape_string($_POST['address']); $town= mysql_real_escape_string($_POST['address2']); $county= mysql_real_escape_string($_POST['county']); $postcode= mysql_real_escape_string($_POST['postcode']); $telephone= mysql_real_escape_string($_POST['telephone']); $mobile= mysql_real_escape_string($_POST['mobile']); $username= mysql_real_escape_string($_POST['login']); $email=mysql_real_escape_string($_POST['email']); $id= $_POST['member_id']; $sql="UPDATE members SET firstname='$fname', lastname='$lname', address='$address', address2='$town', county='$county', postcode='$postcode', telephone='$telephone', mobile='$mobile', login='$username', email='$email' WHERE member_id='$id' LIMIT 1"; $result=mysql_query($sql) or die ("Error: ". mysql_error(). " with query ". $sql); $query = "SELECT * FROM members WHERE member_id = '$id'"; $result = mysql_query($query) or die(mysql_error()); while($member = mysql_fetch_array($result)) { } ?> i am writing this script for use as an include in joomla and the directphp plugin so in my joomla article i have: Code: [Select] <?php include 'test/conducttest.php'; conducttest(); ?> Ok now my issue! the form in this function is passing only the values for the last item in the loop rather than for the selected radio item when submitted. so when say for example the radio selected is: ID TEST TYPE UNIQUE TEST ID AVAILABLE 5 Adolescent Clinical 50021629 1 and the last item in the list is: ID TEST TYPE UNIQUE TEST ID AVAILABLE 4 Adult Clinical 12341629 1 When the form is submitted even if the 1st item is selected, it returns the value for the second one. I am sorta new to php so any suggestions will be appreciated. Here is my full code: Code: [Select] <?php function conducttest() { //GET JOOMLA USER ID & USERNAME FOR LOGGED USER $user =& JFactory::getUser(); $userID = $user->id; //GET JOOMLA DATABASE OBJECTS $db =& JFactory::getDBO(); //NEW TESTS QUERY (what purchased test are available for use with 'item_available' == '1' {unused test} and matching current 'user_id') $new_query = " SELECT * FROM crt_transactionHistory WHERE user_id = ".$userID." AND item_available = '1' ORDER BY item_name, id "; $db->setQuery($new_query); $new = $db->loadAssocList(); //OPEN TESTS QUERY (what purchased test are available for use with 'item_available' == '2' {resume test} and matching current 'user_id') $resume_query = " SELECT * FROM crt_transactionHistory WHERE user_id = ".$userID." AND item_available = '2' ORDER BY item_name, id "; $db->setQuery($resume_query); $resume = $db->loadAssocList(); //DISPLAY use_test FORM if(!isset($_POST['test'])) { //SELECT FORM: WHICH TEST WOULD YOU LIKE TO USE? echo ' <fieldset> <table> <form method="post" action="'.$PHP_SELF.'">'; if (empty($new)) { echo ' <th colspan="3"align="left">NO NEW TESTS AVAILABLE</th>'; } else { echo ' <th colspan="3"align="left">NEW TESTS AVAILABLE</th> <tr> <td width="75px">SELECT</td> <td width="50px">ID</td> <td width="150px">TEST TYPE</td> <td width="150px">UNIQUE TEST ID</td> <tr>'; foreach ($new as $result1) { echo ' <tr> <td><input type="radio" value="' .$result1['id']. '" name="test_id"></td> <td>'.$result1['id'].'</td> <td><input type="hidden" value="'.$result1['item_name'].'" name="item_name">'.$result1['item_name'].'</td> <td><input type="hidden" value="'.$result1['item_number'].'" name="item_number">'.$result1['item_number'].'</td> <input type="hidden" value="'.$result1['item_available'].'" name="item_available"> <input type="hidden" value="'.$userID.'" name="userID"> <tr>'; } } echo ' </table> <hr /> <table>'; if (empty($resume)) { echo ' <th colspan="3"align="left">NO TESTS TO RESUME</th>'; } else { echo ' <th colspan="3"align="left">RESUME TEST</th> <tr> <td width="75px">SELECT</td> <td width="50px">ID</td> <td width="150px">TEST TYPE</td> <td width="150px">UNIQUE TEST ID</td> <tr>'; foreach ($resume as $result2) { echo ' <tr> <td><input type="radio" value="' .$result2['id']. '" name="test_id"></td> <td>'.$result2['id'].'</td> <td><input type="hidden" value="'.$result2['item_name'].'" name="item_name">'.$result2['item_name'].'</td> <td><input type="hidden" value="'.$result2['item_number'].'" name="item_number">'.$result2['item_number'].'</td> <input type="hidden" value="'.$result2['item_available'].'" name="item_available"> <input type="hidden" value="'.$userID.'" name="userID"> <tr>'; } } echo ' </table> </fieldset> <input type="submit" name="test" value="Conduct Test" /> </form> '; } //NOW A TEST HAS BEEN SELECTED FOR USE if(isset($_POST['test'])) { $test_id = $_POST['test_id']; $item_name = $_POST['item_name']; $item_number = $_POST['item_number']; $item_available = $_POST['item_available']; $userID = $_POST['userID']; echo $test_id.'<br />'; echo $item_name.'<br />'; echo $item_number.'<br />'; echo $item_available.'<br />'; echo $userID.'<br />'; //IF THIS IS A NEW TEST... if ($item_available == "1") { echo 'new test'; } //IF WE ARE RESUMING A TEST... elseif ($item_available == "2") { echo 'resume test'; } } } ?> I have a shopping system set up and all works fine until the page where I ask for the clients invoice details etc... I am using php to validate the form data. This works fine but then after it has validated and you submit the form the data does not get passed as I am using a http location redirect. I have heard people mention curl to pass the data, but have never used this before and dont know where to start. Is there an alternate way of doing this. The form data is passed to another website url of a site that processes our payments. Please can someone tell me the best method? I know I could validate with javascript, but want to stay away from that. Ok here is what im trying to do: 1. drop down list pulled from mysql database.( working ) 2. after you select the name in the drop down list 3. Use selected name to another page. here is code Code: [Select] <?php include('include/db_connection.inc'); $table = "truck_master"; $result = mysql_query( "SELECT driver_name FROM $table" ); $options=""; while ($row=mysql_fetch_array($result)) { $driver_name=$row["driver_name"]; $options.="<OPTION VALUE=\"driver_name\">".$driver_name.'</option>'; } ?> <html> <head> </head> <body> <table align="center"> <form name="form1" method="GET" align="center" action="issue.php"> <tr> <td>Driver Name :</td> <td><SELECT name="driver_name"><OPTION VALUE=''>Choose<?php echo $options?></SELECT> </td> </tr> <tr> <td><input type="submit" name="Submit" value="Submit"> </td> </tr> </form> </table> </body> <html> Second Code IS Code: [Select] $driver = $_GET['driver_name']; Hi guys, Is there an html code that allows you to array a form input? and once you passed the form, how do you extract the data then insert it to the database? Thanks I have a html for that posts to a form processing script which is fully functional atm, in the processing script i have if statements, if the condition is met it updates tables in database, if there not met i echo a "not met" statment. problem is my form processing script just goes straight back to the index.php page using the following code; header('Location: index.php'); here is the form processing script: <?php session_start(); header('Location: index.php'); include "connect.php"; $id = $_SESSION['id']; $user = $_SESSION['user']; $ticketNumber = $_POST[ticketNumber]; //echo $_POST[ticketNumber]; $today = date('Y-m-d H:i:s', time() - 3600); // Query "Ticket" Table to check if user has purchased a "regular" ticket within the last 24 hours $query24hour = mysql_query("SELECT * FROM tickets WHERE username = '$user' AND HOUR(TIMEDIFF(NOW() , purchaseDate)) < 24;") or die(mysql_error()); // Query "promoTickets" table to grab information of previous tickets bought to the "promotional" auction and LIMIT tickets to 1 per user for "promotional" auctions. $querySold = mysql_query("SELECT * FROM promoTickets WHERE promoID='$_POST[promoID]' AND (ticketNumber='$ticketNumber' OR username = '$user');") or die(mysql_error()); //echo $querySold; $sold = mysql_fetch_assoc($querySold); //print_r($sold); //echo $sold; //echo query24hour; $querycount24hour = mysql_num_rows($query24hour); //echo $querycount24hour; //check if ticket is sold and if user has purchased a "regular" ticket within 24 hours if(empty($sold)!=FALSE and $querycount24hour >= 1){ //Checks users balance to see if they have enough for the ticket $queryBal = mysql_query("SELECT user_iskbalance FROM users WHERE username = '$user';") or die(mysql_error()); //echo $querySold; //echo $user; //echo $queryBal; $balArray = mysql_fetch_assoc($queryBal); $bal = $balArray[user_iskbalance]; $newBal = $bal-$_POST[ticketPrice]; //check if he has the money to buy the ticket if($bal>=$_POST[ticketPrice]){ //remove the money $queryBalRemoveal = mysql_query("UPDATE `users` SET `user_iskbalance`='$newBal' WHERE `username`='$user';") or die(mysql_error()); //buy ticket & insert data into "promoTickets" table $query = mysql_query("INSERT INTO promoTickets(promoID, username, charID, ticketNumber, ticketPrice, purchaseDate) VALUES ('$_POST[promoID]', '$user', '$id', '$_POST[ticketNumber]', '$_POST[ticketPrice]', '$today');") or die(mysql_error()); } else{ die("Insufficent balance. Please add more ISK") ; } } else{ die("Ticket has already been Sold or you have already bought a ticket to this promotion..!"); } ?> any way i can get the errors to be passed onto the index.php (with the form) and echo them there? as it stands errors arnt shown to the users and its confusing people This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=355809.0 Hi everybody. So I tried to do some research on this and the answers I found were pretty complicated and hard for me (as a newbie) to understand. What I am trying to do is send the results of an HTML form (radio buttons) to more than one php script (currently name_BB1.php but I would also like to send it to name_2.php). Is there a simple way to do this? Is it even possible?
All I need to pass from the script is the name of the department chosen (Music Books or Video) and the first script uses that information to access related databases. However the second script also needs to know the name of the department originally chosen and I don't know how to get that variable over there without asking the user a second time.
HTML:
<form action="name_BB1.php" method="POST"> </p>Which database would you like to select?<br \><br \> <input type="radio" name="choice" value="Music" />I want music!<br \> <input type="radio" name="choice" value="Books" />Give me books!<br \> <input type="radio" name="choice" value="Video" />I want to see videos!<br \><br \> <input type="submit" value="submit"> </p> </form> Thanks! Can someone please tell me what I am doing wrong here? For some reason, the variable doess not seem to be getting passed to the "action" php script this input is in my html form (action=post)... <input type="hidden" name="httpreferer" value="<?php echo $_SERVER['HTTP_REFERER'] ?>" /> this is in the action script... $httpreferer=$_POST['httpreferer']; echo $httpreferer; |