PHP - Multipage Form Using Mysql's Ai
I have tried this for about 2 solid hours and I cannot figure out how to make multiple forms that have the same ID.
Definition: I have 3 pages and they all have different information that needs to be placed into the database. I have no problem doing that the trouble comes when I try to make the 3 different database entry's have the same ID as the first form. My thought was to have the first form be completed then after the data was placed it would use mysql to pull the ID back out by using the WHERE clause to match the persons last name. Code: [Select] //Connection to the Mysql_Database $con = mysql_connect("####", "####", "####"); if(!$con){ die("There was an error connecting to your mysql_database" . mysql_error()); } //Variables to be entered into Patient_Data $last_name = $_POST['last_name']; //Intialize and Select the correct database. mysql_select_db("####"); //Format the data for entry into the mysql Database. $query = mysql_query("INSERT INTO Patient_Data VALUES ('', '$last_name)"); //Verify that the operation has worked if(!$query){ die("Lost in Transmission!" . mysql_error()); } $id_find = mysql_query("SELECT * FROM #### WHERE last_name='$last_name'"); while($id = mysql_fetch_row($id_find)){?> <!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>Untitled Document</title> </head> <body> <form name="MedicalHistory" action="https://evansvillesurgical.com/med-record.php?id=<?php echo $id['id'];}?>" enctype="application/x-www-form-urlencoded" method="post"> Any help would be greatly appreciated. Even if it's just describing in Pseduo code a better way to go about this. Thanks, Colton Wagner Similar TutorialsHey guys, I have checked in google and on this forum for answers to my question but haven't found anything regarding validating each step of a multipage form, hence my post! I wonder if anyone can help me, or rather provide me with advice.... I am trying to create a multipage form, which so far i have done a basic one which i have done using my php cookbook by O'Reilly which is a very basic version, without any validations or anything.... My multipage has 3 steps: Step1: user details - takes users name, email etc Step 2: House details - Takes users address, house type, no of rooms, descriptions of rooms etc Step 3: Image upload - Allows user to upload 3 images max to display (using my original file upload script) As i said, my basic multipage form works, storing all posted values into sessions which can then be outputted at the end in a review page, which will be at the end of the form. In previous forms i have created, i always have an html form, which when posted or submitted, has an action of a separate php script which processes the form and validates it, sends email, updates database etc, and all errors are then stored in sessions and appear back on the form page until there are no errors displayed and then a success page is shown.... so the code i have taken from my cookbook doesn't seem to be able to allow me to validate EACH STEP of the form? it can validate at the end, when the user reviews and then the form is processed all in one go. But i want to be able to validate form entries at each step, rather than in one go. For example if a user leaves their 'town' field empty, an error message will be displayed before going to the next step... If you see the code i have done so fare below: Code: [Select] <?php //Figure out what stage to use if (($_SERVER['REQUEST_METHOD'] == 'GET') || (! isset($_POST['stage']))) { $stage = 1; } else { $stage = (int) $_POST['stage']; } //Save any submitted data if ($stage > 1) { foreach ($_POST as $key => $value) { $_SESSION[$key] = $value; } } if ($stage ==1) {?> <div id="submitCustomerForm"> <FORM ACTION='<?php echo $_SERVER['SCRIPT_NAME'] ?>' method='post'> <h7>Your details</h7> <br /> <div id="inputfield"> <label class="textleft" for="forename">forename:</label> <input class="fade" name="forename" type=text size="30" align="right" maxlength="15" id="forename" value="<?php echo $_SESSION['forename']?>"> </div> <div id="inputfield"> <label class="textleft" for="surname">surname:</label> <input class="fade" name="surname" type=text size="30" maxlength="15" id="surname" align="right" value="<?php echo $_SESSION['surname']?>"> </div> <div id="inputfield"> <label class="textleft" for="email">email:</label> <input class="fade" name="email" type=text size="30" maxlength="30" align="right" id="email" value="<?php echo $_SESSION['email']?>"> </div> <br /> <h7>Your property Address</h7> <br /> <div id="inputfield"> <label class="textleft" for="address1">Address Line 1:</label> <input class="fade" name="address1" type=text size="30" maxlength="30" id="address1" value="<?php echo $_SESSION['address1'];?>" /> </div> <div id="inputfield"> <label class="textleft" for="address2">Address Line 2:</label> <input class="fade" name="address2" type=text size="30" maxlength="30" id="address2" value="<?php echo $_SESSION['address2'];?>" /> </div> <div id="inputfield"> <label class="textleft" for="town">Town/City:</label> <input class="fade" name="town" type=text size="30" maxlength="30" id="town" value="<?php echo $_SESSION['town'];?>" /> </div> <div id="inputfield"> <label class="textleft" for="county">County:</label> <input class="fade" name="county" type=text size="30" maxlength="30" id="county" value="<?php echo $_SESSION['county'];?>" /> </div> <div id="inputfield"> <label class="textleft" for="postcode">Post Code:<span class="asterix">*</span></label> <input class="fade" name="postcode" type=text size="30" maxlength="30" id="postcode" value="<?php echo $_SESSION['postcode'];?>" /> </div> <input type='hidden' name='stage' value='<?php echo $stage + 1 ?>'/> <input name="Next" class="submit" type="image" align ="right" src="Images/updateButton.png" /> </FORM> </div> <?php } else if ($stage == 2) { ?> <div id="submitCustomerForm"> <FORM ENCTYPE="multipart/form-data" action="<?php echo $_SERVER['SCRIPT_NAME']?>" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="1000000" /> <div id="divinputfile"> <input name="userfile" type="file" size="30" id="userfile" onchange="document.getElementById('fakeuserfile').value = this.value;"/> <div id="fakeinputfile"><input name="fakeuserfile" type="text" id="fakeuserfile" /></div> </div> <br /> <input type='hidden' name='stage' value='<?php echo $stage + 1 ?>'/> <input type="image" src="Images/upload.png" align="right" name="Send File" /> <br /> <br /> </FORM> </div> <?php } else if ($stage == 3) {?> <p class="largeblue"> hello there <?php echo $_SESSION['forename']; echo $_SESSION['surname'];?> <br /> the first line of your address is: <?php echo $_SESSION['address1'];?> <br /> the second line of your address is: <?php echo $_SESSION['address2'];?> </p> <?php } ?> For the 'form action' it uses Quote <?php echo $_SERVER['SCRIPT_NAME'] ?> meaning that the form reloads the page, upon which the stage number has changed and therefore loads next step. Where as normally, i have the path for my process script which would handle validation etc and then send them to a success screen or back to the form displaying errors. I propose a few ideas that i could do to get around this, which i just wanted to get a bit of insight on, as to which way of going about this is the right one!! My first idea would be to treat each step of the form as a separate form almost. Doing a form as i normally do, where the form is on one page, then the completed form is sent to a processing page, which processes the entries, sends user back to the form page with errors if there are any, or if it is all ok, increase the 'stage number' in a session and then use a header to go to next page(the next step of the form. at the top of each page is a check to whether the stage number is the same as the step number of the form. OR would i put all my validation in one page, with all the steps of the form as i have at the moment? OR is there a way to send each step of the form to a process script, which then sends the user back to the original form displaying errors if there are any or then moves them to the next step?? Just a little confused with which method to do this, i dont want to start working on it and find out i have done it completely the wrong way!! any help would be greatly received, thanks guys!! Craig Set up: * XAMPP 1.7.3 * Apache 2.2.14 (IPv6 enabled) + OpenSSL 0.9.8l * MySQL 5.1.41 + PBXT engine * PHP 5.3.1 * phpMyAdmin 3.2.4 * Perl 5.10.1 * FileZilla FTP Server 0.9.33 * Mercury Mail Transport System 4.72 I'm trying to set up a multipage registration script. It's tuff! I've set up some basic scripts to distribute variables into the correct tables from previous forms using a session. But I want the script to check the input from form one is valid before it moves on to form 2. Here are my scripts: form 1: <html> <head> <title>Register</title> <style type="text/css"> td { vertical-align: top; } </style> </head> <body> <form action="form2.php" method="post"> <table> <tr> <td><label for="name">Username:</label></td> <td><input type="text" name="name" id="name" size="20" maxlength="20" value=""/></td> </tr><tr> <td><label for="password">Password:</label></td> <td><input type="password" name="password" id="password" size="20" maxlength="20" value=""/></td> </tr><tr> <td><label for="first_name">First name:</label></td> <td><input type="text" name="first_name" id="first_name" size="20" maxlength="20" value=""/></td> </tr><tr> <td><label for="last_name">Last name:</label></td> <td><input type="text" name="last_name" id="last_name" size="20" maxlength="20" value=""/></td> </tr><tr> <td><label for="email">Email:</label></td> <td><input type="text" name="email" id="email" size="20" maxlength="50" value=""/></td> </tr><tr> <td><label for="address">Address:</label></td> <td><input type="text" name="address" id="address" size="20" maxlength="20" value=""/></td> </tr><tr> <td><label for="city">City/Town:</label></td> <td><input type="text" name="city" id="city" size="20" maxlength="20" value=""/></td> </tr><tr> <td><label for="county">County:</label></td> <td><input type="text" name="county" id="county" size="20" maxlength="20" value=""/></td> </tr><tr> <td><label for="post">Postcode:</label></td> <td><input type="text" name="post" id="post" size="20" maxlength="20" value=""/></td> </tr><tr> <td><label for="home">Home Number:</label></td> <td><input type="text" name="home" id="home" size="20" maxlength="20" value=""/></td> </tr><tr> <td><label for="mobile">Mobile:</label></td> <td><input type="text" name="mobile" id="mobile" size="20" maxlength="20" value=""/></td> </tr><tr> <td> </td> <td><input type="submit" name="submit" value="Sumbit"/></td> </tr> </table> </form> </body> </html> Form 2: <?php //let's start the session session_start(); //now, let's register our session variables session_register('name'); session_register('password'); session_register('first_name'); session_register('last_name'); session_register('email'); session_register('address'); session_register('city'); session_register('county'); session_register('post'); session_register('home'); session_register('mobile'); //finally, let's store our posted values in the session variables $_SESSION['name'] = $_POST['name']; $_SESSION['password'] = $_POST['password']; $_SESSION['first_name'] = $_POST['first_name']; $_SESSION['last_name'] = $_POST['last_name']; $_SESSION['email'] = $_POST['email']; $_SESSION['address'] = $_POST['address']; $_SESSION['city'] = $_POST['city']; $_SESSION['county'] = $_POST['county']; $_SESSION['post'] = $_POST['post']; $_SESSION['home'] = $_POST['home']; $_SESSION['mobile'] = $_POST['mobile']; ?> <html> <head> <title>Register</title> <style type="text/css"> td { vertical-align: top; } </style> </head> <body> <form action="form3.php" method="post"> <table> <tr> <td><label for="bio">Biography:</label></td> <td><input type="text" name="bio" id="bio" size="400" maxlength="500" value=""/></td> </tr><tr> <td> </td> <td><input type="submit" name="submit" value="Sumbit"/></td> </tr> </table> </form> </body> </html> I've also got form3.php and process_forms.php(that's where I mysql_real_escape_string and input the data) but that's probably not relevant. How would I get this to work? Are there any sites I should look at that you'd recommend? Any help appreciated. There are two pieces to this- The HTML Form and the resulting php. I can't seem to make the leap, from the code to having the form produce the php page so others can view it until the form is again submitted overwriting the php, thus generating new content. The environment I am working in is limited to IIs 5.1 and php 5.2.17 without mySQL or other DB I'm new to php, this isn't homework,or commercialization, it's for children. I am thinking perhaps fwrite / fread but can't get my head around it. Code snipets below. Any help, please use portions of this code in hopes I can understand it Thanks Code snipet from Output.php Code: [Select] <?php $t1image = $_POST["t1image"]; $t1title = $_POST["t1title"]; $t1info = $_POST["t1info"]; $t2image = $_POST["t2image"]; $t2title = $_POST["t2title"]; $t2info = $_POST["t2info"]; ?> ... <tbody> <tr><!--Headers--> <td style="vertical-align: top; text-align: center; background-color: rgb(204, 255, 255);">Animal</td> <td style="vertical-align: top; text-align: center; background-color: rgb(204, 255, 255);">Image thumb<br> </td> <td style="vertical-align: top; text-align: center; background-color: rgb(204, 255, 255);">Date<br> </td> <td style="vertical-align: top; text-align: center; background-color: rgb(204, 255, 255);">Information<br> </td> </tr> <tr> <td style="vertical-align: top; text-align: center;">Monkey </td> <td style="vertical-align: top; text-align: center;"><img src="<?php echo $t1image.'.gif'; ?>"><!--single image presented selected from radio buttons--> </td> <td style="vertical-align: top; text-align: center;"><?php echo date("m/d/Yh:i A"); ?><!--time stamp generated when submitted form populates all fields at once--> </td> <td style="vertical-align: top; text-align: center;"><a href="#monkey" rel="facebox"><?php echo $t1title ?></a><!--Link name provided by "Title 1", that links to hidden Div generated page with content from "Info1" field--> <div id="Monkey" style="display:none"> <?php echo $t1info; ?> </div> </td> </tr> <tr> <td style="vertical-align: top; text-align: center;">Cat<br> </td> <td style="vertical-align: top; text-align: center;"><img src="<?php echo $t2image.'.gif'?>"></td> <td style="vertical-align: top; text-align: center;"><?php echo date("m/d/Yh:i A"); ?></td> <td style="vertical-align: top; text-align: center;"><a href="#Cat" rel="facebox"><?php echo $t2title ?></a> <div id="Cat" style="display:none"> <?php echo $t2info; ?> </div> </td> </tr> <tr> This replicates several times down the page around 15-20 times ( t1### - t20###) Code Snipet from HTML Form Code: [Select] <form action="animals.php" method="post"> <div style="text-align: left;"><big style="font-family: Garamond; font-weight: bold; color: rgb(51, 51, 255);"><big><big><span>Monkey</span></big></big></big><br> <table style="text-align: left; width: 110px;" border="0" cellpadding="2" cellspacing="0"> <tbody><tr> <td style="vertical-align: top;">Image thumb<br> <input type="radio" name="t1image" value="No opinion" checked><img src="eh.gif" alt="Eh"> <input type="radio" name="t1image" value="Ok"><img src="ok.gif" alt="ok"> <input type="radio" name="t1image" value="Like"><img src="like.gif" alt="Like"> <input type="radio" name="t1image" value="Dont"><img src="dont.gif" alt="Don't Like"> <input type="radio" name="t1image" value="Hate"><img src="hate.gif" alt="Hate"> <input type="radio" name="t1image" value="Other"><img src="other.gif" alt="Other"> <br> Why Title:<input type="text" name="t1title" size="45" value="..."/></td> <td style="vertical-align: top;"> Explain:<br> <textarea name="t1info" cols=45 rows=3 value="..."></textarea> </td></tr></table> <br> <!--Next--> How do I get the Form data to save to the php page for others to view? Hi- the code below lets me upload a CSV file to my database if I have 1 field in my database and 1 column in my CSV. I need to add to my db "player_id" from the CVS file and "event_name" and "event_type" from the form... any ideas??? here's the code: Code: [Select] <?php $hoststring =""; $database = ""; $username = ""; $password = ""; $makeconnection = mysql_pconnect($hoststring, $username, $password); ?> <?php ob_start(); mysql_select_db($database, $makeconnection); $sql_get_players=" SELECT * FROM tabel ORDER BY player_id ASC"; // $get_players = mysql_query($sql_get_players, $makeconnection) or die(mysql_error()); $row_get_players = mysql_fetch_assoc($get_players); // $message = null; $allowed_extensions = array('csv'); $upload_path = '.'; //same directory if (!empty($_FILES['file'])) { if ($_FILES['file']['error'] == 0) { // check extension $file = explode(".", $_FILES['file']['name']); $extension = array_pop($file); if (in_array($extension, $allowed_extensions)) { if (move_uploaded_file($_FILES['file']['tmp_name'], $upload_path.'/'.$_FILES['file']['name'])) { if (($handle = fopen($upload_path.'/'.$_FILES['file']['name'], "r")) !== false) { $keys = array(); $out = array(); $insert = array(); $line = 1; while (($row = fgetcsv($handle, 0, ',', '"')) !== FALSE) { foreach($row as $key => $value) { if ($line === 1) { $keys[$key] = $value; } else { $out[$line][$key] = $value; } } $line++; } fclose($handle); if (!empty($keys) && !empty($out)) { $db = new PDO( 'mysql:host=host;dbname=db', 'user', 'pw'); $db->exec("SET CHARACTER SET utf8"); foreach($out as $key => $value) { $sql = "INSERT INTO `table` (`"; $sql .= implode("`player_id`", $keys); $sql .= "`) VALUES ("; $sql .= implode(", ", array_fill(0, count($keys), "?")); $sql .= ")"; $statement = $db->prepare($sql); $statement->execute($value); } $message = '<span>File has been uploaded successfully</span>'; } } } } else { $message = '<span>Only .csv file format is allowed</span>'; } } else { $message = '<span>There was a problem with your file</span>'; } } ob_flush();?> <!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>CSV File Upload</title> </head> <body> <form class="form" action="" method="post" enctype="multipart/form-data"> <h3>Select Your File</h3> <p><?php echo $message; ?></p> <input type="file" name="file" id="file" size="30" /> <br/> <label>Event Name:</label><input name="event_name" type="text" value="" /> <br/> <label>Event Type:</label><input name="event_type" type="text" value="" /> <br/> <input type="submit" id="btn" class="button" value="Submit" /> </form> <br/> <h3>Results:</h3> <?php do { ?> <p><?php echo $row_get_players['player_id'];?></p> <?php } while ($row_get_players = mysql_fetch_assoc($get_players)); ?> </body> </html> I have a form on our website that a user can fill out for custom product. I want the form data to be 1) stored into a mysql database AND after storing said data, 2) email the same data to our sales department. 1) The form data DOES get stored into mysql database (except for the first two fields, for some weird reason) 2) I added a "mail" section to the php file that stores the data into the database, but it is not working correctly. I have stripped the email portion down to sending just one of the fields in the "message" to make it easier for troubleshooting I have included here, both the form section of the html file, and the formdata.php file that processes the data for your analysis. I am relatively new to php so there are going to be some issues with security, but I can work on those after I get the store & email process to work correctly. Please review my code and see if anyone can be of assistance. I looked through the forums and couldn't find another issue that was the same as mine. If I just overlooked, please tell me the thread post #. Thanks THE FORM WHICH COLLECTS THE DATA ******************************* <form method=POST action=formdata.php> <table width="640" border=0 align="center"> <tr> <td align=right><b>First Name</b></td> <td><input type=text name=FName size=25></td> <td><div align="right"><b>Telephone</b></div></td> <td><input type=text name=Tel size=25></td> </tr> <tr> <td align=right><b>Last Name</b></td> <td><input type=text name=LName size=25></td> <td><div align="right"><b>Fax</b></div></td> <td><input type=text name=Fax size=25></td> </tr> <tr> <td align=right><b>Title</b></td> <td><input type=text name=Title size=25></td> <td><div align="right"><b>Email</b></div></td> <td><input type=text name=Email size=50></td> </tr> <tr> <td align=right><b>Company</b></td> <td><input type=text name=Comp size=25></td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>Address</b></td> <td><input type=text name=Addr size=25></td> <td><div align="right"><b>Estimated Annual Volume</b></div></td> <td><input type=text name=EAV size=25></td> </tr> <tr> <td align=right><b>City</b></td> <td><input type=text name=City size=25></td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>State/Province</b></td> <td><input type=text name=SProv size=25></td> <td><div align="right"><b>Application</b></div></td> <td><input type=text name=Appl size=25></td> </tr> <tr> <td align=right><b>Country</b></td> <td><input type=text name=Ctry size=25></td> <td><div align="right"><b>Type of System</b></div></td> <td><input type=text name=Syst size=25></td> </tr> <tr> <td align=right><b>Zip/Postal Code</b></td> <td><input type=text name=ZPC size=25></td> <td> </td> <td> </td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right> </td> <td><div align="right"><strong><font color="#FFFF00" face="Arial, Helvetica, sans-serif">COIL DESIGN</font></strong></div></td> <td><font color="#FFFF00" face="Arial, Helvetica, sans-serif"><strong>PARAMETERS</strong></font></td> <td> </td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>Primary Resistance (ohms)</b></td> <td><input type=text name=Pres size=25></td> <td><div align="right"><b>Primary Inductance (mH)</b></div></td> <td><input type=text name=Pind size=25></td> </tr> <tr> <td align=right><b>Secondary Resistance (ohms)</b></td> <td><input type=text name=Sres size=25></td> <td><div align="right"><b>Secondary Inductance (H)</b></div></td> <td><input type=text name=Sind size=25></td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>Peak Operating Current (Amps)</b></td> <td><input type=text name=POC size=25></td> <td> </td> <td> </td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>Output Energy (mJ)</b></td> <td><input type=text name=Egy size=25></td> <td><div align="right"><b>Output Voltage (kV)</b></div></td> <td><input type=text name=Volt size=25></td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right><b># HV Towers per Coil</b></td> <td><input type=text name=TPC size=25></td> <td><div align="right"><b># of Coils per Package</b></div></td> <td><input type=text name=CPP size=25></td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <th colspan=4><b>Please enter any additional information he </b></th> </tr> <tr> <th colspan=4><textarea name=Mess cols=50 rows=10 id="Message"></textarea></th> </tr> </table> </dl> <div align="center"> <p> <input type=hidden name=BodyTag value="<body bgcolor="#484589" text="#FFFFFF" link="#FFFF00" alink="#FFFFFF" vlink="#FF7F00">"> <input type=hidden name=FA value=SendMail> </p> <p><font color="#FFFF00" face="Arial, Helvetica, sans-serif"><strong>PLEASE MAKE SURE ALL INFORMATION<br> IS CORRECT BEFORE SUBMITTING</strong></font></p> <p> <input type=submit value="Submit Form"> </p> </div> </form> THE FILE THAT PROCESSES THE FORM DATA (formdata.php) *********************************************** <?php $con = mysql_connect("localhost","XXX","XXX"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("customform", $con); $sql="INSERT INTO formdata (Fname, Lname, Title, Comp, Addr, City, SProv, Ctry, ZPC, Tel, Fax, Email, EAV, Appl, Syst, Pres, Pind, Sres, Sind, POC, Egy, Volt, TPC, CPP, Mess) VALUES ('$_POST[Fname]','$_POST[Lname]','$_POST[Title]','$_POST[Comp]','$_POST[Addr]','$_POST[City]','$_POST[SProv]','$_POST[Ctry]','$_POST[ZPC]','$_POST[Tel]','$_POST[Fax]','$_POST[Email]','$_POST[EAV]','$_POST[Appl]','$_POST[Syst]','$_POST[Pres]','$_POST[Pind]','$_POST[Sres]','$_POST[Sind]','$_POST[POC]','$_POST[Egy]','$_POST[Volt]','$_POST[TPC]','$_POST[CPP]','$_POST[Mess]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Your Information Was Successfully Posted"; mysql_close($con); $to = "recipient email address here"; $subject = "Custom Form"; $email = $_POST['Email'] ; $message = $_POST['Comp'] ; $headers = "From: $Email"; $sent = mail($to, $subject, $message, $headers) ; if($sent) {print "Your mail was sent successfully"; } else {print "We encountered an error sending your mail"; } ?> I am generating a html form that will be sent to a mysql database. In order to fill out this form you must be logged in. On the html form I want a spot for username, this username should be the same one they logged in with. How can I have a spot on the page that automatically has the logged in users username and be able to send that to the database. If anyone could direct me to a website that would be awesome. I realize I am setting myself up for a "let me google that for you" post but I am very new to php and have been searching but cannot find anything. Thanks for the help Ok, so what im trying to achieve is this... you come to this page: http://www.hutcommunity.com/Database/playercard.php You click on a player... and his information is loaded into the table. You can then add "training cards" to the players stats... eg, +5skt or +9 skt, etc, to get them higher stats. each player has a set amount of training slots. below is my code, and its pretty close, but when you do a +9skt and +9hnd, its adding +9 and +9 to stats 1 and 2 instead of 9 for each one... because of the code... so how would i be able to achieve this?? i feel like im really close!!! Code: [Select] <!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>Player Card</title> <script type="text/javascript" src="jquery-1.3.2.js"></script> <script type="text/javascript" src="jquery.form.js"></script> <script type="text/javascript"> // wait for the DOM to be loaded $(document).ready(function() { // bind 'myForm' and provide a simple callback function $('#myForm').ajaxForm(function() { alert("Thank you for your comment!"); }); }); </script> </head> <body> <table cellpadding="0" cellspacing="0" class="display" id="example"> <thead> <tr> <th></th> <th align="left">FIRST NAME</th> <th align="left">LAST NAME</th> <th align="center">OVR</th> <th align="center">POT</th> <th align="left">TEAM</th> <th align="left">LEAGUE</th> <th align="center">SKT</th> <th align="center">SHT</th> <th align="center">HND</th> <th align="center">CHK</th> <th align="center">DEF</th> <th>SALARY</th> <th>CAREER</th> <th align="center">POSITION</th> <th>TYPE</th> <th>SLOTS</th> </tr> </thead> <tbody> <? $username="???"; $password="???"; $database="???"; mysql_connect('hutcommunity.db.6977873.hostedresource.com',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM Players WHERE Team='Buffalo Sabres'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $First_Name=mysql_result($result,$i,"First_Name"); $Last_Name=mysql_result($result,$i,"Last_Name"); $Team=mysql_result($result,$i,"Team"); $League=mysql_result($result,$i,"League"); $Career_Games=mysql_result($result,$i,"Career_Games"); $Salary=mysql_result($result,$i,"Salary"); $Position=mysql_result($result,$i,"Position"); $Player_Type=mysql_result($result,$i,"Player_Type"); $Training_Slots=mysql_result($result,$i,"Training_Slots"); $Stat_1=mysql_result($result,$i,"Stat_1"); $Stat_2=mysql_result($result,$i,"Stat_2"); $Stat_3=mysql_result($result,$i,"Stat_3"); $Stat_4=mysql_result($result,$i,"Stat_4"); $Stat_5=mysql_result($result,$i,"Stat_5"); $Overall=mysql_result($result,$i,"Overall"); $Potential=mysql_result($result,$i,"Potential"); $Mugshot=mysql_result($result,$i,"Mugshot"); echo "<tr> <td><img src=\"http://cdn.nhl.com/photos/mugs/thumb/$Mugshot.jpg\" width=\"37\" height=\"47\" /></td> <td><strong><span class=\"Name\"><a href=\"playercard.php?id=$Mugshot\">$First_Name</a></strong</span></td> <td><strong><span class=\"Name\"><a href=\"playercard.php?id=$Mugshot\">$Last_Name</a></strong</span></td> <td align=\"center\"><span class=\"Overall\"><strong>$Overall</strong></span></td> <td align=\"center\"><span class=\"Potential\"><strong>$Potential</strong></span></td> <td>$Team</td> <td align=\"center\">$League</td> <td align=\"center\"><strong>$Stat_1</strong></td> <td align=\"center\"><strong>$Stat_2</strong</td> <td align=\"center\"><strong>$Stat_3</strong</td> <td align=\"center\"><strong>$Stat_4</strong</td> <td align=\"center\"><strong>$Stat_5</strong</td> <td align=\"center\">$Salary</td> <td align=\"center\">$Career_Games</td> <td align=\"center\">($Position)</td> <td align=\"center\">$Player_Type</td> <td>0 / $Training_Slots</td> </tr> "; $i++; } ?> </tbody> </table> <? $username="???"; $password="???"; $database="???"; $id = $_GET['id']; $Slot1=$_POST['Slot1']; $Slot2=$_POST['Slot2']; $Slot3=$_POST['Slot3']; $Slot4=$_POST['Slot4']; $Slot5=$_POST['Slot5']; $Slot6=$_POST['Slot6']; $Slot7=$_POST['Slot7']; $Slot8=$_POST['Slot8']; $Slot9=$_POST['Slot9']; $Slot10=$_POST['Slot10']; $Slot11=$_POST['Slot11']; $Slot12=$_POST['Slot12']; mysql_connect('hutcommunity.db.6977873.hostedresource.com',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM Players WHERE Mugshot='$id'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $First_Name=mysql_result($result,$i,"First_Name"); $Last_Name=mysql_result($result,$i,"Last_Name"); $Team=mysql_result($result,$i,"Team"); $League=mysql_result($result,$i,"League"); $Career_Games=mysql_result($result,$i,"Career_Games"); $Salary=mysql_result($result,$i,"Salary"); $Position=mysql_result($result,$i,"Position"); $Player_Type=mysql_result($result,$i,"Player_Type"); $Training_Slots=mysql_result($result,$i,"Training_Slots"); $Stat_1=mysql_result($result,$i,"Stat_1"); $Stat_2=mysql_result($result,$i,"Stat_2"); $Stat_3=mysql_result($result,$i,"Stat_3"); $Stat_4=mysql_result($result,$i,"Stat_4"); $Stat_5=mysql_result($result,$i,"Stat_5"); $Overall=mysql_result($result,$i,"Overall"); $Potential=mysql_result($result,$i,"Potential"); $Mugshot=mysql_result($result,$i,"Mugshot"); $S1M99 = 99-$Stat_1; $S2M99 = 99-$Stat_2; $S3M99 = 99-$Stat_3; $S4M99 = 99-$Stat_4; $S5M99 = 99-$Stat_5; $SKATE5=5; $SKATE7=7; $SKATE9=9; $HAND5=5; $HAND7=7; $HAND9=9; $SKATETOTAL = $Stat_1+$Slot1+$Slot2; $HANDTOTAL = $Stat_2+$Slot1+$Slot2; echo " <table width=\"500\" border=\"2\" cellspacing=\"2\" cellpadding=\"2\"> <tr> <td colspan=\"3\" rowspan=\"3\"><img src=\"http://cdn.nhl.com/photos/mugs/$Mugshot.jpg\"/></td> <td width=\"294\">$League</td> </tr> <tr> <td>$Team</td> </tr> <tr> <td>$Overall $Potential</td> </tr> <tr> <td colspan=\"4\">$First_Name $Last_Name</td> </tr> <tr> <td width=\"67\">SKT</td> <td width=\"58\">$Stat_1</td> <td width=\"43\">$S1M99</td> <td>$SKATETOTAL</td> </tr> <tr> <td>SHT</td> <td>$Stat_2</td> <td>$S2M99</td> <td>$HANDTOTAL</td> </tr> <tr> <td>HND</td> <td>$Stat_3</td> <td>$S3M99</td> <td> </td> </tr> <tr> <td>CHK</td> <td>$Stat_4</td> <td>$S4M99</td> <td> </td> </tr> <tr> <td>DEF</td> <td>$Stat_5</td> <td>$S5M99</td> <td> </td> </tr> </table> "; $i++; } ?> <form id="myForm" method="post"> <? $username="???"; $password="???"; $database="???"; $id = $_GET['id']; mysql_connect('hutcommunity.db.6977873.hostedresource.com',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM Players WHERE Mugshot='$id'"; $result=mysql_query($query); $var = $Training_Slots; foreach(range(1,$var) as $num) { echo "Training Slot $num: <select name=\"Slot$num\" id=\"Slot$num\"> <option value=\"\">Choose Training</option> <option value=\"$SKATE5\">+5 SKT</option> <option value=\"$SKATE7\">+7 SKT</option> <option value=\"$SKATE9\">+9 SKT</option> <option value=\"$HAND5\">+5 HND</option> <option value=\"$HAND7\">+7 HND</option> <option value=\"$HAND9\">+9 HND</option> </select><br> "; } ?> <input type="Submit"> </form> </body> </html> Hey everybody! This is probably a simple fix, but it has been a big issue for me. I have actually in the past changed the whole table to fix this. I want to be professional this time. Basically, I have created a forum. It is a basic forum. There are three separate tables for it, the posts, and topics. I want to be able to let them pick the NAME of the topic they want to create the topic in from a drop down box, but have the query insert it as an id. So, lets say, this: General Chat is id 1 Help Chat is id 2 The drop down I select is Help chat, it will enter 2 instead of help chat. How do I do this the SIMPLE way? thanks! Here is my code fro the forums: Code: [Select] <?php session_start(); include("config536.php"); ?> <html> <head> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <?php if(!isset($_SESSION['username'])) { echo "<banner></banner><nav>$shownavbar</nav><ubar><a href=login.php>Login</a> or <a href=register.php>Register</a></ubar><content><center><font size=6>Error!</font><br><br>You are not Logged In! Please <a href=login.php>Login</a> or <a href=register.php>Register</a> to Continue!</center></content>"; } if(isset($_SESSION['username'])) { echo "<nav>$shownavbar</nav><ubar>$ubear</ubar><content><center><font size=6>Boards</font><br><br>"; $getboardid = $_GET['boardid']; $gettopicid = $_GET['topicid']; $getpostid = $_GET['postid']; $view = $_GET['view']; $newtopic = $_GET['action']; if(isset($view)) { echo "<center>Welcoem to the Boards! Please read the <a href=tos.php>Rules</a> before posting anything. Feel free to browse whenever you'de like. :)<br><br><table border=1 bordercolor=black cellspacing=0 cellpadding=10><tr><td><center><b>Board Name</b></center></td><td><center><b>Description</b></center></td><td><center><b>Topics</b></center></td><td><center><b>Posts</b></center></td></tr>"; $gettq = "SELECT * FROM category WHERE catid!= '0'"; $gett = mysql_query($gettq); while($rowy = mysql_fetch_array($gett)) { $tid = $rowy['catid']; $tname = $rowy['name']; $tposts = $rowy['posts']; $ttopics = $rowy['topics']; $tdesc = $rowy['body']; echo "<tr><td><center><a href=?boardid=$tid>$tname</a></center></td><td><center>$tdesc</center></td><td><center>$ttopics</center></td><td><center>$tposts</center></td></tr>"; } echo "</table><br><br><a href=?action=create>Create a New Topic</a><br><br><br></center>"; } if(isset($getboardid)) { echo "<table border=1 bordercolor=black cellpadding=10 cellspacing=0><tr><td><center><b>Topic Name</b></center></td><td><center><b>Created By</b></center></td><td><center><b>Date</b></center></td></tr>"; $getbq = "SELECT * FROM topics WHERE boardin='$getboardid'"; $getb = mysql_query($getbq); while($crow = mysql_fetch_array($getb)) { $uname = $crow['username']; $unm = $crow['name']; $ubodu = $crow['body']; $ucount = $crow['countit']; $ucreate = $crow['created']; $utid = $crow['topicid']; echo "<tr><td><center><a href=?topicid=$utid>$unm</a></center></td><td><center>$uname</center></td><td>$ucreate</center></td></tr>"; } echo "</table>"; } if(isset($gettopicid)) { $nowtq = "SELECT * FROM posts WHERE topicon='$gettopicid'"; $nowt = mysql_query($nowtq); while($now = mysql_fetch_array($nowt)) { $postidis = $now['postid']; $poster = $now['poster']; $thisb = $now['body']; $getdate = $now['date']; $gettopic = $now['topicon']; $uq = "SELECT * FROM users WHERE username='$poster'"; $uset = mysql_query($uq); while($row = mysql_fetch_array($uset)) { $did = $row['userid']; $dun = $row['username']; $dpo = $row['posts']; $dmp = $row['mainpet']; $dac = $row['avatarcount']; $dua = $row['useravatar']; $djs = $row['jobs']; $aq = "SELECT * FROM avatars WHERE name='$dua'"; $aaa = mysql_query($aq); while($arow = mysql_fetch_array($aaa)) { $theimage = $arow['image']; } echo "<tr><td><table border=0 cellspacing==1 cellpaddign=3 bgcolor=#F58B8E><tr><td bg color=#FFFFFF align=center valign=top width=100><font face=verdana size=3 color=#000000><br><br><a href=lookup.php?username=$dum>$dun</a><br><br><img src=/images/avatars/$theimage><br><br><br>Posts: $dpo<br><br></font></td><td bgcolor=#FFFFFF align=center valign=top width=300><font face=verdana size=3 color=black><i>Posted on: $getdate</i><br><br>$thisb</font></td></tr></table><br><br><br>"; } } $submitpost = $_POST['post']; $reply = $_POST['reply']; ?> <br><br><br><br><form action="<?php echo "$PHP_SELF"; ?>" method="POST"><center><font size=5>Post a Reply</font><br> <textarea name="reply" rows="5" cols"32"></textarea><br><br><input type="submit" name="post" action="Post Reply"><br><br><br></form></center><?php if(isset($submitpost)) { if($reply == "") { echo "<font color=red>Error! Please enter a reply!</font>"; } if($reply != "") { mysql_query("INSERT INTO posts (poster, body, date, topicon) VALUES ('$showusername', '$reply', '$sitetime', '$gettopicid')"); echo "<font color=green>Success! Your reply has been posted!</font>"; } } } if(isset($newtopic)) { $name = $_POST['tname']; $tbody = $_POST['tbody']; $tcat = $_POST['tcat']; $nownow = $_POST['submit']; if(!isset($nownow)) { ?> <form action="<?php echo "$PHP_SELF"; ?>" method="POST"> Topic Title: <input type="text" name="tname"><br> <select name="topic"><option>General Chat</option> <option>Help Chat</option> </select><br><br>Body:<br><textarea name="tbody" cols="38" rows="8"></textarea><br><br><input type="submit" name="submit" value="Create Topic"></form> <?php } if(isset($nownow)) { mysql_query("INSERT INTO topics (name, username, body, countit, boardin, created) VALUES ('$name', '$showusername', '$tbody', '0', '$tcat', 'sitetime')"); echo "<font color=green>Success! Your Topic has been created.</font>"; } echo "meeba."; } } ?> </html> The part I'm talking about can be found down by one oft he last if statements. The one that says "if(isset($newtopic)) {" I appreciate any help in advance, thank you! Hello Guys, I am new to the forum and i would be greatfull if any one can help me with this script. The Script is supposed to fill that info in to mysql. The problem is when i fil the form and i click Submit then it show me my home page it shuld show localhost/index.php?page=addID but it bring me back to localhost/index.php?page=home Index.php <?php include_once 'Login.php'; include_once 'admin_add.class.php'; include_once ('content_home.class.php'); include_once ('html_page.class.php'); // Create new HtmlPage to display content in browser // Declarartion, set properties for HtmlPage object $htmlpage = new HtmlPage(); $htmlpage->setMetaDescription("Webpage for First database OO in PHP"); $htmlpage->setMetaKeywords("php, object orientend, database"); $htmlpage->setCssFile("css/style.css"); $htmlpage->setFavicon("images/favicon.ico"); // Set content to the body of the HtmlPage object $htmlpage->setContentPart(new ContentHome()); $htmlpage->setTitle("Homepage - Database OO PHP"); $htmlpage->setHeaderPart("Home Page"); $htmlpage->setFooterPart("Copyright 2011 by The Movies"); $htmlpage->setMenuPart("<ul> <li><a href='index.php?page=home' class='mainlevel'>Home</a><br /></li> <li><a href='index.php?page=addID' class='mainlevel'>Add Item</a><br /></li> </ul>"); // Process page specifications if ($_SERVER['REQUEST_METHOD'] == 'GET') { if ($_GET['page'] == 'addID') { $htmlpage->setContentPart(new ContentAddItem()); $htmlpage->setTitle("Add item - Database OO PHP"); $htmlpage->setHeaderPart("Add Page"); } } Admin Add Items admin_add.class.php <?php include_once ('bodypart.class.php'); include_once 'sqlhandler.class.php'; class ContentAddItem extends BodyPart { public function render() { // html variabelen ophalen $sTitel = $_POST['titel']; $sPrijs = $_POST['prijs']; $sKorte_text = $_POST['korte_text']; $sLange_text = $_POST['lange_text']; $sBesteld = $_POST['besteld']; $sFoto = $_POST['foto']; $sSpecial_offer = $_POST['special_offer']; $sType = $_POST['type']; require "cgi-bin/connector.php"; // sql insert die je in de database gaat doen $sql =("INSERT INTO product (id, titel, prijs, korte_text, lange_text, besteld, foto, special_offer, type) VALUES ('','".$sTitel."', '".$sPrijs."', '".$sKorte_text."', '".$sLange_text."', '".$sBesteld."', '".$sFoto."', '".$sSpecial_offer."', '".$sType."')"); //uitvoeren van de query : $adddata = $sqlConnection->executeQuery($sql); $result .= "<form action=\"index.php?page=addID\" method=\"POST\"> Titel:<br /> <input type=\"text\" name=\"titel\"><br /><br /> Prijs:<br /> <input type=\"text\" name=\"prijs\"><br /><br /> Korte_text:<br /> <input type=\"text\" name=\"korte_text\"><br /><br /> Lange_text:<br /> <input type=\"text\" name=\"lange_text\"><br /><br /> Besteld:<br /> <input type=\"text\" name=\"besteld\"><br /><br /> Foto:<br /> <input type=\"text\" name=\"foto\"><br /><br /> Special_offer:<br /> <input type=\"text\" name=\"special_offer\"><br /><br /> Type:<br /><br /> <input id=\"movie\" type=\"radio\" name=\"Type\" value=\"movie\" checked /><label for=\"movie\">Movie</label><br /> <input id=\"audio\" type=\"radio\" name=\"Type\" value=\"audio\" /><label for=\"audio\">Audio</label><br /> <input id=\"book\" type=\"radio\" name=\"Type\" value=\"book\" checked /><label for=\"book\">Book</label><br /> <input type =\"submit\" value=\"verzenden\"> </form>"; $result .= "<br>"; $result .= "<br>"; $result .= "<br>"; return $result; } } ?> Thanks in advanced Hi,
I created a form that inserts first - last name, address, and email address into a mysql databse table.
The record inserts correctly - No problems here.
The problem is I only want to insert the data if the email and address doesn't exist.
I set it up for just the email right now to try to get this to work but have failed.
When the form is submitted and the record exists it inserts the record anyway and sends the email which it's not suppose to do.
The form is suppose to after submitting -
1. validate
2. insert only if the record doesn't exist
3. send the email.
Here's the code
<?php $to = "email@email.com"; if(isset($_POST['submit'])) { // VALIDATION if(empty($_POST['firstName'])) { $errorfirstName .= "First Name Required"; } if(empty($_POST['lastName'])) { $errorfirstName .= "Last Name Required"; } if(empty($error)) # No error go ahead and email it. { $to = "$to"; $subject = 'the form'; $msg .="<html><head> <meta http-equiv='Content-Type' content='text/html; charset=utf-8' /> <title>The Form</title> </head> <body> <table> <tr> <td>Email sent for confirmation</td> </tr> </table> </body> </html>"; $mail($to, $subject, $headers, $msg); if(!$result) { $error = "<div id='errors'>There was an unknown error </div>"; } else { include('connection.php'); $firstName = mysqli_real_escape_string($con, $_POST['firstName']); $lastName = mysqli_real_escape_string($con, $_POST['lastName']); $address = mysqli_real_escape_string($con, $_POST['address']); $email = mysqli_real_escape_string($con, $_POST['email']); $email = $_POST['email']; $sql = "SELECT * FROM table WHERE `email` = '{$email}'"; $result = mysql_query($sql); if ( mysql_num_rows ( $result ) > 0 ) { $error = "Email Exists."; } else { $error = "Email does not exist. Insert it!!!"; $sql="INSERT INTO table (firstName, lastName, address, email) VALUES ('$_POST[firstName]','$_POST[lastName]','$_POST[address]', '$_POST[email]')"; } if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } mysqli_close($con) { } } } } ?> <!-- Form --> <html> <head></head> <body> <section> <form method="POST" action="theform" name="for" onsubmit="return validateForm(this)"> <?php if(!empty($error)) { echo "$error"; } ?> This where the inputs would go not going to include them because not having an issue with the form </form> </section> </body> </html> Edited by barkly, 26 October 2014 - 06:54 PM. Hi I currently have this form to update the names of each session in the database. However how do I go about updating more than one value. I also want to update the 'order' swell as the name so the order in which they're displayed is updated I want to have another text field next to it for the order which will just be a number but i can't figure out how to update both in the foreach() function Code: [Select] <?php if($_POST['update_sessions']){ foreach($_POST as $sessionid => $sessionname){ mysql_query("UPDATE `sessions` SET `name`='".mysql_real_escape_string($sessionname)."' WHERE `id`='".mysql_real_escape_string($sessionid)."'"); } echo("Done!"); } ?> <form method="post"> <?php $getsessions = mysql_query("SELECT * FROM `sessions` ORDER BY `order`"); while($sessions = mysql_fetch_array($getsessions)){ echo("<input type='text' name='".$sessions['id']."' value='".$sessions['name']."'><br />\n"); } ?> <input type="submit" value="Update" name="update_sessions" /> </form> Hi, Hoping someone could help me, im not great at php programming and im trying to implement a search form which searches a sql database but for some reason its not working i keep on getting the following error.. " Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\site\contact\search.php on line 141" Im not sure why this happens and its really starting to bug me now :/ I have to pages to the search feature, one page which contains the <form> and the other with the PHP code.... the form.. <form method="get" action="search.php"> <label>Search Term: <input type="text" id="query" name="query"/> </label> <label> <select name="category" id="category"> <option value="none">Please Select a Type</option> <option value="teamname">Manager Name</option> <option value="manager">Team Name</option> <option value="age">Age Group</option> </select> </label> <input name="Search" type="submit" value="Search"/> </form> the PHP code.. <?php $query=$_GET['query']; $db_host="localhost"; $db_username="root"; $db_password=""; $db_name="info"; $db_tb_name="info"; $db_tb_atr_name=$_GET['category']; mysql_connect("$db_host","$db_username","$db_password"); mysql_select_db("$db_name"); $query_for_result=mysql_query("SELECT * FROM $tb_name WHERE $db_tb_atr_name like '%".$query."%'"); while($data_fetch=mysql_fetch_array($query_for_result)) { echo "<p>"; echo $data_fetch['table_attribute']; echo "</p>"; } mysql_close(); ?> Id be really great full for any light you guys could shed on this for me with thanks, fozze Hi, when someone logs in to my page, i have a form displayed with names, address, etc...what i need to do is when i hit the update button for that information to go into the MYSQL table I have created and over write that information if a user updates...so how do i do that? Having trouble where I think I need to provide most of my code to see what is happening. Trying to output a simple table of cameras. They are stored as part of a form with data filled in already. A user can change and hit the apply button for any camera in the row. The changes should update the db for that camera only (just that one row). The problem is that when I hit apply it doesn't make the change to the row. The exception is the very last row (last camera in the list). I tried to simplify the mysql update query to just one select (camera_status) to figure out what is going on. The problem is that if I echo camera_status it is showing the wrong value. i.e. if I change the form select from Enabled to Disabled. Something wrong with how I'm doing the POST? I appreciate any guidance. Code: [Select] <?php // Dont allow direct linking defined('_JEXEC') or die('Direct Access to this location is not allowed.'); //get current user $user =& JFactory::getUser(); // get a reference to the database $db = &JFactory::getDBO(); if (isset($_POST['apply_changes'])) { //process changes to camera options $camera_id = (int) $_POST['camera_id']; echo "CAMERA ID ".$camera_id; $camera_status = check_input($_POST['camera_status']); echo "CAMERA STATUS ".$camera_status; $camera_name = check_input($_POST['camera_name']); $camera_quality = check_input($_POST['camera_quality']); $query_insert_camera = 'UPDATE `#__cameras` SET `camera_status` ="'.$camera_status.'" WHERE `camera_id`='.$camera_id; echo "CAMERA query ".$query_insert_camera; $db->setQuery($query_insert_camera); $db->query(); } function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { echo $myError; exit(); } echo "<html>"; echo "<head>"; ?> <script type="text/javascript"> function oncameraSubmit(camera_id) { //TODO get camera name i.e. "Apply changes to <camera name>" document.active_cameras.camera_id.value = camera_id; return confirm('Apply changes?'); } </script> <?php $query_camera_name = "SELECT camera_id, camera_name, camera_status, camera_quality, camera_hash, camera_type FROM #__cameras WHERE user_id=".$user->id." AND camera_status!='DELETED'"; $db->setQuery($query_camera_name); //get number of cameras so we can build the table accordingly $db->query(); $num_rows = $db->getNumRows(); // We can use array names with loadAssocList. $result_cameras = $db->loadAssocList(); echo "</head>"; echo "<body>"; //check if we have cameras running (basically someone logged in) if (!isset($result_cameras)) { //TODO check if query failed } else { if ($num_rows == 0) { echo '<b><i><center>You currently have no cameras setup. Add a Camera below.</center></i></b>'; } else { ?> <form name="active_cameras" action="<?php htmlentities($_SERVER['REQUEST_URI']); ?>" method="POST"> <input type="hidden" name="camera_id" value="" /> <table id="webcam-table"> <thead> <tr> <th>Camera Type</th> <th>Name</th> <th>Quality</th> <th>Status</th> <th>Camera Actions</th> </tr> </thead> <tbody> <?php for($i=0;$i<$num_rows;$i++) { //camera_status if ($result_cameras[$i]["camera_status"] == "ENABLED") { $enabled_option = "value='ENABLED' selected='selected'"; $disabled_option = "value='DISABLED'"; } else { $enabled_option = "value='ENABLED'"; $disabled_option = "value='DISABLED' selected='selected'"; } //camera_quality if ($result_cameras[$i]["camera_quality"] == "HIGH") { $high_option = "value='HIGH' selected='selected'"; $medium_option = "value='MEDIUM'"; $mobile_option = "value='MOBILE'"; } else if ($result_cameras[$i]["camera_quality"] == "MEDIUM") { $high_option = "value='HIGH'"; $medium_option = "value='MEDIUM' selected='selected'"; $mobile_option = "value='MOBILE'"; } else if ($result_cameras[$i]["camera_quality"] == "MOBILE") { $high_option = "value='HIGH'"; $medium_option = "value='MEDIUM'"; $mobile_option = "value='MOBILE' selected='selected'"; } else { //TODO proper logging } //camera_type if ($result_cameras[$i]["camera_type"] == "WEBCAM") { $webcam = "value='WEBCAM' selected='selected'"; $axis = "value='AXIS'"; $other = "value='IPCAM'"; } else if ($result_cameras[$i]["camera_type"] == "AXIS") { $webcam = "value='WEBCAM'"; $axis = "value='AXIS' selected='selected'"; $other = "value='IPCAM'"; } else if ($result_cameras[$i]["camera_type"] == "IPCAM") { $webcam = "value='WEBCAM'"; $axis = "value='AXIS'"; $other = "value='IPCAM' selected='selected'"; } else { //TODO proper logging } echo $result_cameras[$i]["camera_id"]; ?> <tr> <td> <?php echo $result_cameras[$i]["camera_type"] ?> </td> <td> <input type="text" size="32" maxlength="64" name="camera_name" value="<?php echo $result_cameras[$i]["camera_name"]; ?>" /> </td> <td> <select name="camera_quality"> <option <?php echo $high_option; ?>>High</option> <option <?php echo $medium_option; ?>>Medium</option> <option <?php echo $mobile_option; ?>>Mobile</option> </select> </td> <td> <select name="camera_status"> <option <?php echo $enabled_option; ?>>Enabled</option> <option <?php echo $disabled_option; ?>>Disabled</option> </select> </td> <td> <input type="submit" name="apply_changes" value="Apply" onClick="oncameraSubmit(<?php echo $result_cameras[$i]["camera_id"]; ?>);"/> <input type="submit" name="delete" value="Delete" onClick="oncameraDelete(<?php echo $result_cameras[$i]["camera_id"]; ?>);"/> <input type="submit" name="video" value="Launch" onClick="oncameraLaunch(<?php echo $result_cameras[$i]["camera_id"]; ?>);"/> </td> </tr> <?php } echo "</tbody>"; echo "</table>"; echo "</form>"; } } echo "</body>"; echo "</html>"; ?> Hello I am trying to do a simple CSV import of a file and then upload to mysql. I am basing my code on an example I have found and I am getting the error message 'invalid file'. The example used includes a text box for the file import field and I am referencing the file from my computer in that box 'Users/James/name.csv' My code is as follows: HTML <form action="results.php?data=upload" method='post'> Import File : <input type='text' name='sel_file' size='20'> <input type='submit' name='submit' value='submit'> </form> PHP if ($b == 'upload') { $fname = $_FILES['sel_file']['name']; $chk_ext = explode(".",$fname); if(strtolower($chk_ext[1]) == "csv") { $filename = $_FILES['sel_file']['tmp_name']; $handle = fopen($filename, "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $sql = "INSERT into ".$db['name']."(field1,field2,field3,field4) values('$data[0]','$data[1]','$data[2]', '$data[3]')"; mysql_query($sql) or die(mysql_error()); } fclose($handle); echo "Successfully Imported"; } else { echo "Invalid File"; } } my file format is: 1,23,1,5 1,24,2,5 1,25,3,5 1,26,4,5 1,27,5,5 1,28,6,5 1,29,7,5 1,30,8,5 1,31,9,5 1,32,10,5 If anybody can help that would be good - or perhaps point out if I am going about this the wrong way - cheers I've got a form on my site, with a textbox...and the info is sent to a db. How would I get the textbox info to be displayed the same as it was entered? For instance if I put in an address: 11 Street Town City PostCode It gets displayed like: 11StreetTownCityPostCode How could I have it so when I press enter it actually adds a <br> or something to the db? Thanks. Hi friends I have a form with mysqli comnnection <label for="fullname">Fullname</label> <input type="text" name="fullname" /> <label for="photo">Upload photo</label> <input name="photo" type="file"/> and on the php ends I have $fullname = $_POST['fullname']; $uploaddir = './uploads/'; //upload file in folder $uploadfile = $uploaddir. basename($_FILES['photo']['name']); //insert filename in db $upload_filename = basename($_FILES['photo']['name']); move_uploaded_file($_FILES['photo']['tmp_name'], $uploadfile); $photo = $upload_filename; $sql = "INSERT INTO members(fullname,photo) VALUES('$fullname', '$photo'); $stmt = $link->query($sql) or die($link->error); $stmt->close; Please help me, I am using this on a live site Each time i submit this form it wont send to mysql, can anyone help?
<?php $hostname="mysql6.000webhost.com"; //local server name default localhost $username="a5347792_meto"; //mysql username default is root. $password=""; //blank if no password is set for mysql. $database="a5347792_login"; //database name which you created $con=mysql_connect($hostname,$username,$password); if(! $con) { die('Connection Failed'.mysql_error()); } mysql_select_db($database,$con); //include connect.php page for database connection include('connect.php'); //if submit is not blanked i.e. it is clicked. if($_SERVER['POST_METHOD'] == 'POST') { if($_POST['name']=='' || $_POST['email']=='' || $_POST['password']==''|| $_POST['repassword']=='') { echo "please fill the empty field."; } else { $sql="insert into student(name,email,password,repassword) values('".$_REQUEST['name']."', '".$_REQUEST['email']."', '".$_REQUEST['password']."', '".$_REQUEST['repassword']."')"; $res=mysql_query($sql); if($res) { echo "Record successfully inserted"; } else { echo "There is some problem in inserting record"; } } } ?> Alright so I am trying to code a very simple form that adds a user to my SQL database with certain information filled in and certain information kept hidden with default values in a form. My index.php file is as follows (not all of the code but just the form part): <?PHP $submitMessage = $_GET['value']; if ($submitMessage == success) { echo '<div class="congratulations"><font color="#84d20c"><strong>Congratulations:</strong></font> The user has been added.</div>'; }else if($submitMessage == NULL){ }else if($submitMessage == fail){ echo '<div class="error"><font color="#d3430c"><strong>Error:</strong></font> An error occurred please check the error details below:</div>'; echo 'ERROR DETAILS:'; echo mysql_error(); } ?> <h1><i>Add User</i></h1> <p>This page is where you would manually add a user to the donations databases (for example you or a member of the community with elevated status that does not need to pay).</p> <br/> <form enctype="multipart/form-data" action="scripts/admin_save_sm_db.php" method="post"> <input name="authtype" value="steam"/><br /><br /> <h3><i>STEAM ID:</i></h3> <input name="identity" value="STEAM_0:X:XXXXXXXX"/><br /> <div class="form_help">Steam ID of the player you wish to add. Must be in the format STEAM_0:X:XXXXXXXX</div><br /> <input name="flags" value="o"/><br /><br /> <input name="name" value="Donator"/><br /><br /> <input name="immunity" value="0"/><br /><br /> <h3><i>Your Email Address</i></h3> <input name="user_email"/><br /> <div class="form_help">Your Email Address for security purposes.</div><br /> <input name="Submit" type="submit" value="Submit" class="form_submit" /> </form> My admin_save_sm_db.php file is as follows: <?php session_start(); if(!isset($_SESSION["username"])) { header('Location: login.php'); exit; } @require("../sm_admin_db.php"); $authtype = $_POST['authtype']; $identity = $_POST['identity']; $flags = $_POST['flags']; $name = $_POST['name']; $immunity = $_POST['immunity']; $user_email = $_POST['user_email']; $link = @mysql_connect(_HOST,_USER,_PASS); @mysql_select_db(_DB); $sql = @mysql_db_query(_DB,"INSERT INTO "._TBL." (`authtype`, `identity`, `flags`, `name`, `immunity`, `user_email`) VALUES (NULL, '$authtype', '$identity', '$flags', '$name', '$immunity', '$user_email')"); $okay = @mysql_affected_rows(); if($okay > 0) { header( "Location: ../index.php?value=success" ); } else { header( "Location: ../index.php?value=fail" ); } @mysql_close($link); ?> And finally my sm_admin_db.php file is as follows: <?PHP //host loaction define("_HOST", "localhost", TRUE); //database username define("_USER", "thatsact_admin", TRUE); //database username`s password define("_PASS", "*********", TRUE); //database name define("_DB", "thatsact_sadadmins", TRUE); //database table name change this to install multiple version on same database define("_TBL", "sm_admins", TRUE); //This is the email that you will recieve emails when someone signs up. define("_EMAIL", "admin@tag-clan.com", TRUE); ?> All of this together does not work and gives the echo error code, however the mysql_error() string does not return anything. Nothing is inserted into the database. Can I get some help on where I went wrong and please keep in mind I am VERY new to php and didn't write most of this script so just tell me what to edit and exactly how to do it please. Thanks in advance. Hi All I am trying to upload a csv file to a database using php html form however, the results shows none of the data passsing through to the database and it produces 1000's of empty fields here is the form Code: [Select] form action="lib/import.php" method="post" enctype="multipart/form-data"> Type file name to import: <input type="file" name="filename" size="20"><br /> <input type="submit" name="submit" value="submit"></form> and here is the passing info Code: [Select] $file = $_FILES['filename']; $sqlstatement="LOAD DATA INFILE '$file' into TABLE shop FIELDS TERMINATED BY ',' (id, merchant_name, product_name, description, category_name, Affiliate_deep_link, Affiliate_image_url, price)" ; mysql_query($sqlstatement); echo "it is done!"; can anyone help please? |