PHP - Dynamic Form Generation From Database
I'm praying there's a function somewhere out there that:
generates a html form based on the fields of a particular table within a DB (namely mySQL) generates the appropriate form input based on the fields type or notes (ie. for field: avatar_img, it knows to generate a file input) uses the POST method to submit generates and submits SQL insert query to database In addition to that, a similar function that generates a form that allows the editing of records. It doesn't take too long to write these each time myself, but if there's a function that you provide the formname, database driver, table name, whether your form is to insert or edit, that would be quite nifty i think. ie. generateForm(addUser, mySQL, tUsers, insert) Seen any such thing? Many thanks. Similar TutorialsI wrote this basic script yesterday to process and generate a Google Site Map. And it works! BUT I want to advance this script to accommodate for something else and I don't know the correct path to take from here, but I will tell you what I've found out so far.. Current Situation: 1 - Currently my below script generates urls in the site map like: http://abcdefg.com/index.php?dispatch=products.view&product_id=29826 2 - I have .htaccess configured to rewrite the urls to the products name data like: http://abcdefg.com/pennies/wheat-pennies/lincoln-wheat-penny-cent.html (just an example) and these urls are ONLY active if clicking on the site links themselves - meaning if I enter: http://abcdefg.com/index.php?dispatch=products.view&product_id=29826 directly into the url, the url does not resolve to this natural friendly url name. What Id like to achieve (which I don't know what direction I should be looking!): - I'd like my xml output urls (as current) to be written in the natural format (as in #2 above). FYI here is a current example output item in my sitemap: Code: [Select] <url> <loc>http://abcdefg.com/index.php?dispatch=products.view&product_id=29803</loc> <changefreq>weekly</changefreq> <lastmod>2010-09-24T08:00:00+04:00</lastmod> </url> Can anyone give me some guidance on what method might work for this? Do you think it's more a mod_rewrite issue? Or can this be handled easier with straight up modifications to my below? I'm just a bit confused on what direction I should be looking.. Thanks for any input. <?php header("Content-Type: text/xml;charset=iso-8859-1"); echo '<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; //include('config.local.php'); $cxn = mysqli_connect($config['db_host'], $config['db_user'], $config['db_password'], $config['db_name']); $query = "SELECT cscart_product_descriptions.product_id, cscart_products.product_id, cscart_products.timestamp FROM cscart_product_descriptions JOIN cscart_products ON cscart_product_descriptions.product_id = cscart_products.product_id WHERE cscart_products.status='A' LIMIT 10000"; $result = mysqli_query($cxn, $query); $row = mysqli_fetch_array($result); while ($row = mysqli_fetch_array($result)) { $formatedTime = $row['timestamp']; echo '<url> <loc>http://abcdefg.com/index.php?dispatch=products.view&product_id=' . $row['product_id'] . '</loc> <changefreq>weekly</changefreq> <lastmod>'. date('c',$formatedTime) .'</lastmod> </url>'; } //while ($row = mysqli_fetch_array($result)) echo '</urlset>'; ?> I'm using some code to create a select menu of a fieldname of data I have in a mysql database : Code: [Select] <?php mysql_connect('localhost' , 'dbname', 'password'); mysql_select_db('dbname'); $result=mysql_query("SELECT * FROM Persons"); if(mysql_num_rows($result)>0) { ?> <select name="Persons"> <?php while($rows=mysql_fetch_array($result)){ ?> <option value="<?php echo $rows['id']; ?>"> <?php echo $rows['FirstName']; ?></option> <?php } ?> </select> What I would like to do is to elevate this into a jump menu form so that if the user selects an item from my form they are taken to a results page showing the full row of data from the database. Basically a search form containing items from the database they can choose to see more details on. eg. In my example you select a persons name and then you are taken to a results page which displays the details of that person from the database. Problem is I don't know how to do this and have been trawling around for a couple of days to find a solution (sorry I'm new to php). I would appreciate some help or a working example would be great of : 1/ A working dynamic jump menu 2/ The page that would process the form 3/ The results page displaying the data I have selected. Thank you for your time... Hi guys, i was wondering how can i make php to generate custom image with required fields (contact form). For example, i have a page with first name, last name, full address, email. And it's like this: First name: <input field here> Last name: <input field here> Full Address: <input field here> Email: <input field here> I would like to know how can i (once they fill all the info) generate an image with custom background (prepared full image previously) with all the filled info and have it emailed back to him. That email should be something like: Dear, FirstName, Here's your full info displayed on image below <img src="/path/to/thatImage.png"></img> Is this even possible? If so, please let me know how, i used to google a lot, but i can't find a solution, and i'm beginner in coding. Hope you guys will help me out, thanks a lot in advance! Hi, I'm learning php and I'm trying to get to grips with dynamic xml and php coming from a database. The trouble I am having is I can't get my code to give any output. I don't get an error I message, I just can't get the xml to display. If anyone can give me any pointers as to what I'm doing wrong that would be great... Here's the code I have. Code: [Select] <?php DEFINE ('DB_USER', 'root'); DEFINE ('DB_PASSWORD', 'password'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'flashphpbible'); $link = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $query = "SELECT * FROM dynamicxml WHERE id=1"; $result = mysqli_query($link, $query); $xmlData .= " "; $xmlData .= "<store>\n"; while($row = mysqli_fetch_array($result)); { $xmlData .= " <item>\n"; $xmlData .= " <name>".$row['name']."</name>\n"; $xmlData .= " <section>".$row['section']."</section>\n"; $xmlData .= " <price>".$row['price']."</price>\n"; $xmlData .= " <inStock>".$row['instock']."</inStock>\n"; $xmlData .= " </item>\n"; } $xmlData .= "</store>\n"; echo "response=".$xmlData; ?> Thanks for any help offered. Ben. Hey, I'm currently planning on how i will code some breadcrumbs for a shopping site where the admin can add more options/levels to the database which in turn store products. I understand how to get the url of the previous options/level but am stuck on retrieving the name of the level and can only imagine retrieving it from the database. Though Its possible to do so is there any other method as relying on the database for crumbs seems like a easy way out or am i just picky? the typical url is like so: website.com/shop.php?cat_id=1004, so i cant retrieve the name from it unless i cross reference it to its database name and dont know how to retreive from their <a href> tag. On a side note is there a graph that can show a general outline of how many db queries a server can make per second etc depending on its hardware? Thanks. Hiya I was wondering how one would get make dynamic url variable value pairs from a databases fields. I have a database that I want to use to store variable value pairs that will be used on my pages for dynamic content. It will check one thing for certain besides if the variable value pair match. The table looks like this rpg loc_type loc_type template I want it to check if the rpg is in an array and then check if the url variable and value pair match on from the database. I dont know much about auto code that would generate this on its own and I'm not sure if you can say $_GET[$location]; I dont want to hard code it so it only works with what i code I want the urls variable value pair to be based on the database info which determines which template to show based on those values. Hi everyone,
I'm a complete newbie here. I've looked around for help and tried a few solutions without success, so because time is short I'm asking for help.
I have a registration form which includes address details. The form holds a country field which is a listbox, the values being selected from a MySQL table. How do I assign the selected country option to a field list in the insert statement?
Here's what I have so far:
Registration page form:
<div class="form-group"> im making a game and i need to show a users money but i dont know how help? What I have so far is a page that produces a list of usernames with checkboxes next to them. From the usernames that I check, I want to update a field for each of those users. My problem is that the number of checkboxes I check is not going to be static so I am pretty sure I have to run a loop based on the number of checked checkboxes ("People chosen"). Here is what I have so far: Code: [Select] <?php if (isset($_POST['submit1'])) { $pick = $_POST["pick"]; $how_many = count($pick); echo 'People chosen: '.$how_many.'<br><br>'; echo "<br><br>"; $count = 0; while ($count < $how_many) { //mysql code probably should go here but I am stuck $count++; } } else { $gender = mysql_real_escape_string($_POST['Gender']); $limit = mysql_real_escape_string($_POST['limit']); echo $gender; echo "<br />"; $count = 0; if ($gender == 'Male') { $result = mysql_query("SELECT * FROM users WHERE gender =\"1\" LIMIT 0, $limit", $connection); if (!$result) { die("Database query failed: " . mysql_error()); } ?> <form method="post"> <?php while ($row = mysql_fetch_array($result)) { ?> <input name="pick[]" type="checkbox" value="<?php echo $row['username'] ?>"><?php echo $row['username'];?> <br /> <?php } ?> <input type="submit" name="submit1" value="Make Offer" /> </form> <?php } ?> I hope this makes sense. Any help would be greatly appreciated. I am having a lot of trouble with this code, and I have no clue how to fix it. Right now, I have a GUI for a fictitious car dealership that has 5 populated drop down menus called Make, Model, Year, Color, and Mileage. What I want the code to do is read the selections made by the user with the drop down menus once the user hits the submit button and then filter the tables that I have in a mysql database to meets the choice requirements of the user. The code will bring up the GUI, but once I hit the submit button, I get the following errors Please if anyone can help me that would be fantastic. I really have no clue I can not get the values from the javascript add row to go dynamically as a row into MySql only the form values show up as the form below as one row. I made it as an array, but no such luck, I have tried this code around a multitude of ways. I don't know what I am doing wrong, kindly write out the correct way.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...ransitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Dynamic Fields js/php to MySql need to submit dynamically to the database</title> <?php require ('database.php'); ?> <script type="text/javascript"> var counter = 1; var collector = ""; function addfields(indx) { var tbl = document.getElementById('table_id'); var newtr = document.createElement('tr'); counter = counter + indx; newtr.setAttribute('id','tr'+counter); newtr.innerHTML = '<td><input type="checkbox" name="checkb'+counter+'" id="checkb'+counter+'" value="'+counter+'" onclick="checkme('+counter+')"></td><td><input type="text" name="text1[]"></td><td><textarea name="textarea1[]"></textarea></td>'; tbl.appendChild(newtr); } function checkme(dx) { collector += dx+","; } function deletetherow(indx) { var col = collector.split(","); for (var i = 0; i < col.length; i++) { var remvelem = document.getElementById('tr'+col[i]); var chckbx = document.getElementById("checkb"+col[i]); if(remvelem && chckbx.checked) { var tbl = document.getElementById('table_id'); tbl.removeChild(remvelem); } } } </script> </head> <body> <form enctype="multipart/form-data" id="1" style="background-color:#ffffff;" action="<?php echo $_SERVER['PHP_SELF']; ?>"></form> <table id="table_id" > <tr id="tr1" class="trmain"> <td> </td> <td> <input type="text" name="text1[]"> </td> <td> <textarea name="textarea1[]"></textarea> </td> </tr> </table> <input type="button" value="Add" onClick="addfields(1);" /> <input type="button" value="Delete" onClick="deletetherow()" /> <input type="submit" value="Send" id="submit" name="submit"/> <?php if(isset($_POST['submit'])) { for ($i=0; $i < count($_POST['text1']); $i++ ) { $ced = stripslashes($_POST['text1'][$i]); $erg = stripslashes($_POST['textarea1'][$i]); } $bnt = mysql_query("INSERT INTO tablename (first, second) VALUES ('$ced', '$erg')")or die('Error: '. mysql_error() ); $result = mysql_query($bnt); } ?> </body> </html> Hi, I had a form which contains, 8 select boxes. In those 8 select boxes, 3 of the boxes are interlinked, like, I am able to generate data in other 2 select boxes, if one box is been selected. i.e. based upon selection of one select box, and i am able to generate data in other select box. So, 3 select boxes are interlinked. And remaining 5 selects are optional, if the user selects, then we need to generate data based upon selection of the user. Here the main issue is how to grab data in the post back form, like, how to capture the number of selects boxes selected and what are those selected, and based upon that we need to generate data. Here one more important thing is that, in the report generation form(postback form), I need to show the data in a table. So , in table I had 9 columns and these would be common to whatever the selection made, but, only the requeired data would be changed based upon the selection of the remaining 5 optional boxes. Hope you got me!!!! 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 all, it's been a while since I wrote in PHP but a University project has forced me to touch up on my knowledge of it. I'm trying to re-create an old form making system I made a few years ago from memory. But it's not working. I know it's something very obvious but I just need another eye to take a look for me. I get the following error message: Warning: Invalid argument supplied for foreach() in /home/birdneto/public_html/rebelfrogv2/p_createaccount.php on line 169 So I know it's do with my show_form(); function. Can anyone help? Code: [Select] <div id="page-body-special"> <?php // List page details $page_header = "Create your account"; $page_desc = "Enter your details below to create an account. Creating an account comes with great benefits! You can create a wishlist, sign up for our mailing list and purchase items. Make sure you enter all your information correctly."; // List form details $form_name = "createaccount"; // List all the field names here $field_email_address = "email_address"; $field_email_address_confirm = "confirm_email_address"; $field_password = "password"; $field_password_confirm = "confirm_password"; $field_house_number = "house_number"; $field_street_name = "street_name"; $field_city = "city"; $field_county = "county"; $field_postcode = "postcode"; $field_phone_number = "phone_number"; $field_newsletter = "newsletter"; $field_submit = "submit"; // Define all the field meta data (field name, maxlength, minlength, field type, [field options], [field description]) $fields = array( array($field_email_address, 80, 8, "text", $_POST[$field_email_address]), array($field_email_address_confirm, 80, 8, "text", $_POST[$field_email_address_confirm]), array($field_password, 16, 8, "password", $_POST[$field_password]), array($field_password_confirm, 16, 8, "password", $_POST[$field_password_confirm]), array($field_house_number, 2, 4, "password", $_POST[$field_house_number]), array($field_street_name, 16, 8, "password", $_POST[$field_street_name]), array($field_city, 16, 8, "password", $_POST[$field_city]), array($field_county, 16, 8, "password", $_POST[$field_county]), array($field_postcode, 16, 8, "password", $_POST[$field_postcode]), array($field_phone_number, 16, 8, "password", $_POST[$field_phone_number]), array($field_newsletter, 0, 0, "checkbox", $_POST[$field_newsletter], 0, "Would you like to sign up to our newsletter?"), array($field_submit, 0, 0, "submit", "Create Account") ); // Check if form has been submitted or not. All fields must be declared here with an if statement if($_POST['submit']) { // Set no_errors and show_form to inital 0 $no_errors = 1; function show_errors($field) { if($field == $field_email_address) { if(strlen($_POST[$field_email_address]) < $fields[0][2] and strlen($_POST[$field_email_address]) > $fields[0][1]) { $no_errors = 0; $error = "Your email address must be between " . $fields[0][2] . " and " . $fields[0][1] . " characters"; } } if($field == $field_email_address_confirm) { if($_POST[$field_email_address_confirm] != $_POST[$field_email_address]) { $no_errors = 0; $error = "Your emails do not match each other"; } } if($field == $field_password) { if(strlen($_POST[$field_password]) < $fields[2][2] and strlen($_POST[$field_password]) > $fields[2][1]) { $no_errors = 0; $error = "Your password must be between " . $fields[2][2] . " and " . $fields[2][1] . " characters"; } } if($field == $field_password_confirm) { if($_POST[$field_password_confirm] != $_POST[$field_password_confirm]) { $no_errors = 0; $error = "Your passwords do not match"; } } if($field == $field_house_number) { if(strlen($_POST[$field_house_number]) < $fields[4][2] and strlen($_POST[$field_house_number]) > $fields[4][1]) { $no_errors = 0; $error = "Your house number must be between " . $fields[4][2] . " and " . $fields[4][1] . " numbers"; } } if($field == $field_street_name) { if(strlen($_POST[$field_street_name]) < $fields[5][2] and strlen($_POST[$field_street_name]) > $fields[5][1]) { $no_errors = 0; $error = "Your street name must be between " . $fields[5][2] . " and " . $fields[5][1] . " characters"; } } if($field == $field_city) { if(strlen($_POST[$field_city]) < $fields[6][2] and strlen($_POST[$field_city]) > $fields[6][1]) { $no_errors = 0; $error = "Your city must be between " . $fields[6][2] . " and " . $fields[6][1] . " characters"; } } if($field == $field_county) { if(strlen($_POST[$field_county]) < $fields[7][2] and strlen($_POST[$field_county]) > $fields[7][1]) { $no_errors = 0; $error = "Your county must be between " . $fields[7][2] . " and " . $fields[7][1] . " characters"; } } if($field == $field_postcode) { if(strlen($_POST[$field_postcode]) < $fields[8][2] and strlen($_POST[$field_postcode]) > $fields[8][1]) { $no_errors = 0; $error = "Your postcode must be between " . $fields[8][2] . " and " . $fields[8][1] . " characters"; } } if($field == $field_phone_number) { if(strlen($_POST[$field_phone_number]) < $fields[7][2]) { $no_errors = 0; $error = "Your phone number must be under " . $fields[7][2] . " numbers"; } } return $error; } if($no_errors == 0) { show_form(); } else { echo "<p>Form posted</p>"; echo $br . $br; } } else { show_form(); } function show_form() { // Show the page header echo $br . '<form method="post" action="./?p=' . $page . '" name="' . $form_name . '">'; echo $br . $br; echo '<table id="form-' . $form_name . '">'; echo $br; // List all fields in form format foreach($fields as $meta) { // Explode the array and implode it, changes commas to spaces, then makes all words have capital letters $label_exp = explode("_", $meta[0]); $label_imp = ucwords(implode(" ", $label_exp)); // Is the field type a submission? if($meta[3] == "submit") { echo ' <tr><td colspan="2"><input type="' . $meta[3] . '" name="' . $meta[0] . '" class="' . $meta[0] . '" value="' . $meta[4] . '" /></td></tr>'; echo $br; } // Is the field type a select? elseif($meta[3] == "select") { $options = explode(",", $meta[5]); echo ' <tr><td><label>' . $label_imp . '</label></td><td><select type="' . $meta[3] . '" name="' . $meta[0] . '" class="' . $meta[0] . '">'; echo $br; foreach($options as $option) { function is_selected() { if($option == $_POST[$meta[0]]) { echo 'selected="selected"'; } } echo(' <option ' . is_selected($option) . '>' . $option . '</option>'); echo $br; } echo ' </select></td></tr>'; echo $br; } // Is the field type a checkbox? elseif($meta[3] == "checkbox") { echo ' <tr><td><label>' . $meta[6] . '</label></td><td><input type="' . $meta[3] . '" name="' . $meta[0] . '" class="' . $meta[0] . '" /></td></tr>'; echo $br; } // Is the field type anything else? else { echo ' <tr><td><label>' . $label_imp . '</label></td><td><input type="' . $meta[3] . '" name="' . $meta[0] . '" class="' . $meta[0] . '" maxlength="' . $meta[1] . '" value="' . $meta[4] . '" /></td></tr>'; echo $br; } } // Show the page footer echo '</table>'; echo $br . $br; echo '</form>'; echo $br . $br; } echo $br . "<h1>" . $page_header . "</h1>"; echo $br . $br; echo "<p>" . $page_desc . "</p>"; echo $br . $br; echo '<div class="clear"></div>'; echo $br . $br; ?> </div> Okay, so I have a page with a heap of fields and buttons on it (and want to keep it like that really) inside one form. Layout Box 1 Button 1 Box 2 Button 2 Box 3 Button 3 Box 4 Button 4 etc... Box 1 is called 'amount1$id' Box 2 is called 'amount.$id' where $id is the $id of the data being displayed etc So a sample form may look like Box: "amount22" Button: "Pay22" Box: "amount25" Button: "Pay25" Box: "amount32" Button: "Pay32" Box: "amount39" Button: "Pay39" Box: "amount420" Button: "Pay420" Its working fine up to that point. My problem now is that I can't work out how to get that id number from the form once submitted. If I could get the button name somehow I could do it, although I don't know the button or box names when writing the processing script. I could use a loop and check if button1 to buttonX was posted etc, although if there is a large number of entries in the database, then that starts to become a problem. Thoughts? Hi guys, this is very urgent. Can anyone help me out..... I want to generate reports using php and MySQL. I have one table which includes customer_id, full_name, name_with_initials, address, contact_number and gender fields. I want to print the details of all the records of the table. It should be good if results will come on a PDF format. Thanks, Dear All, Below is a php file for my website invitacoach.com I need to issue passwords myself to members who have already paid up for my services...of which they will then be able to access the advantages of a members area which include Videos, Audios and other publications. Which part of my code am i to edit Below is the SQL and register.php code. SQL CREATE TABLE users ( userid int(25) NOT NULL auto_increment, first_name varchar(25) NOT NULL default '', last_name varchar(25) NOT NULL default '', email_address varchar(25) NOT NULL default '', username varchar(25) NOT NULL default '', password varchar(255) NOT NULL default '', info text NOT NULL, user_level enum('0','1','2','3') NOT NULL default '0', signup_date datetime NOT NULL default '0000-00-00 00:00:00', last_login datetime NOT NULL default '0000-00-00 00:00:00', activated enum('0','1') NOT NULL default '0', PRIMARY KEY (userid) ) TYPE=MyISAM COMMENT='Membership Information'; REGISTER.PHP <? include 'db.php'; // Define post fields into simple variables $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email_address = $_POST['email_address']; $username = $_POST['username']; $info = $_POST['info']; /* Let's strip some slashes in case the user entered any escaped characters. */ $first_name = stripslashes($first_name); $last_name = stripslashes($last_name); $email_address = stripslashes($email_address); $username = stripslashes($username); $info = stripslashes($info); /* Do some error checking on the form posted fields */ if((!$first_name) || (!$last_name) || (!$email_address) || (!$username)){ echo 'You did not submit the following required information! <br />'; if(!$first_name){ echo "First Name is a required field. Please enter it below.<br />"; } if(!$last_name){ echo "Last Name is a required field. Please enter it below.<br />"; } if(!$email_address){ echo "Email Address is a required field. Please enter it below.<br />"; } if(!$username){ echo "Desired Username is a required field. Please enter it below.<br />"; } include 'join_form.html'; // Show the form again! /* End the error checking and if everything is ok, we'll move on to creating the user account */ exit(); // if the error checking has failed, we'll exit the script! } /* Let's do some checking and ensure that the user's email address or username does not exist in the database */ $sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'"); $sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'"); $email_check = mysql_num_rows($sql_email_check); $username_check = mysql_num_rows($sql_username_check); if(($email_check > 0) || ($username_check > 0)){ echo "Please fix the following errors: <br />"; if($email_check > 0){ echo "<strong>Your email address has already been used by another member in our database. Please submit a different Email address!<br />"; unset($email_address); } if($username_check > 0){ echo "The username you have selected has already been used by another member in our database. Please choose a different Username!<br />"; unset($username); } include 'join_form.html'; // Show the form again! exit(); // exit the script so that we do not create this account! } /* Everything has passed both error checks that we have done. It's time to create the account! */ /* Random Password generator. http://www.phpfreaks.com/quickcode/Random_Password_Generator/56.php We'll generate a random password for the user and encrypt it, email it and then enter it into the db. */ function makeRandomPassword() { $salt = "abchefghjkmnpqrstuvwxyz0123456789"; srand((double)microtime()*1000000); $i = 0; while ($i <= 7) { $num = rand() % 33; $tmp = substr($salt, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } $random_password = makeRandomPassword(); $db_password = md5($random_password); // Enter info into the Database. $info2 = htmlspecialchars($info); $sql = mysql_query("INSERT INTO users (first_name, last_name, email_address, username, password, info, signup_date) VALUES('$first_name', '$last_name', '$email_address', '$username', '$db_password', '$info2', now())") or die (mysql_error()); if(!$sql){ echo 'There has been an error creating your account. Please contact the webmaster.'; } else { $userid = mysql_insert_id(); // Let's mail the user! $subject = "Your Membership at invitacoach.com!"; $message = "Dear $first_name, Thank you for registering at our website, http://www.invitacoach.com You are two steps away from logging in and accessing our exclusive members area. To activate your membership, please click he http://www.invitacoach.com/test/activate.php?id=$userid&code=$db_password Once you activate your membership, you will be able to login with the following information: Username: $username Password: $random_password Thanks! Invita Coach
Hi All, $userClient = "VARIABLE OF WHO IS LOGGED IN"; <form action="actions/assign.php" method="post"> <?php $sql = "SELECT * FROM Engineers where Engineer_Company = '".addslashes($userClient)."' and userType = '5'"; $result = mysqli_query($db, $sql); while($row = mysqli_fetch_assoc($result)) { $userSID = $row["userID"]; echo '<tr> <td>'.$row["userName"].' <input type="hidden" class="form-control" id="usersID[]" name="usersID'.$row["userID"].'" value="'.$row["userID"].'"> <input type="hidden" class="form-control" id="date" name="date" value="'.date('d-m-Y').'"> </td> <td>'; $sql1 = "SELECT * FROM job_orders where companyID = '".addslashes($userClient)."'"; $result1 = mysqli_query($db, $sql1); echo "<select style='width: 250px;' id='job$userSID' name='job$userSID'>"; echo '<option value="">-- Please Select --</option>'; while($row1 = mysqli_fetch_assoc($result1)) { echo '<option value="'.$row1["jobID"].'">'.$row1["jobtitle"].'</option>'; } echo "</select>"; echo '</td> <td>'; $query = $db->query("SELECT * FROM Engineer_Company WHERE Company_ID = '".addslashes($userClient)."'"); $rowCount = $query->num_rows; if($rowCount > 0){ echo ' <select name="company'.$userSID.'" id="company'.$userSID.'" style="width: 250px;"> <option value="">-- Select Company --</option>'; while($row = $query->fetch_assoc()){ echo '<option value="'.$row['Engineer_Company_ID'].'" class="form-control form-control-sm">'.$row['Engineer_Company_Name'].'</option>'; } echo '</select>'; } echo'</td> <td> <div class="form-group"> <select id="site'.$userSID.'" name="site'.$userSID.'" style="width: 250px;"> <option value="">-- Select Site --</option> </select> </div> '; echo'</td> </tr>'; echo ' <script type="text/javascript"> $(document).ready(function(){ $("#company'.$userSID.'").on("change",function(){ var diag_id = $(this).val(); if(diag_id){ $.ajax({ type:"POST", url:"ajax-client-side.php", data:"diag_id="+diag_id, success:function(html){ $("#site'.$userSID.'").html(html); } }); } }); }); </script>'; } ?> </tbody> </table> <input class="btn btn-dark float-right" type="submit" value="Allocate"> </form>
|