|
Re: Linking php code to a form & mysql database
Hey Rakuli!!!
- PHP: Select all
<?php require_once('Connections/dbprofile.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); }
if (isset($_POST['select4'])) { $month = $_POST['select4']; } if (isset($_POST['select5'])) { $day = $_POST['select5']; } if (isset($_POST['select6'])) { $year = $_POST['select6']; } $dob = $day."/".$month."/".$year; if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO tbl_signup (sigiam, siginterested, sigfor, sigdob, sigpostcode, sigarea, sigemail, sigusername, sigpassword, siphonenumber, sisexmalefemale, signame, sigwhatturnsmeon, sigtellwhatlooklike) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, )", GetSQLValueString($_POST['sigiam'], "int"), GetSQLValueString($_POST['siginterested'], "int"), GetSQLValueString($_POST['sigfor'], "int"), GetSQLValueString($dob, "text"), GetSQLValueString($_POST['sigpostcode'], "text"), GetSQLValueString($_POST['sigarea'], "int"), GetSQLValueString($_POST['sigemail'], "text"), GetSQLValueString($_POST['sigusername'], "text"), GetSQLValueString($_POST['sigpassword'], "text")); GetSQLValueString($_POST['siphonenumber'], "text")); GetSQLValueString($_POST['sisexmalefemale'], "text")); GetSQLValueString($_POST['signame'], "text")); GetSQLValueString($_POST['sigwhatturnsmeon'], "text")); GetSQLValueString($_POST['sigtellwhatlooklike'], "text")); mysql_select_db($database_dbprofile, $dbprofile); $Result1 = mysql_query($insertSQL, $conndb) or die(mysql_error()); $insertGoTo = "profile.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_dbprofile, $dbprofile); $query_rsIam = "SELECT * FROM tbl_iam ORDER BY imid ASC"; $rsIam = mysql_query($query_rsIam, $dbprofile) or die(mysql_error()); $row_rsIam = mysql_fetch_assoc($rsIam); $totalRows_rsIam = mysql_num_rows($rsIam); mysql_select_db($database_dbprofile, $dbprofile); $query_rsInterested = "SELECT * FROM tbl_interested ORDER BY intid ASC"; $rsInterested = mysql_query($query_rsInterested, $dbprofile) or die(mysql_error()); $row_rsInterested = mysql_fetch_assoc($rsInterested); $totalRows_rsInterested = mysql_num_rows($rsInterested); mysql_select_db($database_dbprofile, $dbprofile); $query_rsFor = "SELECT * FROM tbl_for ORDER BY forid ASC"; $rsFor = mysql_query($query_rsFor, $dbprofile) or die(mysql_error()); $row_rsFor = mysql_fetch_assoc($rsFor); $totalRows_rsFor = mysql_num_rows($rsFor); mysql_select_db($database_dbprofile, $dbprofile); $query_rsArea = "SELECT * FROM tbl_area ORDER BY areaname ASC"; $rsArea = mysql_query($query_rsArea, $dbprofile) or die(mysql_error()); $row_rsArea = mysql_fetch_assoc($rsArea); $totalRows_rsArea = mysql_num_rows($rsArea); <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Create Your profile</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rel="stylesheet" href="css/1.css" type="text/css" media="screen,projection" /> <style type="text/css"> <!-- .style1 {color: #FF00FF} .style2 {color: #FF3399} .style3 {color: #0474F1; } .style4 {font-family: Tahoma} .style5 {font-family: Verdana, Arial, Helvetica, sans-serif} --> </style> <script src="file:///C|/webserver/Apache2/htdocs/Scripts/AC_RunActiveContent.js" type="text/javascript"></script> </head> <body bgcolor="white"> <div id="header"> <h1 class="right"> </h1> <h1> </h1> </div> <ul id="nav"> <li class="right"><input value="Search..." type="text" /></li> <li><a href="MainPage.php">MainPage</a></li> <li><a href="Login.php">LogIn</a></li> <li><a href="admin/Sign Up.php">SignUp</a></li> <li><a href="Chat.php">Chat</a></li> </ul> <div class="clear" /> <div id="content"> <p> <?php // Connect to database $errmsg = ""; if (! @mysql_connect("localhost","trainee","abc123")) { $errmsg = "Cannot connect to database"; } @mysql_select_db("test"); // First run ONLY - need to create table by uncommenting this // Or with silent @ we can let it fail every sunsequent time ;-) $q = <<<CREATE create table pix ( pid int primary key not null auto_increment, title text, imgdata longblob) CREATE; @mysql_query($q); // Insert any new image into database if ($_REQUEST[completed] == 1) { // Need to add - check for large upload. Otherwise the code // will just duplicate old file ;-) // ALSO - note that latest.img must be public write and in a // live appliaction should be in another (safe!) directory. move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img"); $instr = fopen("latest.img","rb"); $image = addslashes(fread($instr,filesize("latest.img"))); if (strlen($instr) < 149000) { mysql_query ("insert into pix (title, imgdata) values (\"". $_REQUEST[whatsit]. "\", \"". $image. "\")"); } else { $errmsg = "Too large!"; } } // Find out about latest image $gotten = @mysql_query("select * from pix order by pid desc limit 1"); if ($row = @mysql_fetch_assoc($gotten)) { $title = htmlspecialchars($row[title]); $bytes = $row[imgdata]; } else { $errmsg = "There is no image in the database yet"; $title = "no database image available"; // Put up a picture of our training centre $instr = fopen("../wellimg/ctco.jpg","rb"); $bytes = fread($instr,filesize("../wellimg/ctco.jpg")); } // If this is the image request, send out the image if ($_REQUEST[gim] == 1) { header("Content-type: image/jpeg"); print $bytes; exit (); } ?> </p> <h2>Welcome To Your Profile!</h2> <font color="red"> <?= $errmsg ?> </font> <center> <img src="?gim=1" width="144" /><br /> <b> <?= $title ?> </center> <hr /> <h2>Upload A Photo Of Yourself & Enhance Your Responce From Other Members</h2> <form enctype="multipart/form-data" method="post"> <p> <input type="hidden" name="MAX_FILE_SIZE" value="150000" /> <input type="hidden" name="completed" value="1" /> <span class="style2"><font face="Tahoma">Please choose an image to upload:</font></span> <input type="file" name="imagefile" /> </p> <p> <br /> <span class="style2"><font face="Tahoma">Please enter the title of that picture:</font></span> <input name="whatsit" /> </p> <p> <br /> <span class="style2"><font face="Tahoma">Click Submit To Upload Your Image:</font></span> <input type="submit" /> </p> </form> <div align="center"> <table width="828" height="557" border="0"> <tr> <td height="45"><h2>To Contact & Be Contacted By Other Members Please Create Your Profile Id</h2></td> </tr> <tr> <td height="504" valign="top"><p> </p> <table width="736" height="484" border="0"> <tr> <td valign="top" class="style4"><div align="center"> <p class="style2">Please Input Your First Name (no capitals)</p> <form id="form1" method="post" action=""> <span class="style2"> <label> <input type="text" name="name" id="name" /> </label> </span> </form> <p class="style2">Please Input Your Age (digits only)</p> <form id="form2" method="post" action=""> <span class="style2"> <label> <input type="text" name="age" id="age" /> </label> </span> <p class="style2">Please Input Your Sex (male\female no capitals)</p> <p> <span class="style2"> <label> <input type="text" name="sex" id="sex" /> </label> </span></p> <p class="style2">Please Input Your Phone number (optional)</p> <p class="style2">Please Input Your User Name </p> <p class="style2">(user name must be same as your login name)</p> <p> <span class="style2"> <label> <input type="text" name="username" id="username" /> </label> </span></p> <p class="style2">Please Input Your Password</p> <p class="style2">(password must be the same as your login password)</p> <p> <span class="style2"> <label> <input type="text" name="password" id="password" /> </label> </span></p> <p> <label></label> <span class="style2">Please Describe Your Hobbies & Interests</span></p> <p> <textarea name="hobbies" id="hobbies" cols="45" rows="5"></textarea> </p> </form> <p class="style2">Please Input Your Email Address</p> <form id="form9" method="post" action=""> <p> <label> <input type="text" name="email" id="email" /> </label> </p> </form> <p class="style2"> </p> </div></td> <td valign="top" class="style4"><div align="center"> <p class="style2"><span class="style2">Describe What Turns You On & Why </span></p> <form action="" method="post" class="style3" id="form3"> <span class="style2"> <label></label> </span> </form> <form action="" method="post" class="style3" id="form4"> <span class="style2"> <label> <textarea name="turnon" id="turnon" cols="45" rows="5"></textarea> </label> </span> </form> <form action="" method="post" class="style3" id="form5"> <span class="style2"> <label>Please Tell Us What You Look Like<br /> <br /> <textarea name="looklike" id="looklike" cols="45" rows="5"></textarea> <br /> <br /> </label> </span> <p class="style2">I Am</p> <p> <span class="style2"> <label> <select name="iam" id="iam"> <option>Man</option> <option>Women</option> <option>Bi Couple</option> <option>Group</option> </select> </label> </span></p> <p>Interested In</p> <p> <label> <select name="interestedin" id="interestedin"> <option>Man</option> <option>Women</option> <option>By Couple</option> <option>Group</option> </select> </label> </p> <p class="style2">Looking For (Sexual Interests)</p> <p> <span class="style2"> <label> <select name="sexsubject" id="sexsubject"> <option>Anythink</option> <option>Group Sex</option> <option>1 On 1 Sex</option> <option>Sexual Discreet Ongoing Partner</option> <option>Erotic Chat</option> <option>Email Swopping</option> <option>Photo Swopping</option> </select> </label> </span></p> </form> <p class="style2">Please Input Your Area</p> <form action="" method="post" class="style3" id="form6"> <span class="style2"> <label> <select name="area" id="area"> </select> </label> </span> </form> <p class="style2">Please Input Your Postcode</p> <p class="style2">(no capital letters) </p> <form action="" method="post" class="style3" id="form7"> <span class="style2"> <label> <input type="text" name="postcode" id="postcode" /> </label> </span> </form> <form id="form8" method="post" action=""> <p> <label> <input type="submit" name="button" id="button" value="Submit" /> </label> </p> </form> <p class="style3"> </p> <p> </p> <p> </p> </div></td> </tr> </table> <h2 align="center" class="style5">Remember this is your space so be accurate with you data to ensure results!</h2> <p> </p></td> </tr> </table> <br /> </div> <hr /> <p> </p> <p> </p> <p> </p> </div> <div id="footer"> <p>Site Design by <a href="http://www.sixshootermedia.com">AJL Online Services Business Developement Specialists</a>.<br /> <!-- you can delete below here --> © All copyrights reserved.</p> </div> </body> </html>
|