PHP - Why Wont This Go To Mysql Form?
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"; } } } ?> Similar TutorialsNeed help ASAP. i need the following form to right to mysql table "table1" and columns "name" "email" and "comment".
<form action="sign.php" method="post" class="pure-form pure-form-stacked"> <fieldset> <label for="name">Your Name</label> <input id="name" type="text" placeholder="Your Name" name="name"> <label for="email">Your Email</label> <input id="email" type="email" placeholder="Your Email" name="email"> <label for="comment">Your Comments</label> <input id="comment" type="text" placeholder="Your Comments" name="comment"> <a href="thanks.html" button type="submit" class="pure-button">SUBMIT</button> </a> </fieldset> </form> My PHP File looks like this: <html> <body> <?php $myUser = "dbuser"; $myPassd = "********"; $myDB = "dbname"; $myserver = "192.168.1.80:3306"; $name = $_POST['name']; $email = $_POST['email']; $comment = $_POST['comment']; // Create connection $dbhandle = mysql_connect($myserver,$myUser,$myPassd) or die("Unable to connect to MySQL"); echo "Connected to MySQL<br>"; //select a database to work with $selected = mysql_select_db($myDB, $dbhandle) or die("Couldn't open database $myDB"); //if (mysqli_connect_errno()) { //echo "Failed to connect to MySQL: " . mysqli_connect_error(); //} //echo "connected"; $sql = "INSERT INTO signatures (name, comment) VALUES ( $name, $comment)"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } echo "record added"; mysql_close($dbhandle); ?> </body> </html> I also need this to redirect to another html page after it run. Like i said any help would be great because i cant get it to work! Here is the code: Code: [Select] <?php $db = mysql_query(" SELECT story_id FROM story_info WHERE story='$story_form' AND user='$username' ")or die(mysql_error()); $rows = mysql_fetch_assoc($db); $id = $rows['story_id']; ?> All of the variables are defined earlier in the code. MySQL connection works and it connects to my database but it doesnt insert values into the table that I created. <form action="phplogin2.php" method="post"> Username: <input type="text" name="user" style="color: white; background-color: blue;"/><br/> Password: <input type="password" name="pass" style="color: grey; background-color: black;"/><br/> <button>Login</button> </form> <?php $con = mysql_connect('localhost', 'root', 'eagles1') or die("did not connect"); $dbc = mysql_select_db('mysql') or die("did not connect to database"); $query = mysql_query("INSERT INTO login VALUES('', '$user', '$pass')") or die("query did not work"); $user = $_POST['user']; $pass = $_POST['pass']; if ($con==true){ echo "MySQL Connection Succesful"; } if ($dbc==true){ echo "MySQL Database Connection Succesful"; } if ($query==true){ echo "MySQL Query Succesful"; } ?> Ok, i really need help with my registration page for my website. I've been working on this for 2 days now and i can't seem to get it to work propertly. This problem is that whenever i'm trying to register myself as a new user at my localhost website i get "Could Not Process Form" error that i've put into the code myself. I beleive this has something to do with the connection to my MySQL but i've put in "membership" as the database "root" as the username and then my password. If anyone has the time to read through my coding, i have marked the line where the error message is placed in the code.. yeah see for your self. Really need help with this! <?php class Register { private $username; private $firstname; private $lastname; private $password; private $passmd5; private $email; private $gender; private $birthday; private $errors; private $token; public function __construct() { $this->errors = array(); $this->username = $this->filter($_POST['username']); $this->firstname = $this->filter($_POST['first_name']); $this->lastname = $this->filter($_POST['last_name']); $this->password = $this->filter($_POST['password']); $this->email = $this->filter($_POST['email']); $this->gender = $this->filter($_POST['gender']); $this->birthday = $this->filter($_POST['birth_day']); $this->token = $_POST['token']; $this->passmd5 = md5($this->password); } public function process() { if($this->valid_token() && $this->valid_data()) $this->register(); return count($this->errors)? 0 : 1; } public function filter($var) { return preg_replace('/[^a-zA-Z0-9@.]/','',$var); } public function register() { mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("membership") or die (mysql_error()); mysql_query("INSERT INTO users(username,password) VALUES ('{$this->username}','{$this->passmd5}')"); if(mysql_affected_rows()< 1) $this->errors[] = 'Could Not Process Form'; <------------------ HERE IS THE ERROR MESSAGE I'VE PUT IN THE CODE TO SPIT OUT IF SOMETHING GOES WRONG } public function user_exists() { mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("membership") or die (mysql_error()); $data = mysql_query("SELECT username FROM users WHERE username = '{$this->username}'"); return mysql_num_rows($data) > 0 ? 1 : 0; } public function show_errors() { echo "<h3>Errors</h3>"; foreach($this->errors as $key=>$value) echo $value."<br>"; } public function valid_data() { if($this->user_exists()) $this->errors[] = 'Username Already Taken'; if(empty($this->username)) $this->errors[] = 'Invalid Username'; if(empty($this->firstname)) $this->errors[] = 'Invalid First Name'; if(empty($this->lastname)) $this->errors[] = 'Invalid Last Name'; if(empty($this->password)) $this->errors[] = 'Invalid Password'; if(empty($this->email) || !preg_match('/^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$/',$this->email)) $this->errors[] = 'Invalid Email'; if(empty($this->gender)) $this->errors[] = 'Invalid Gender'; if(empty($this->birthday)) $this->errors[] = 'Invalid Birthday'; return count($this->errors)? 0 : 1; } public function valid_token() { if(!isset($_SESSION['token']) || $this->token != $_SESSION['token']) $this->errors[] = 'Invalid Submission'; return count($this->errors)? 0 : 1; } } ?> I have the code echoing into the next page where it says your mail was sent successfully but it wont email me all the variables here is the code: <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>Submitted Form</title> </head> <body> <?php session_start(); echo "<html> <head><title>Posted Variables</title></head> <body>"; $to = "artdept@calmktg.com"; $subject = "SCE SONGS ORDER FORM"; $email = $_REQUEST['email']; foreach ($_POST as $field => $value) { echo "$field = $value<br>"; } $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"; } ?> </body> </html> please help me out if you need anything else just ask....my email is artdept@calmktg.com I HAVE TRIED looking at it but i am new to php so i can't figure out what i did wrong help please !!!!!!!!!!!! Fatal error: Call to undefined method modernCMS::update_form() in C:\wamp\www\test\inc\update-content.php on line 4 ---- Page that's accessing code ----- <?php include '../test/inc/admin/nav.php'; echo $obj->update_form($_GET['id']); ?> ------ function ------ <?php class modernCMS { var $host; var $username; var $password; var $db; function connect() { $con = mysql_connect($this->host, $this->username, $this->password) or die(mysql_error()); mysql_select_db($this->db, $con) or die(mysql_error()); } //end connect function get_content($id = '') { if($id != ""): $id = mysql_real_escape_string($id); $sql = "SELECT * FROM cms_content WHERE id = '$id'"; // $return = "<p><a href=../test/inc/admin/nav.php>Go Back To Content</a></p>"; else: $sql = "SELECT * FROM cms_content ORDER BY id DESC"; endif; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) != 0): while($row = mysql_fetch_assoc($res)) { echo '<table bgcolor="#975627" width="100%" border="0" cellspacing="1" cellpadding="3"> <tr> <td height="25" background="images/menu.gif"><center><strong>' . $row['title'] . '</strong></center></td> </tr> <tr bgcolor="975627"><td height="0"></td></tr> <tr> <td bgcolor="#181818"> '; echo '<br> <div align="center">' . $row['body'] . ' <br><br> </td> </tr> <tr> <td height="25" background="images/menu.gif"> </td> </tr> </table><br><br> '; } else: echo '<p>Uh Oh!!! </p>'; endif; // echo $return; } //end get_content function add_content($p) { $title = mysql_real_escape_string($p['title']); $body = mysql_real_escape_string($p['body']); if(!$title || !$body): if(!$title): echo "<p>The title is required!</p>"; endif; if(!$body): echo "<p>The body is required!</p>"; endif; echo '<p><a href="add-content.php">Try Again!!!</a></p>'; else: $sql = "INSERT INTO cms_content VALUES (null, '$title', '$body')"; $res = mysql_query($sql) or die(mysql_error()); echo "Added Successfully!"; endif; } //end add_content function manage_content() { $sql = "SELECT * FROM cms_content ORDER BY id DESC"; $res = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($res)): ?> <div> <h2 class="title"><?php echo $row['title']; ?></h2> <span class="actions"<a href="../test/update-content.php?id=<?php echo $row['id']?>">Edit</a> | <a href="?delete= <?php echo $row['id'] ?> ">Delete</a></span> </div> <?php endwhile; echo '</div>'; //Class Manage Div } //end manage_content function delete_content($id) { if(!$id) { return false; }else { $id = mysql_real_escape_string($id); $sql = "DELETE FROM cms_content WHERE id = '$id'"; $res = mysql_query($sql) or die(mysql_error()); echo "Content Deleted Successfully!"; } } } //end delete_content function update_form($id) { $id = mysql_real_escape_string($id); $sql = "SELECT * FROM cms_content WHERE id = '$id'"; $res = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($res); ?> <form method="post" action="./post-added.php"> <input type="hidden" name="update" value="true" /> <input type="hidden" name="id" value="<?php $row['id'] ?>" /> <div> <label for="title">Title:</label> <input type="text" name="title" id="title" value="<?php echo $row['title'] ?>" /> </div> <div> <label for="body">Body:</label> <textarea name="body" id="body" rows="8" cols="40" /><?php echo $row['body'] ?></textarea> </div> <input type="submit" name="submit" value="Update Content" /> </form> <?php } //end update_content_form function update_content($p) { $title = mysql_real_escape_string($p['title']); $body = mysql_real_escape_string($p['body']); $id = mysql_real_escape_string($p['id']); if(!$title || !$body): if(!$title): echo "<p>The title is required!</p>"; endif; if(!$body): echo "<p>The body is required!</p>"; endif; echo '<p><a href="update-content.php?id=' . $id . '">Try Again!!!</a></p>'; else: $sql = "UPDATE cms_content SET title = '$title', body = '$body' WHERE id = '$id'"; $res = mysql_query($sql) or die(mysql_error()); echo "Updated Successfully!"; endif; } //end update_content($p) ?> Can anyone explain... (note this is first time using PHP , dont have a clue, only using it as FLash CS5 wont send emails forms directly) so add all the details and explain it all please.) why my yahoo email is not detecting this at all. Also I managed some success earlier with earlier attempts but eveythign was surrounded with html tags even though I set them to off in Flash on the property tabs on the input text. In the Flash file . swf the send button has this code Code: [Select] on(release){ form.loadVariables("email_send.php", "POST"); } and the movie containing the input text fields has this code Code: [Select] onClipEvent(data){ _root.nextFrame(); } the next page is a thank you screen The variables in the input text boxes in the Flash file are name, dept, phone, email and message Code: [Select] <?php $sendTo = "chris.bruneluni@yahoo.co.uk"; $subject = "Message from chriscreativity.com"; $headers = "From: ". $_POST("name"); $headers = "Postion: ". $_POST["dept"]; $headers = "<". $_POST["email"] .">". "\r\n"; $headers = "Reply-To: " . $_POST["email"] . "\r\n"; $headers = "Return-Path: ". $_POST["email"] ; $headers = $_POST["phone"]; $message = $_POST["message"]; $message = wordwrap($message, 70); mail($sendTo, $subject, $headers, $message); ?><\Strong> Please can you help to A) get it to email my yahoo email B) make an email that looks like Name: Micky Dept : Disney Emial : Mick @mouse.com etc not <TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Comic Sans MS" SIZE="16" COLOR="#000000" LETTERSPACING="0" KERNING="0">Micky</FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Comic Sans MS" SIZE="16" COLOR="#000000" LETTERSPACING="0" KERNING="0"> please [attachment deleted by admin] ok..ive done this a million times..i have a working example here and i copied it and amended it for this new project but for some reason i cant get a form to post data to another page. this is the error message i get Notice: Undefined index: username in C:\wamp\www\uni\fyp\site\mobile\login.php on line 16 Notice: Undefined index: password in C:\wamp\www\uni\fyp\site\mobile\login.php on line 17 here is my form code: <form method="post" action="login.php"> <table align="center" cellpadding="0" cellspacing="0"> <tr> <td style="vertical-align:top;">Username: </td><td><input type="text" name="username" value="" /></td> </tr> <tr> <td style="vertical-align:top;">Password: </td><td><input type="password" name="password" value="" /><br /><input type="submit" id="submit" value="Login" /></td> </tr> </table> </form> and here is the code within the login.php where the form should post to $username = $_POST['username']; $password = $_POST['password']; // Help protect against MySQL injection $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); // Selecting data from database where correct username and password are found $sql="SELECT * FROM customer WHERE username='$username' and password='$password'"; $result=mysql_query($sql) or die(mysql_error()); i cant see anything wrong..been looking for hours...please please help me 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 need help trying to get this delete feature to work its not deleting from the database (by the way i took out my database names and passwords at the top of the file) is it possible someone could help me, ive been working on this for like a week and cant figure out the problem. thanks! you can email me at spr_spng@yahoo.com picture 2.png is showing what it looks like Code: [Select] <?php $host="localhost"; // Host name $username="username"; // Mysql username $password="password"; // Mysql password $db_name="database_name"; // Database name $tbl_name="table_name"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <style> /*table affects look of the whole table look */ table { margin-left: auto; margin-right: auto; border: 1px solid #330000; border-collapse:collapse; width:70%; border-width: 5px 5px 5px 5px; border-spacing: 1px; border-style: outset outset outset outset; border-color: #330000 #330000 #330000 #330000; border-collapse: separate; background-color: #330000; #800517 f535aa #330000 school color #9A0000 school color2 #991B1E school color3 #CCCC99 school color4 #9A0000 } /*th is table header */ th { text-align: left; height: 2.5em; background-color: #330000; color: #FC0; font-size:1.5em; } /*td is table data or the cells below the header*/ td { text-align: left; height:1.0em; font-size:1.0em; vertical-align:bottom; padding:10px; border-width: 5px 5px 5px 5px; padding: 8px 8px 8px 8px; border-style: outset outset outset outset; border-color: #9A0000 #9A0000 #9A0000 #9A0000; background-color: #CCCC99; -moz-border-radius: 0px 0px 0px 0px; } </style> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="form1" method="post" action=""> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td bgcolor="#FFFFFF"> </td> <td colspan="4" bgcolor="#FFFFFF"><strong>Pick Which Rows you want to delete, Then press delete.</strong> </td> </tr> <tr> <td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Lastname</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Email</strong></td> <td align="center" bgcolor="#FFFFFF">delete</td></tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['name']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['lastname']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['email']; ?></td> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td> </tr> <? // Check if delete button active, start this // edited if($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "DELETE FROM $tbl_name WHERE id='$del_id'"; $result = mysql_query($sql); } // if successful redirect to delete_multiple.php if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.php\">"; } } mysql_close(); ?> </table> </form> </td> </tr> </table> 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"; } ?> 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> 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 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! 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 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> 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 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 |